From f13a8487beca19b1e0dad18ab6a7245379993598 Mon Sep 17 00:00:00 2001 From: "Achim D. Brucker" Date: Fri, 20 Jul 2018 08:28:46 +0100 Subject: [PATCH] Basic setup of a test that runs against the actual data base. --- .gitignore | 1 + .../Tests.fs | 31 +++++++++++++++++-- .../app.config.in | 17 ++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/LogicalHacking.ExtensionDsLab.Tests/app.config.in diff --git a/.gitignore b/.gitignore index 8e28847..c714494 100644 --- a/.gitignore +++ b/.gitignore @@ -193,6 +193,7 @@ docs # ignore app.config src/LogicalHacking.ExtensionDsLab/app.config +tests/LogicalHacking.ExtensionDsLab.Tests/app.config # ignore superfluous directories created by FSLab */*/DesignTimeURIs/ diff --git a/tests/LogicalHacking.ExtensionDsLab.Tests/Tests.fs b/tests/LogicalHacking.ExtensionDsLab.Tests/Tests.fs index ca1eb9c..25445c1 100644 --- a/tests/LogicalHacking.ExtensionDsLab.Tests/Tests.fs +++ b/tests/LogicalHacking.ExtensionDsLab.Tests/Tests.fs @@ -4,15 +4,38 @@ open Expecto open FsCheck open GeneratorsCode +open System +open System.Configuration + +open LogicalHacking.ExtensionDsLab +open LogicalHacking.ExtensionDsLab.Archive.MySqlConnector +open LogicalHacking.ExtensionDsLab.Archive.ExtensionCore + + 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] } let configReplay = { FsCheckConfig.defaultConfig with maxTest = 10000 ; replay = Some <| (1940624926, 296296394) } + 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) + + [] let testSimpleTests = - testList "DomainTypes.Tag" [ testCase "equality" <| fun () -> let result = 42 @@ -23,5 +46,9 @@ module Tests = Prop.forAll (Arb.fromGen <| whitespaceString()) (fun (x : string) -> x = x) + + testCase "Testing Performance of getDownloads" <| fun () -> + let (time, result) = measureExecutionTime (fun () -> (getDownloads ctx "lkllajgbhondgjjnhmmgbjndmogapinp")) + Expect.isLessThan time 1500 "Query should take less than 1500ms" ] - + \ No newline at end of file diff --git a/tests/LogicalHacking.ExtensionDsLab.Tests/app.config.in b/tests/LogicalHacking.ExtensionDsLab.Tests/app.config.in new file mode 100644 index 0000000..4821e49 --- /dev/null +++ b/tests/LogicalHacking.ExtensionDsLab.Tests/app.config.in @@ -0,0 +1,17 @@ + + + + + + + + + True + + + + + +