You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://stand-with-ukraine.pp.ua)
[](https://stand-with-ukraine.pp.ua)
To use the CE, you must build your CE object first by passing the generic Startup type argument.
13
-
For how the library is implemented, it still needs you to provide a Startup class,
14
-
future versions might make use of Program only from minimal API (this already uses WebApplication only anyway).
10
+
# Easy API Testing 🧞♀️
11
+
12
+
You have an ASP NET NET6+ (NET6 is LTS in 2023) aspnetcore API, and you want to simplify HTTP stubs for [integration
13
+
testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-9.0) using `WebApplicationFactory`,
14
+
but you find that a bit cumbersome sometimes?
15
+
16
+
this library is here to help you!
17
+
18
+
## Mechanics
19
+
20
+
This library makes use of [F# computation expressions](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions) to hide some complexity of `WebApplicationFactory` and provide the user with a *domain specific language* (DSL) for integration tests in aspnetcore apps.
21
+
The best way to understand how it all works is checking the [code](https://github.com/jkone27/fsharp-integration-tests/blob/249c3244cd7e20e2168b82a49b6e7e14f2ad1004/ApiStub.FSharp/CE.fs#L176) and this member CE method `GetFactory()` in scope.
22
+
23
+
If you have ideas for improvements feel free to open an issue/discussion!
24
+
I do this on my own time, so support is limited but contributions/PRs are welcome 🙏
15
25
16
-
**How** does the library work? the best way to understand it is checking this line of [code](https://github.com/jkone27/fsharp-integration-tests/blob/249c3244cd7e20e2168b82a49b6e7e14f2ad1004/ApiStub.FSharp/CE.fs#L176) and the member CE method `GetFactory()` in scope.
26
+
## Features 👨🏻🔬
17
27
28
+
***HTTP client mock DSL**:
29
+
* supports main HTTP verbs
30
+
* support for JSON payload for automatic object serialization
* to express tests in gherkin GIVEN, WHEN, THEN format if you want to
33
+
* EXTRAS
34
+
* utilities for test setup and more...
18
35
19
-
## USAGE
36
+
## Usage
37
+
38
+
To use the CE, you must build your CE object first by passing the generic Startup type argument.
20
39
21
40
Suppose your server registers 2 API clients internally to make calls to other services, say to the outbound routes `externalApi` and `anotherApi`,
22
41
one client using `GET` and another using `POST` methods inside your API client code.
@@ -53,9 +72,11 @@ module Tests =
53
72
}
54
73
```
55
74
56
-
## HTTP MOCKING METHODS
75
+
## HTTP Methods 🚕
76
+
77
+
Available HTTP methods in the test dsl to "mock" HTTP client responses are the following:
57
78
58
-
Available HTTP mocking methods in the test dsl are:
79
+
### Basic
59
80
60
81
*`GET`, `PUT`, `POST`, `DELETE` - for accessing request, route parameters and sending back HttpResponseMessage (e.g. using R_JSON or other constructors)
61
82
@@ -68,12 +89,16 @@ Available HTTP mocking methods in the test dsl are:
68
89
)
69
90
```
70
91
92
+
### JSON
93
+
71
94
*`GETJ`, `PUTJ`, `POSTJ`, `DELETEJ` - for objects converted to JSON content
72
95
73
96
```fsharp
74
97
GETJ "/yetAnotherOne" {| Success = true |}
75
98
```
76
99
100
+
### Async (task)
101
+
77
102
*`GET_ASYNC`, `PUT_ASYNC`, `POST_ASYNC`, `DELETE_ASYNC` - for handling asynchronous requests inside a task computation expression (async/await) and mock dynamically
*`WITH_SERVICES`: to override your ConfigureServices for tests
101
126
*`WITH_TEST_SERVICES`: to override your specific test services (a bit redundant in some cases, depending on the need)
102
127
103
-
## BDD Extensions
128
+
## BDD (gherkin) Extensions 🥒
104
129
105
130
You can use some BDD extension to perform [Gherkin-like setups and assertions](https://cucumber.io/docs/gherkin/reference/)
106
131
@@ -175,12 +200,13 @@ module BDDTests =
175
200
176
201
Please take a look at the examples in the `test` folder for more details on the usage.
177
202
178
-
## ApiStub.FSharp.Stubbery
203
+
## ApiStub.FSharp.Stubbery ⚠️ 🐦
179
204
180
205
A version using the [Stubbery](https://github.com/markvincze/Stubbery) library is also present for "compatibility" when migrating from `stubbery` versions of pre existing integration tests, in your integration tests setup.
181
206
182
207
In general, it's advised to not have dependencies or run any in-memory HTTP server if possible, so the minimal version is preferred.
183
208
209
+
NOTICE ⚠️: Stubbery will not be supported in adding new features or eventually might be not supported at all in the future.
184
210
185
211
```fsharp
186
212
open ApiStub.FSharp.Stubbery.StubberyCE
@@ -213,7 +239,7 @@ module Tests =
213
239
```
214
240
215
241
216
-
## How to Contribute
242
+
## How to Contribute ✍️
217
243
218
244
* Search for an open issue or report one, and check if a similar issue was reported first
219
245
* feel free to get in touch, to fork and check out the repo
0 commit comments