Skip to content

Commit 4c17015

Browse files
authored
Update README.md
1 parent 2f114d1 commit 4c17015

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

README.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1-
[![Ceasefire Now](https://badge.techforpalestine.org/ceasefire-now)](https://techforpalestine.org/learn-more)
2-
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
3-
<a href='https://juststopoil.org/' target="_blank"><img alt='JUST_STOP_OIL' src='https://img.shields.io/badge/Just_STOP OIL-100000?style=plastic&logo=JUST_STOP_OIL&logoColor=white&labelColor=FFA600&color=000000'/></a>
1+
# ApiStub.FSharp [![NuGet Badge](https://img.shields.io/nuget/v/ApiStub.FSharp)](https://www.nuget.org/packages/ApiStub.FSharp) 🦔
42

3+
<img width="331" alt="Screenshot 2024-12-16 at 13 01 33" src="https://github.com/user-attachments/assets/5095d6cb-63bb-4644-836f-99b5355870fe" />
54

6-
# ApiStub.FSharp [![NuGet Badge](https://img.shields.io/nuget/v/ApiStub.FSharp)](https://www.nuget.org/packages/ApiStub.FSharp)
75

8-
You have an ASP NET NET6+ (NET6 is LTS in 2023) dotnet API, and you want to simplify HTTP stubs for integration
9-
testing, so you can make use of these Computation Expressions (CE) to simplify
10-
your tests with some integration testing HTTP stubs DSL.
6+
[![Ceasefire Now](https://badge.techforpalestine.org/ceasefire-now)](https://techforpalestine.org/learn-more)
7+
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
8+
<a href='https://juststopoil.org/' target="_blank"><img alt='JUST_STOP_OIL' src='https://img.shields.io/badge/Just_STOP OIL-100000?style=plastic&logo=JUST_STOP_OIL&logoColor=white&labelColor=FFA600&color=000000'/></a>
119

12-
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 🙏
1525

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 👨🏻‍🔬
1727

28+
* **HTTP client mock DSL**:
29+
* supports main HTTP verbs
30+
* support for JSON payload for automatic object serialization
31+
* **BDD spec dsl extension** (behaviour driven development)
32+
* to express tests in gherkin GIVEN, WHEN, THEN format if you want to
33+
* EXTRAS
34+
* utilities for test setup and more...
1835

19-
## USAGE
36+
## Usage
37+
38+
To use the CE, you must build your CE object first by passing the generic Startup type argument.
2039

2140
Suppose your server registers 2 API clients internally to make calls to other services, say to the outbound routes `externalApi` and `anotherApi`,
2241
one client using `GET` and another using `POST` methods inside your API client code.
@@ -53,9 +72,11 @@ module Tests =
5372
}
5473
```
5574

56-
## HTTP MOCKING METHODS
75+
## HTTP Methods 🚕
76+
77+
Available HTTP methods in the test dsl to "mock" HTTP client responses are the following:
5778

58-
Available HTTP mocking methods in the test dsl are:
79+
### Basic
5980

6081
* `GET`, `PUT`, `POST`, `DELETE` - for accessing request, route parameters and sending back HttpResponseMessage (e.g. using R_JSON or other constructors)
6182

@@ -68,12 +89,16 @@ Available HTTP mocking methods in the test dsl are:
6889
)
6990
```
7091

92+
### JSON
93+
7194
* `GETJ`, `PUTJ`, `POSTJ`, `DELETEJ` - for objects converted to JSON content
7295

7396
```fsharp
7497
GETJ "/yetAnotherOne" {| Success = true |}
7598
```
7699

100+
### Async (task)
101+
77102
* `GET_ASYNC`, `PUT_ASYNC`, `POST_ASYNC`, `DELETE_ASYNC` - for handling asynchronous requests inside a task computation expression (async/await) and mock dynamically
78103

79104
```fsharp
@@ -87,20 +112,20 @@ GETJ "/yetAnotherOne" {| Success = true |}
87112
)
88113
```
89114

90-
## HTTP RESPONSE CONSTRUCTORS
115+
### Http response helpers 👨🏽‍🔧
91116

92117
Available HTTP content constructors are:
93118

94119
* `R_TEXT`: returns plain text
95120
* `R_JSON`: returns JSON
96121
* `R_ERROR`: returns an HTTP error
97122

98-
## Configure Services HELPERS
123+
## Configure Services Helpers 🪈
99124

100125
* `WITH_SERVICES`: to override your ConfigureServices for tests
101126
* `WITH_TEST_SERVICES`: to override your specific test services (a bit redundant in some cases, depending on the need)
102127

103-
## BDD Extensions
128+
## BDD (gherkin) Extensions 🥒
104129

105130
You can use some BDD extension to perform [Gherkin-like setups and assertions](https://cucumber.io/docs/gherkin/reference/)
106131

@@ -175,12 +200,13 @@ module BDDTests =
175200

176201
Please take a look at the examples in the `test` folder for more details on the usage.
177202

178-
## ApiStub.FSharp.Stubbery
203+
## ApiStub.FSharp.Stubbery ⚠️ 🐦
179204

180205
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.
181206

182207
In general, it's advised to not have dependencies or run any in-memory HTTP server if possible, so the minimal version is preferred.
183208

209+
NOTICE ⚠️: Stubbery will not be supported in adding new features or eventually might be not supported at all in the future.
184210

185211
```fsharp
186212
open ApiStub.FSharp.Stubbery.StubberyCE
@@ -213,7 +239,7 @@ module Tests =
213239
```
214240

215241

216-
## How to Contribute
242+
## How to Contribute ✍️
217243

218244
* Search for an open issue or report one, and check if a similar issue was reported first
219245
* feel free to get in touch, to fork and check out the repo

0 commit comments

Comments
 (0)