Skip to content

Instantly share code, notes, and snippets.

@OnurGumus
Created December 17, 2019 11:24
Show Gist options
  • Save OnurGumus/b01f1848a121f3a4e54edefe13887626 to your computer and use it in GitHub Desktop.
Save OnurGumus/b01f1848a121f3a4e54edefe13887626 to your computer and use it in GitHub Desktop.
tickspec xunit wiring
open TickSpec
open Akkling
open Akkling.TestKit
open Akkling.Streams
open Akka.Streams
open Akka.TestKit.Xunit2
open CSVParser
open Swensen.Unquote
open System
open Serilog
open Domain
let testDefaultNoDispose fn =
let config = Configuration.parse("akka { loglevel=DEBUG, log-config-on-start = on , loggers=[\"Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog\"]}")
let system = testConfig |> config.WithFallback |> System.create "test-system"
let tck = new TestKit(system)
fn tck
module Tests
open Xunit
open TickSpec
open Serilog
Log.Logger <-
LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger()
let source = AssemblyStepDefinitionsSource(System.Reflection.Assembly.GetExecutingAssembly())
let scenarios resourceName = source.ScenariosFromEmbeddedResource resourceName |> MemberData.ofScenarios
[<Theory; MemberData("scenarios", "DubaiPolice.Test.CSV.feature")>]
let csv (scenarioWrapper : ScenarioWrapper) =
scenarioWrapper.Scenario.Action.Invoke()
[<Theory; MemberData("scenarios", "DubaiPolice.Test.Flow.feature")>]
let flow (scenarioWrapper : ScenarioWrapper) =
scenarioWrapper.Scenario.Action.Invoke()
namespace TickSpec
open Xunit.Abstractions
open System
type ScenarioWrapper = class
[<NonSerialized>]
val mutable public Scenario : Scenario
[<DefaultValue>]
static val mutable private map : Map<string,Scenario>
interface IXunitSerializable with
member this.Deserialize info =
let scnName = info.GetValue("scenarios")
this.Scenario <- ScenarioWrapper.map.[scnName]
member this.Serialize info =
ScenarioWrapper.map <- ScenarioWrapper.map.Add (this.Scenario.Name, this.Scenario)
info.AddValue("scenarios", this.Scenario.Name)
new () = {
Scenario = Unchecked.defaultof<_>
}
override this.ToString() = this.Scenario.Name
end
/// Represents a set of Step Definitions available within a given Assembly
type AssemblyStepDefinitionsSource(assembly : System.Reflection.Assembly) =
let definitions = StepDefinitions(assembly)
/// Yields Scenarios generated by parsing the supplied Resource Name and binding the steps to their Step Definitions
member __.ScenariosFromEmbeddedResource resourceName : Scenario seq =
let stream = assembly.GetManifestResourceStream(resourceName)
definitions.GenerateScenarios(resourceName, stream)
/// Adapts a Scenario Sequence to match the required format for an xUnit MemberData attribute
module MemberData =
let ofScenarios xs = xs |> Seq.map (fun (x : Scenario) -> [| ScenarioWrapper( Scenario = x) |])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment