2018-07-06 23:14:06 +00:00
|
|
|
namespace LogicalHacking.ExtensionDsLab.Tests
|
2017-08-06 16:59:09 +00:00
|
|
|
|
2018-07-06 23:14:06 +00:00
|
|
|
open Expecto
|
|
|
|
open FsCheck
|
|
|
|
open GeneratorsCode
|
|
|
|
|
2018-07-20 07:28:46 +00:00
|
|
|
open System
|
|
|
|
open System.Configuration
|
|
|
|
|
|
|
|
open LogicalHacking.ExtensionDsLab
|
2018-07-23 05:10:27 +00:00
|
|
|
open LogicalHacking.ExtensionDsLab.Archive.DbConnector
|
2018-07-24 06:33:12 +00:00
|
|
|
open LogicalHacking.ExtensionDsLab.Archive.ExtensionQueries
|
2018-07-20 07:28:46 +00:00
|
|
|
|
|
|
|
|
2018-07-06 23:14:06 +00:00
|
|
|
module Tests =
|
|
|
|
let config10k = { FsCheckConfig.defaultConfig with maxTest = 10000}
|
|
|
|
// bug somewhere: registering arbitrary generators causes Expecto VS test adapter not to work
|
|
|
|
//let config10k = { FsCheckConfig.defaultConfig with maxTest = 10000; arbitrary = [typeof<Generators>] }
|
|
|
|
let configReplay = { FsCheckConfig.defaultConfig with maxTest = 10000 ; replay = Some <| (1940624926, 296296394) }
|
|
|
|
|
2018-07-20 07:28:46 +00:00
|
|
|
let connectionStringOrDefault defaultString =
|
|
|
|
let map = new ExeConfigurationFileMap(ExeConfigFilename = __SOURCE_DIRECTORY__ + "/app.config")
|
|
|
|
let config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)
|
|
|
|
match config.ConnectionStrings.ConnectionStrings.["ProductionExtensionDB"] with
|
|
|
|
| null -> defaultString
|
|
|
|
| a -> a.ConnectionString
|
|
|
|
|
|
|
|
let ctx = ExtensionDbProvider.GetDataContext(connectionStringOrDefault "")
|
|
|
|
|
|
|
|
let measureExecutionTime f =
|
|
|
|
let timer = new System.Diagnostics.Stopwatch()
|
|
|
|
timer.Start()
|
|
|
|
let result = f()
|
|
|
|
(int32(timer.ElapsedMilliseconds), result)
|
|
|
|
|
|
|
|
|
2018-07-06 23:14:06 +00:00
|
|
|
[<Tests>]
|
|
|
|
let testSimpleTests =
|
|
|
|
testList "DomainTypes.Tag" [
|
|
|
|
testCase "equality" <| fun () ->
|
|
|
|
let result = 42
|
|
|
|
Expect.isTrue (result = 42) "Expected True"
|
|
|
|
|
|
|
|
testPropertyWithConfig config10k "whitespace" <|
|
|
|
|
fun () ->
|
|
|
|
Prop.forAll (Arb.fromGen <| whitespaceString())
|
|
|
|
(fun (x : string) ->
|
|
|
|
x = x)
|
2018-07-20 07:28:46 +00:00
|
|
|
|
|
|
|
testCase "Testing Performance of getDownloads" <| fun () ->
|
|
|
|
let (time, result) = measureExecutionTime (fun () -> (getDownloads ctx "lkllajgbhondgjjnhmmgbjndmogapinp"))
|
|
|
|
Expect.isLessThan time 1500 "Query should take less than 1500ms"
|
2018-07-06 23:14:06 +00:00
|
|
|
]
|
2018-07-24 06:33:12 +00:00
|
|
|
|