@@ -10,25 +10,29 @@ open ApiStub.FSharp.HttpResponseHelpers
1010module BDD =
1111
1212
13+ /// Defines a BDD scenario
1314 type Scenario < 'TStartup when 'TStartup: not struct > =
1415 { UseCase: string
1516 TestClient: TestClient < 'TStartup > }
1617
18+ /// Defines the context propagated through the test
1719 type Environment < 'TStartup , 'FeatureStubData when 'TStartup: not struct > =
1820 { Scenario: Scenario < 'TStartup >
1921 FeatureStubData: 'FeatureStubData
2022 Factory: 'TStartup WebApplicationFactory
2123 Client: HttpClient }
2224
25+ /// Result of a Given gherkin clause
2326 type GivenResult < 'ArrangeData , 'FeatureStubData , 'TStartup when 'TStartup: not struct > =
2427 { Environment: Environment < 'TStartup , 'FeatureStubData >
2528 ArrangeData: 'ArrangeData } // once preconditions are set
2629
30+ /// Result of a When gherkin clause
2731 type WhenResult < 'ArrangeData , 'FeatureStubData , 'AssertData , 'TStartup when 'TStartup: not struct > =
2832 { Given: GivenResult < 'ArrangeData , 'FeatureStubData , 'TStartup >
2933 AssertData: 'AssertData }
3034
31-
35+ /// Generic step type for the BDD steps
3236 type Step < 'TStartup , 'FeatureStubData , 'ArrangeData , 'AssertData when 'TStartup: not struct > =
3337 | Scenario of Scenario < 'TStartup >
3438 | Environment of Environment < 'TStartup , 'FeatureStubData >
@@ -37,11 +41,13 @@ module BDD =
3741 | Invalid of error : string
3842
3943
44+ /// Scenario builder
4045 let SCENARIO useCase testClient =
4146 { UseCase = useCase
4247 TestClient = testClient }
4348 |> Step.Scenario
4449
50+ /// Setup the Environment for the given scenario
4551 let SETUP arrangeTestEnvironment customizeClient step =
4652 task {
4753
@@ -58,6 +64,7 @@ module BDD =
5864 | _ -> return Step.Invalid( " only environment is supported for ENVIRONMENT_SETUP" )
5965 }
6066
67+ /// specify a GIVEN gherkin clause
6168 let GIVEN setPreconditions stepTask =
6269 task {
6370
@@ -88,6 +95,7 @@ module BDD =
8895 | Result.Error( e) -> Step.Invalid( e)
8996 }
9097
98+ /// specify a WHEN gherkin clause
9199 let WHEN action stepTask =
92100 task {
93101
@@ -114,6 +122,7 @@ module BDD =
114122 return r
115123 }
116124
125+ /// Specify an assert in THEN gherkin format
117126 let THEN assertAction stepTask =
118127 task {
119128
@@ -126,6 +135,7 @@ module BDD =
126135 | _ -> return Step.Invalid( $" {step} is not supported in WHEN clause" )
127136 }
128137
138+ /// Conclude the pipeline of steps
129139 let END stepTask =
130140 task {
131141
@@ -141,35 +151,35 @@ module BDD =
141151 }
142152
143153
144- // [<Fact>] sample
145- let ``when i call / hello i get 'world' back with 200 ok`` ( testClient : TestClient < _ >) =
146-
147- let stubData = [ 1 , 2 , 3 ]
148-
149- testClient { GET " /hello" ( fun _ _ -> $" hello world {stubData}" |> R_ TEXT) }
150- |> SCENARIO " when i call /hello i get 'world' back with 200 ok"
151- |> SETUP
152- ( fun s ->
153- task {
154-
155- let test = s.TestClient
156-
157- let f = test.GetFactory()
158-
159- return
160- { Client = f.CreateClient()
161- Factory = f
162- Scenario = s
163- FeatureStubData = stubData }
164- })
165- ( fun c -> c)
166- |> GIVEN( fun g -> " hello" |> Task.FromResult)
167- |> WHEN( fun g ->
168- task {
169- let! ( r : HttpResponseMessage ) = g.Environment.Client.GetAsync( " /Hello" )
170- return ! r.Content.ReadAsStringAsync()
171- })
172- |> THEN( fun w ->
173- let _ = ( " hello world 1,2,3" = w.AssertData)
174- ())
175- |> END
154+ // [<Fact>] sample
155+ // let ``when i call /hello i get 'world' back with 200 ok`` (testClient: TestClient<_>) =
156+
157+ // let stubData = [ 1, 2, 3 ]
158+
159+ // testClient { GET "/hello" (fun _ _ -> $"hello world {stubData}" |> R_TEXT) }
160+ // |> SCENARIO "when i call /hello i get 'world' back with 200 ok"
161+ // |> SETUP
162+ // (fun s ->
163+ // task {
164+
165+ // let test = s.TestClient
166+
167+ // let f = test.GetFactory()
168+
169+ // return
170+ // { Client = f.CreateClient()
171+ // Factory = f
172+ // Scenario = s
173+ // FeatureStubData = stubData }
174+ // })
175+ // (fun c -> c)
176+ // |> GIVEN(fun g -> "hello" |> Task.FromResult)
177+ // |> WHEN(fun g ->
178+ // task {
179+ // let! (r: HttpResponseMessage) = g.Environment.Client.GetAsync("/Hello")
180+ // return! r.Content.ReadAsStringAsync()
181+ // })
182+ // |> THEN(fun w ->
183+ // let _ = ("hello world 1,2,3" = w.AssertData)
184+ // ())
185+ // |> END
0 commit comments