├── .fantomasignore ├── commitlint.config.js ├── docs ├── img │ ├── logo.png │ ├── favicon.ico │ └── ApiStub.FSharp.png ├── _body.html └── index.md ├── samples ├── web-csharp │ ├── test │ │ ├── Program.fs │ │ ├── Tests.fs │ │ ├── Web.CSharp.Test.fsproj │ │ └── LegacyTests.fs │ ├── src │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ ├── Web.CSharp.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ └── Services.cs │ ├── docker-compose.yaml │ ├── mock-data │ │ └── db.json │ ├── JsonServerDocker │ └── Web.CSharp.sln └── web │ ├── test │ ├── Web.Sample.Test │ │ ├── Program.fs │ │ ├── Tests.fs │ │ └── Web.Sample.Test.fsproj │ └── Web.Sample.Csharp.Test │ │ ├── Web.Sample.Csharp.Test.csproj │ │ └── CSharpTests.cs │ ├── src │ └── Web.Sample │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ ├── Web.Sample.fsproj │ │ ├── Properties │ │ └── launchSettings.json │ │ └── Program.fs │ └── Web.Sample.sln ├── src ├── appsettings.Development.json ├── appsettings.json ├── WeatherForecast.fs ├── app.fsproj ├── Properties │ └── launchSettings.json ├── Controllers │ └── WeatherForecastController.fs └── Program.fs ├── package.json ├── .husky ├── task-runner.json ├── commit-msg └── pre-commit ├── Directory.Build.props ├── .github └── workflows │ ├── build.yml │ ├── docs.yaml │ └── publish.yml ├── .config └── dotnet-tools.json ├── CHANGELOG.md ├── ApiStub.FSharp ├── Csharp.fs ├── BuilderExtensions.fs ├── HttpResponseHelpers.fs ├── ApiStub.FSharp.fsproj ├── DelegatingHandlers.fs ├── BDD.fs └── CE.fs ├── LICENSE ├── test ├── ApiStub.FSharp.Tests.fsproj ├── BDDTests.fs ├── swagger.json ├── BuilderExtensionsTests.fs └── CETests.fs ├── ApiStub.FSharp.sln ├── README.md ├── .gitignore └── bun.lock /.fantomasignore: -------------------------------------------------------------------------------- 1 | samples 2 | samples/** -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | export default { extends: ['@commitlint/config-conventional'] }; 2 | -------------------------------------------------------------------------------- /docs/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkone27/fsharp-integration-tests/HEAD/docs/img/logo.png -------------------------------------------------------------------------------- /samples/web-csharp/test/Program.fs: -------------------------------------------------------------------------------- 1 | module Program 2 | 3 | [] 4 | let main _ = 0 5 | -------------------------------------------------------------------------------- /docs/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkone27/fsharp-integration-tests/HEAD/docs/img/favicon.ico -------------------------------------------------------------------------------- /samples/web/test/Web.Sample.Test/Program.fs: -------------------------------------------------------------------------------- 1 | module Program 2 | 3 | [] 4 | let main _ = 0 5 | -------------------------------------------------------------------------------- /docs/img/ApiStub.FSharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkone27/fsharp-integration-tests/HEAD/docs/img/ApiStub.FSharp.png -------------------------------------------------------------------------------- /src/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": {}, 3 | "type": "module", 4 | "devDependencies": { 5 | "@commitlint/cli": "^19.8.1", 6 | "@commitlint/config-conventional": "^19.8.1" 7 | } 8 | } -------------------------------------------------------------------------------- /src/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /samples/web-csharp/src/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/web/src/Web.Sample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/web-csharp/src/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /samples/web/src/Web.Sample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /samples/web-csharp/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | mock-server: 5 | container_name: json-server 6 | build: 7 | context: . 8 | dockerfile: JsonServerDocker 9 | ports: 10 | - "3000:3000" 11 | volumes: 12 | - ./mock-data:/app -------------------------------------------------------------------------------- /samples/web-csharp/src/Web.CSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /samples/web-csharp/mock-data/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "persons": [ 3 | { 4 | "id": "1", 5 | "name": "John", 6 | "age": 30 7 | }, 8 | { 9 | "id": "2", 10 | "name": "Jane", 11 | "age": 25 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /src/WeatherForecast.fs: -------------------------------------------------------------------------------- 1 | namespace fsharpintegrationtests 2 | 3 | open System 4 | 5 | type WeatherForecast = 6 | { Date: DateTime 7 | TemperatureC: int 8 | Summary: string } 9 | 10 | member this.TemperatureF = 32.0 + (float this.TemperatureC / 0.5556) 11 | 12 | type Hello = { Ok: string } 13 | -------------------------------------------------------------------------------- /docs/_body.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /samples/web-csharp/JsonServerDocker: -------------------------------------------------------------------------------- 1 | # sample usage 2 | # https://github.com/typicode/json-server 3 | # http://localhost:3000/persons?age=25 4 | # http://localhost:3000/persons/1 5 | 6 | FROM node:alpine3.19 7 | RUN mkdir -p /app 8 | WORKDIR /app 9 | RUN npm install -g json-server 10 | CMD ["json-server", "--watch", "db.json", "--host", "0.0.0.0"] -------------------------------------------------------------------------------- /samples/web/src/Web.Sample/Web.Sample.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.husky/task-runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://alirezanet.github.io/Husky.Net/schema.json", 3 | "tasks": [ 4 | { 5 | "name": "fantomas-format-staged-files", 6 | "group": "pre-commit", 7 | "command": "dotnet", 8 | "args": [ 9 | "fantomas", 10 | "${staged}" 11 | ], 12 | "include": [ 13 | "**/*.fs", 14 | "**/*.fsx", 15 | "**/*.fsi" 16 | ] 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /samples/web-csharp/test/Tests.fs: -------------------------------------------------------------------------------- 1 | module Web.CSharp.Tests.WithCe 2 | 3 | open System 4 | open Xunit 5 | open ApiStub.FSharp 6 | open ApiStub.FSharp.CE 7 | open System.Net.Http.Json 8 | 9 | let ce = (new TestWebAppFactoryBuilder()) { 10 | GETJ "persons" [{| Name = "John" ; Age = 30 |}] 11 | } 12 | 13 | [] 14 | let ``Test with CE and HTTP mocking`` () = 15 | task { 16 | use f = ce.GetFactory() 17 | let c = f.CreateClient() 18 | 19 | let! r = c.GetFromJsonAsync<{| Age: int|}>("/john") 20 | 21 | Assert.Equal(30, r.Age) 22 | } 23 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | ## husky task runner examples ------------------- 5 | ## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky' 6 | 7 | ## run all tasks 8 | #husky run 9 | 10 | ### run all tasks with group: 'group-name' 11 | #husky run --group group-name 12 | 13 | ## run task with name: 'task-name' 14 | #husky run --name task-name 15 | 16 | ## pass hook arguments to task 17 | #husky run --args "$1" "$2" 18 | 19 | ## or put your custom commands ------------------- 20 | #echo 'Husky.Net is awesome!' 21 | 22 | npx --no -- commitlint --edit 23 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | ## husky task runner examples ------------------- 5 | ## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky' 6 | 7 | ## run all tasks 8 | #husky run 9 | 10 | ### run all tasks with group: 'group-name' 11 | #husky run --group group-name 12 | 13 | ## run task with name: 'task-name' 14 | #husky run --name task-name 15 | 16 | ## pass hook arguments to task 17 | #husky run --args "$1" "$2" 18 | 19 | ## or put your custom commands ------------------- 20 | #echo 'Husky.Net is awesome!' 21 | 22 | dotnet husky run --group pre-commit 23 | -------------------------------------------------------------------------------- /src/app.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://github.com/jkone27/fsharp-integration-tests 4 | https://raw.githubusercontent.com/jkone27/fsharp-integration-tests/refs/heads/main/LICENSE 5 | https://github.com/jkone27/fsharp-integration-tests/blob/master/CHANGELOG.md 6 | https://github.com/jkone27/fsharp-integration-tests 7 | true 8 | default 9 | 10 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Setup .NET 19 | uses: actions/setup-dotnet@v4 20 | with: 21 | dotnet-version: 8.0.x 22 | source-url: https://api.nuget.org/v3/index.json 23 | env: 24 | NUGET_AUTH_TOKEN: ${{secrets.NUGET_KEY}} 25 | 26 | - name: Restore dependencies 27 | run: dotnet restore 28 | - name: Build 29 | run: dotnet build --no-restore 30 | - name: Test 31 | run: dotnet test --no-build --verbosity normal 32 | -------------------------------------------------------------------------------- /samples/web-csharp/src/Program.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | var builder = WebApplication.CreateBuilder(args); 4 | 5 | builder.Services.AddHttpClient(); 6 | builder.Services.AddTransient(); 7 | var app = builder.Build(); 8 | 9 | app.MapGet("/", () => "Hello World!"); 10 | 11 | app.MapGet("/john", 12 | async ctx => { 13 | var repo = ctx.RequestServices.GetRequiredService(); 14 | 15 | var john = await repo.GetPerson("John"); 16 | 17 | ctx.Response.StatusCode = 200; 18 | await ctx.Response.WriteAsJsonAsync(john); 19 | }); 20 | 21 | app.Run(); 22 | 23 | // NOTE: add this to be able to test with WebApplicationFactory 24 | public partial class Program { } 25 | -------------------------------------------------------------------------------- /samples/web-csharp/src/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "http": { 5 | "commandName": "Project", 6 | "dotnetRunMessages": true, 7 | "launchBrowser": true, 8 | "applicationUrl": "http://localhost:5078", 9 | "environmentVariables": { 10 | "ASPNETCORE_ENVIRONMENT": "Development" 11 | } 12 | }, 13 | "https": { 14 | "commandName": "Project", 15 | "dotnetRunMessages": true, 16 | "launchBrowser": true, 17 | "applicationUrl": "https://localhost:7024;http://localhost:5078", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/web/src/Web.Sample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "http": { 5 | "commandName": "Project", 6 | "dotnetRunMessages": true, 7 | "launchBrowser": true, 8 | "applicationUrl": "http://localhost:5003", 9 | "environmentVariables": { 10 | "ASPNETCORE_ENVIRONMENT": "Development" 11 | } 12 | }, 13 | "https": { 14 | "commandName": "Project", 15 | "dotnetRunMessages": true, 16 | "launchBrowser": true, 17 | "applicationUrl": "https://localhost:7222;http://localhost:5003", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "fantomas": { 6 | "version": "7.0.1", 7 | "commands": [ 8 | "fantomas" 9 | ], 10 | "rollForward": false 11 | }, 12 | "husky": { 13 | "version": "0.7.2", 14 | "commands": [ 15 | "husky" 16 | ], 17 | "rollForward": false 18 | }, 19 | "fsdocs-tool": { 20 | "version": "20.0.1", 21 | "commands": [ 22 | "fsdocs" 23 | ], 24 | "rollForward": false 25 | }, 26 | "versionize": { 27 | "version": "2.3.1", 28 | "commands": [ 29 | "versionize" 30 | ], 31 | "rollForward": false 32 | }, 33 | "dotnet-outdated-tool": { 34 | "version": "4.6.8", 35 | "commands": [ 36 | "dotnet-outdated" 37 | ], 38 | "rollForward": false 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /samples/web/test/Web.Sample.Test/Tests.fs: -------------------------------------------------------------------------------- 1 | module Tests 2 | 3 | open System 4 | open Xunit 5 | open ApiStub.FSharp 6 | open System.Threading.Tasks 7 | open ApiStub.FSharp.CE 8 | open Web.Sample 9 | open System.Net.Http.Json 10 | 11 | 12 | let webAppFactory = 13 | new TestWebAppFactoryBuilder() 14 | |> fun x -> x { 15 | GETJ Web.Sample.Clients.Routes.name {| Name = "Peter" |} 16 | GETJ Web.Sample.Clients.Routes.age {| Age = 100 |} 17 | } 18 | |> _.GetFactory() 19 | 20 | [] 21 | let ``Peter is 100 years old`` () = 22 | task { 23 | let c = webAppFactory.CreateClient() 24 | 25 | let! res = c.PostAsJsonAsync(Web.Sample.Services.routeOne, {| |}) 26 | let! responseText = res.Content.ReadAsStringAsync() 27 | 28 | Assert.True(res.IsSuccessStatusCode) 29 | Assert.Contains("Peter", responseText) 30 | Assert.Contains("100", responseText) 31 | } 32 | -------------------------------------------------------------------------------- /src/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:21627", 8 | "sslPort": 44329 9 | } 10 | }, 11 | "profiles": { 12 | "fsharpintegrationtests": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "weatherforecast", 17 | "applicationUrl": "https://localhost:7033;http://localhost:5257", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "weatherforecast", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /samples/web/test/Web.Sample.Csharp.Test/Web.Sample.Csharp.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /samples/web/test/Web.Sample.Test/Web.Sample.Test.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | false 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. See [versionize](https://github.com/versionize/versionize) for commit guidelines. 4 | 5 | ### Features 6 | 7 | * renamed TestClient to TestWebAppFactoryBuilder, fix to publish and docs ([a3a90a1](https://www.github.com/jkone27/fsharp-integration-tests/commit/a3a90a1bc91b880225d9db07f67aa794859bf7be)) 8 | 9 | 10 | ## [1.4.0](https://www.github.com/jkone27/fsharp-integration-tests/releases/tag/v1.4.0) (2025-05-12) 11 | 12 | 13 | ## [1.3.0](https://www.github.com/jkone27/fsharp-integration-tests/releases/tag/v1.3.0) (2025-05-10) 14 | 15 | ### Features 16 | 17 | * removed stubbery support, end of life, added multitarget for net8 lts, net6 is DEPRECATED ([41e7492](https://www.github.com/jkone27/fsharp-integration-tests/commit/41e74920d06e054232756cb626c09e4e77dc1032)) 18 | 19 | 20 | ## [1.2.5](https://www.github.com/jkone27/fsharp-integration-tests/releases/tag/v1.2.5) (2025-05-10) 21 | 22 | -------------------------------------------------------------------------------- /samples/web-csharp/src/Services.cs: -------------------------------------------------------------------------------- 1 | // https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient 2 | 3 | // DTO 4 | public record Person(string Name, int Age); 5 | 6 | 7 | // http typed client 8 | public class PersonClient 9 | { 10 | private HttpClient httpClient; 11 | private readonly Random rnd = new Random(); 12 | 13 | public PersonClient(HttpClient httpClient) 14 | { 15 | this.httpClient = httpClient; 16 | } 17 | 18 | public async Task GetByName(string name) 19 | { 20 | var result = await httpClient.GetFromJsonAsync($"persons?name={name}"); 21 | 22 | return result?.FirstOrDefault(); 23 | } 24 | 25 | } 26 | 27 | // service using this client 28 | public class PersonRepository 29 | { 30 | private readonly PersonClient personClient; 31 | public PersonRepository(PersonClient personClient) 32 | { 33 | this.personClient = personClient; 34 | } 35 | 36 | public Task GetPerson(string name) => personClient.GetByName(name); 37 | } -------------------------------------------------------------------------------- /ApiStub.FSharp/Csharp.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.Fsharp.CSharp 2 | 3 | open System.Runtime.CompilerServices 4 | open ApiStub.FSharp.CE 5 | 6 | [] 7 | type CsharpExtensions = 8 | 9 | [] 10 | static member GETJ<'a when 'a: not struct>(x: TestWebAppFactoryBuilder<'a>, route: string, stub: obj) = 11 | x.GetJson(x, route, stub) 12 | 13 | [] 14 | static member POSTJ<'a when 'a: not struct>(x: TestWebAppFactoryBuilder<'a>, route: string, stub: obj) = 15 | x.PostJson(x, route, stub) 16 | 17 | [] 18 | static member PUTJ<'a when 'a: not struct>(x: TestWebAppFactoryBuilder<'a>, route: string, stub: obj) = 19 | x.PutJson(x, route, stub) 20 | 21 | [] 22 | static member DELETEJ<'a when 'a: not struct>(x: TestWebAppFactoryBuilder<'a>, route: string, stub: obj) = 23 | x.DeleteJson(x, route, stub) 24 | 25 | [] 26 | static member PATCHJ<'a when 'a: not struct>(x: TestWebAppFactoryBuilder<'a>, route: string, stub: obj) = 27 | x.PatchJson(x, route, stub) 28 | -------------------------------------------------------------------------------- /samples/web-csharp/test/Web.CSharp.Test.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | false 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 jkone27 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ApiStub.FSharp/BuilderExtensions.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp 2 | 3 | open Microsoft.AspNetCore.Mvc.Testing 4 | open Microsoft.Extensions.DependencyInjection 5 | open Microsoft.AspNetCore.Hosting 6 | open System.Threading.Tasks 7 | open System 8 | open Microsoft.AspNetCore.TestHost 9 | 10 | /// Utility methods for aspnetcore configuration 11 | module BuilderExtensions = 12 | 13 | let configure_services (configure: IServiceCollection -> 'a) (builder: IWebHostBuilder) : IWebHostBuilder = 14 | builder.ConfigureServices(fun s -> configure (s) |> ignore) 15 | 16 | let configure_test_services (configure: IServiceCollection -> 'a) (builder: IWebHostBuilder) : IWebHostBuilder = 17 | builder.ConfigureTestServices(fun s -> configure (s) |> ignore) 18 | 19 | let web_host_builder (builder: IWebHostBuilder -> 'a) (factory: WebApplicationFactory<'T>) = 20 | factory.WithWebHostBuilder(fun b -> builder (b) |> ignore) 21 | 22 | let web_configure_services configure = 23 | configure_services configure |> web_host_builder 24 | 25 | let web_configure_test_services configure = 26 | configure_test_services configure |> web_host_builder 27 | -------------------------------------------------------------------------------- /samples/web/test/Web.Sample.Csharp.Test/CSharpTests.cs: -------------------------------------------------------------------------------- 1 | namespace Web.Sample.Csharp.Test; 2 | 3 | using System; 4 | using Xunit; 5 | using System.Threading.Tasks; 6 | using Web.Sample; 7 | using System.Net.Http.Json; 8 | using Microsoft.AspNetCore.Mvc.Testing; 9 | using static ApiStub.FSharp.CE; 10 | using static ApiStub.Fsharp.CSharp.CsharpExtensions; 11 | 12 | public class CSharpTests 13 | { 14 | private static WebApplicationFactory getWebAppFactory() => 15 | // create an instance of the test client builder 16 | new TestWebAppFactoryBuilder() 17 | .GETJ(Clients.Routes.name, new { Name = "Peter" }) 18 | .GETJ(Clients.Routes.age, new { Age = 100 }) 19 | .GetFactory(); 20 | 21 | // one app factory instance is oke for all tests 22 | private static readonly WebApplicationFactory webAppFactory = getWebAppFactory(); 23 | 24 | [Fact] 25 | public async Task CsharpTest_Peter_is_100_years_old() 26 | { 27 | var client = webAppFactory.CreateClient(); 28 | 29 | var response = await client.PostAsJsonAsync(Services.routeOne, new { }); 30 | 31 | var responseText = await response.Content.ReadAsStringAsync(); 32 | 33 | Assert.True(response.IsSuccessStatusCode); 34 | Assert.Contains("Peter", responseText); 35 | Assert.Contains("100", responseText); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/docs.yaml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | 3 | # Trigger this Action when new code is pushed to the main branch 4 | on: 5 | push: 6 | branches: 7 | - main 8 | 9 | # We need some permissions to publish to Github Pages 10 | permissions: 11 | contents: write 12 | pages: write 13 | id-token: write 14 | 15 | jobs: 16 | build: 17 | runs-on: ubuntu-latest 18 | steps: 19 | # Checkout the source code 20 | - uses: actions/checkout@v4 21 | # Setup dotnet, please use a global.json to ensure the right SDK is used! 22 | - name: Setup .NET 23 | uses: actions/setup-dotnet@v4 24 | # Restore the local tools 25 | - name: Restore tools 26 | run: dotnet tool restore 27 | # Build the code for the API documentation 28 | - name: Build code 29 | run: dotnet build -c Release ApiStub.FSharp.sln 30 | # Generate the documentation files 31 | - name: Generate the documentation' 32 | run: dotnet fsdocs build --properties Configuration=Release --parameters root "https://${{github.repository_owner}}.github.io/fsharp-integration-tests/" 33 | # Upload the static files 34 | - name: Upload documentation 35 | uses: actions/upload-pages-artifact@v3 36 | with: 37 | path: ./output 38 | 39 | # GitHub Actions recommends deploying in a separate job. 40 | deploy: 41 | runs-on: ubuntu-latest 42 | needs: build 43 | steps: 44 | - name: Deploy to GitHub Pages 45 | id: deployment 46 | uses: actions/deploy-pages@v4 -------------------------------------------------------------------------------- /test/ApiStub.FSharp.Tests.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | false 5 | true 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | all 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/web-csharp/Web.CSharp.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.CSharp", "src\Web.CSharp.csproj", "{69EC9787-159F-43CC-A179-AFF77D4E85A5}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CED50CB1-C8A7-45D2-B9AA-A54CEEF16418}" 9 | EndProject 10 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Web.CSharp.Test", "test\Web.CSharp.Test.fsproj", "{7C8E4848-201B-456F-994E-3701B4E0DFCD}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {69EC9787-159F-43CC-A179-AFF77D4E85A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {69EC9787-159F-43CC-A179-AFF77D4E85A5}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {69EC9787-159F-43CC-A179-AFF77D4E85A5}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {69EC9787-159F-43CC-A179-AFF77D4E85A5}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {7C8E4848-201B-456F-994E-3701B4E0DFCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {7C8E4848-201B-456F-994E-3701B4E0DFCD}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {7C8E4848-201B-456F-994E-3701B4E0DFCD}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {7C8E4848-201B-456F-994E-3701B4E0DFCD}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(NestedProjects) = preSolution 31 | {7C8E4848-201B-456F-994E-3701B4E0DFCD} = {CED50CB1-C8A7-45D2-B9AA-A54CEEF16418} 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | # trigger only on completion of Build on main 5 | workflow_run: 6 | workflows: ["Build"] 7 | branches: 8 | - main 9 | types: 10 | - completed 11 | 12 | jobs: 13 | publish: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Setup .NET 21 | uses: actions/setup-dotnet@v4 22 | with: 23 | dotnet-version: 8.0.x 24 | source-url: https://api.nuget.org/v3/index.json 25 | env: 26 | NUGET_AUTH_TOKEN: ${{secrets.NUGET_KEY}} 27 | 28 | - name: Setup Git 29 | uses: fregante/setup-git-user@v2 30 | 31 | - name: Restore Dotnet Tools 32 | run: dotnet tool restore 33 | 34 | - name: Run Versionize 35 | id: versionize 36 | run: dotnet versionize 37 | continue-on-error: true 38 | 39 | - name: Push version changes 40 | if: steps.versionize.outcome == 'success' 41 | uses: ad-m/github-push-action@master 42 | with: 43 | github_token: ${{ secrets.GITHUB_TOKEN }} 44 | branch: main 45 | tags: true 46 | 47 | # Checkout the repository again to ensure the latest changes are available 48 | - name: Checkout repository after versionize 49 | if: steps.versionize.outcome == 'success' 50 | uses: actions/checkout@v4 51 | 52 | - name: No release required 53 | if: steps.versionize.outcome != 'success' 54 | run: echo "Skipping publishing. No release required." 55 | 56 | - name: Build 57 | if: steps.versionize.outcome == 'success' 58 | run: dotnet build ./ApiStub.FSharp --configuration Release 59 | 60 | - name: Pack 61 | if: steps.versionize.outcome == 'success' 62 | run: dotnet pack ./ApiStub.FSharp --no-build --output ./nupkgs --include-source --configuration Release --include-symbols 63 | 64 | - name: Push Package 65 | if: steps.versionize.outcome == 'success' 66 | run: dotnet nuget push ./nupkgs/*.nupkg --api-key ${{secrets.NUGET_KEY}} --skip-duplicate 67 | -------------------------------------------------------------------------------- /src/Controllers/WeatherForecastController.fs: -------------------------------------------------------------------------------- 1 | namespace fsharpintegrationtests.Controllers 2 | 3 | open System 4 | open System.Collections.Generic 5 | open System.Linq 6 | open System.Threading.Tasks 7 | open Microsoft.AspNetCore.Mvc 8 | open Microsoft.Extensions.Logging 9 | open fsharpintegrationtests 10 | open System.Threading.Tasks 11 | open System.Net.Http 12 | open System.Net.Http.Json 13 | 14 | [] 15 | [] 16 | type WeatherForecastController(logger: ILogger) = 17 | inherit ControllerBase() 18 | 19 | let summaries = 20 | [| "Freezing" 21 | "Bracing" 22 | "Chilly" 23 | "Cool" 24 | "Mild" 25 | "Warm" 26 | "Balmy" 27 | "Hot" 28 | "Sweltering" 29 | "Scorching" |] 30 | 31 | [] 32 | member _.Get() = 33 | let rng = System.Random() 34 | 35 | [| for index in 0..4 -> 36 | { Date = DateTime.Now.AddDays(float index) 37 | TemperatureC = rng.Next(-20, 55) 38 | Summary = summaries.[rng.Next(summaries.Length)] } |] 39 | 40 | 41 | [] 42 | [] 43 | type HelloController(logger: ILogger, httpClientFactory: IHttpClientFactory) = 44 | 45 | inherit ControllerBase() 46 | 47 | // https://stackoverflow.com/questions/23438416/why-is-httpclient-baseaddress-not-working 48 | 49 | [] 50 | member _.GetAsync() = 51 | task { 52 | 53 | let externalApiClient = httpClientFactory.CreateClient("externalApiClient") 54 | 55 | let! res = externalApiClient.GetAsync("externalApi") 56 | 57 | res.EnsureSuccessStatusCode() |> ignore 58 | 59 | let anotherApiClient = httpClientFactory.CreateClient("anotherApiClient") 60 | 61 | let! res2 = anotherApiClient.PostAsJsonAsync("anotherApi?test=123", {| Test = "Ok" |}) 62 | 63 | res2.EnsureSuccessStatusCode() |> ignore 64 | 65 | let! str = res2.Content.ReadAsStringAsync() 66 | 67 | let! res2 = res.Content.ReadFromJsonAsync() 68 | 69 | return res2 70 | } 71 | -------------------------------------------------------------------------------- /samples/web-csharp/test/LegacyTests.fs: -------------------------------------------------------------------------------- 1 | namespace Web.CSharp.Test 2 | 3 | open System 4 | open Xunit 5 | open Microsoft.AspNetCore.Mvc.Testing 6 | open Microsoft.AspNetCore.Hosting 7 | open Microsoft.Extensions.Configuration 8 | open Microsoft.Extensions.DependencyInjection 9 | open Microsoft.Extensions.Http 10 | open System.Net.Http.Json 11 | 12 | 13 | // TODO: before starting the tests, check that json-server is running in docker if running "e2e" simulation 14 | // docker compose up... 15 | 16 | 17 | type CustomAppFactory() = 18 | // references Web.CSharp.Program partial class 19 | inherit WebApplicationFactory() 20 | 21 | // here we configure the clients in the test server 22 | override this.ConfigureWebHost (builder: IWebHostBuilder): unit = 23 | builder.ConfigureServices(fun s -> 24 | s.ConfigureHttpClientDefaults(fun c -> 25 | c.ConfigureHttpClient(fun cc -> 26 | // testing e2e with docker compose 27 | // important, base address MUST end with / in aspnet 28 | // thanks - https://www.damirscorner.com/blog/posts/20240802-HttpClientBaseAddressPathMerging.html 29 | cc.BaseAddress <- new Uri("http://localhost:3000/", UriKind.Absolute) 30 | ) |> ignore 31 | ) |> ignore 32 | ) |> ignore 33 | base.ConfigureWebHost(builder) 34 | 35 | 36 | // e.g. for auth in test etc, this client is the test client 37 | override this.ConfigureClient (client: Net.Http.HttpClient): unit = 38 | base.ConfigureClient(client) 39 | 40 | type LegacyTests(factory: CustomAppFactory) = 41 | interface IClassFixture 42 | 43 | [] 44 | member this.GetHello () = task { 45 | 46 | let c = factory.CreateClient() 47 | 48 | let! hello = c.GetStringAsync("") 49 | 50 | Assert.True(hello.Contains("World")) 51 | } 52 | 53 | [] 54 | member this.GetJohnsAge () = task { 55 | 56 | let c = factory.CreateClient() 57 | 58 | let! john = c.GetFromJsonAsync<{| Age: int |}>("/john") 59 | 60 | Assert.Equal(30, john.Age) 61 | } -------------------------------------------------------------------------------- /test/BDDTests.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp.Tests 2 | 3 | open Xunit 4 | open fsharpintegrationtests 5 | open Microsoft.AspNetCore.Mvc.Testing 6 | open Microsoft.Extensions.DependencyInjection 7 | open Microsoft.AspNetCore.Hosting 8 | open SwaggerProvider 9 | open System.Threading.Tasks 10 | open System.Net.Http 11 | open System 12 | open Microsoft.AspNetCore.TestHost 13 | open Microsoft.Extensions.Http 14 | open Microsoft.AspNetCore.Routing.Template 15 | open Microsoft.AspNetCore.Routing.Patterns 16 | open Microsoft.AspNetCore.Routing 17 | open System.Net 18 | open System.Text.Json 19 | open Microsoft.AspNetCore.Http 20 | open System.Net.Http.Json 21 | open Swensen.Unquote 22 | open ApiStub.FSharp.CE 23 | open ApiStub.FSharp.BuilderExtensions 24 | open ApiStub.FSharp.HttpResponseHelpers 25 | open ApiStub.FSharp 26 | open ApiStub.FSharp.BDD 27 | open HttpResponseMessageExtensions 28 | open Xunit.Abstractions 29 | 30 | 31 | module BDDTests = 32 | 33 | let testce = new TestWebAppFactoryBuilder() 34 | 35 | 36 | [] 37 | let ``when i call /hello i get 'world' back with 200 ok`` () = 38 | 39 | let mutable expected = "_" 40 | let stubData = { Ok = "undefined" } 41 | 42 | testce { 43 | POSTJ "/another/anotherApi" {| Test = "NOT_USED_VAL" |} 44 | GET_ASYNC "/externalApi" (fun r _ -> task { return { stubData with Ok = expected } |> R_JSON }) 45 | } 46 | |> SCENARIO "when i call /Hello i get 'world' back with 200 ok" 47 | |> SETUP 48 | (fun s -> 49 | task { 50 | 51 | let test = s.TestWAFBuilder 52 | 53 | let f = test.GetFactory() 54 | 55 | return 56 | { Client = f.CreateClient() 57 | Factory = f 58 | Scenario = s 59 | FeatureStubData = stubData } 60 | }) 61 | (fun c -> c) 62 | |> GIVEN(fun g -> 63 | expected <- "world" 64 | expected |> Task.FromResult) 65 | |> WHEN(fun g -> 66 | task { 67 | let! (r: HttpResponseMessage) = g.Environment.Client.GetAsync("/Hello") 68 | return! r.Content.ReadFromJsonAsync() 69 | 70 | }) 71 | |> THEN(fun w -> Assert.Equal(w.Given.ArrangeData, w.AssertData.Ok)) 72 | |> END 73 | -------------------------------------------------------------------------------- /ApiStub.FSharp/HttpResponseHelpers.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp 2 | 3 | open System.Threading.Tasks 4 | open System.Net.Http 5 | open System 6 | open System.Net 7 | open System.Net.Http.Json 8 | open System.Text.Json 9 | 10 | module HttpResponseHelpers = 11 | 12 | let inline R_OK (contentType: string) content = 13 | let response = new HttpResponseMessage(HttpStatusCode.OK) 14 | response.Content <- new StringContent(content, Text.Encoding.UTF8, contentType) 15 | response 16 | 17 | let inline R_TEXT content = content |> R_OK "text/html" 18 | 19 | let inline R_JSON (x: obj) = 20 | x |> JsonSerializer.Serialize |> R_OK "application/json" 21 | 22 | let inline R_JSON_CONTENT (x: obj) = 23 | // this seems to be buggy, causing stream read exception with F# types!! 24 | let response = new HttpResponseMessage(HttpStatusCode.OK) 25 | response.Content <- JsonContent.Create(inputValue = x) 26 | response 27 | 28 | let inline R_ERROR statusCode content = 29 | let response = new HttpResponseMessage(statusCode) 30 | response.Content <- content 31 | response 32 | 33 | 34 | module HttpResponseMessageExtensions = 35 | 36 | open HttpResponseHelpers 37 | 38 | type System.Net.Http.HttpResponseMessage with 39 | 40 | member this.EnsureSuccessOrFailWithContent() = 41 | task { 42 | let! contentString = this.Content.ReadAsStringAsync() 43 | 44 | if this.IsSuccessStatusCode |> not then 45 | if contentString |> String.IsNullOrWhiteSpace then 46 | failwith 47 | $"{this.RequestMessage.Method} {this.RequestMessage.RequestUri.AbsolutePath}: unknown server error {this.StatusCode}" 48 | else 49 | failwith contentString 50 | 51 | return () 52 | } 53 | 54 | member this.EnsureSuccessAndParse<'a>() = 55 | task { 56 | let! contentString = this.Content.ReadAsStringAsync() 57 | 58 | if this.IsSuccessStatusCode |> not then 59 | if contentString |> String.IsNullOrWhiteSpace then 60 | failwith 61 | $"{this.RequestMessage.Method} {this.RequestMessage.RequestUri.AbsolutePath}: unknown server error {this.StatusCode}" 62 | else 63 | failwith contentString 64 | 65 | return contentString |> JsonSerializer.Deserialize<'a> 66 | } 67 | -------------------------------------------------------------------------------- /ApiStub.FSharp/ApiStub.FSharp.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0;net8.0 4 | true 5 | ApiStub.FSharp 6 | 1.4.0 7 | jkone27 8 | false 9 | MIT 10 | Aspnet;Testing;Integration Testing;dotnet;Stub 11 | true 12 | https://github.com/jkone27/fsharp-integration-tests.git 13 | git 14 | true 15 | true 16 | snupkg 17 | true 18 | true 19 | true 20 | true 21 | Library 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /samples/web/Web.Sample.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{969848AF-660B-4C8F-A732-86958A0A3F9D}" 7 | EndProject 8 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Web.Sample", "src\Web.Sample\Web.Sample.fsproj", "{09C4FAA7-792D-48F0-9AD0-77D99B5B337D}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3FA0092-6D80-4228-A143-E35105DAD823}" 11 | EndProject 12 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Web.Sample.Test", "test\Web.Sample.Test\Web.Sample.Test.fsproj", "{16F1F95C-D971-4F35-B1BA-D0CD6A7F5569}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Sample.Csharp.Test", "test\Web.Sample.Csharp.Test\Web.Sample.Csharp.Test.csproj", "{F9662931-A238-4FAD-81D9-50D81885EC55}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {09C4FAA7-792D-48F0-9AD0-77D99B5B337D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {09C4FAA7-792D-48F0-9AD0-77D99B5B337D}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {09C4FAA7-792D-48F0-9AD0-77D99B5B337D}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {09C4FAA7-792D-48F0-9AD0-77D99B5B337D}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {16F1F95C-D971-4F35-B1BA-D0CD6A7F5569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {16F1F95C-D971-4F35-B1BA-D0CD6A7F5569}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {16F1F95C-D971-4F35-B1BA-D0CD6A7F5569}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {16F1F95C-D971-4F35-B1BA-D0CD6A7F5569}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {F9662931-A238-4FAD-81D9-50D81885EC55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {F9662931-A238-4FAD-81D9-50D81885EC55}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {F9662931-A238-4FAD-81D9-50D81885EC55}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {F9662931-A238-4FAD-81D9-50D81885EC55}.Release|Any CPU.Build.0 = Release|Any CPU 37 | EndGlobalSection 38 | GlobalSection(NestedProjects) = preSolution 39 | {09C4FAA7-792D-48F0-9AD0-77D99B5B337D} = {969848AF-660B-4C8F-A732-86958A0A3F9D} 40 | {16F1F95C-D971-4F35-B1BA-D0CD6A7F5569} = {D3FA0092-6D80-4228-A143-E35105DAD823} 41 | {F9662931-A238-4FAD-81D9-50D81885EC55} = {D3FA0092-6D80-4228-A143-E35105DAD823} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /src/Program.fs: -------------------------------------------------------------------------------- 1 | namespace fsharpintegrationtests 2 | 3 | open Microsoft.Net.Http.Headers 4 | 5 | #nowarn "20" 6 | 7 | open System 8 | open System.Collections.Generic 9 | open System.IO 10 | open System.Linq 11 | open System.Threading.Tasks 12 | open Microsoft.AspNetCore 13 | open Microsoft.AspNetCore.Builder 14 | open Microsoft.AspNetCore.Hosting 15 | open Microsoft.AspNetCore.HttpsPolicy 16 | open Microsoft.Extensions.Configuration 17 | open Microsoft.Extensions.DependencyInjection 18 | open Microsoft.Extensions.Hosting 19 | open Microsoft.Extensions.Logging 20 | open Swashbuckle.AspNetCore 21 | 22 | // integration tests in fsharp rely on this atm 23 | type Startup(configuration: IConfiguration, env: IWebHostEnvironment) = 24 | 25 | abstract member ConfigureServices: IServiceCollection -> unit 26 | 27 | default this.ConfigureServices(services: IServiceCollection) = 28 | 29 | services.AddControllers() 30 | 31 | //make sure this is not the generic one 32 | services.AddHttpClient( 33 | "externalApiClient", 34 | configureClient = 35 | fun httpClient -> 36 | //generate your public request bin and replace here 37 | httpClient.BaseAddress <- new Uri("https://enfir17jla5z.x.pipedream.net/") 38 | () 39 | ) 40 | 41 | services.AddHttpClient( 42 | "anotherApiClient", 43 | configureClient = 44 | fun httpClient -> 45 | //generate your public request bin and replace here 46 | httpClient.BaseAddress <- new Uri("https://enfir17jla5z.x.pipedream.net/another/") 47 | () 48 | ) 49 | 50 | services.AddEndpointsApiExplorer() 51 | services.AddSwaggerGen() 52 | () 53 | 54 | abstract member Configure: IApplicationBuilder -> unit 55 | 56 | default this.Configure(app: IApplicationBuilder) = 57 | 58 | if env.IsDevelopment() then 59 | app.UseSwagger() 60 | app.UseSwaggerUI() 61 | () 62 | 63 | app.UseHttpsRedirection() 64 | 65 | app.UseAuthorization() 66 | 67 | app.UseRouting() 68 | app.UseEndpoints(fun o -> o.MapControllers() |> ignore) 69 | () 70 | 71 | 72 | module public Program = 73 | 74 | let createHost (args: string[]) = 75 | let builder = WebApplication.CreateBuilder(args) 76 | 77 | let st = new Startup(builder.Configuration, builder.Environment) 78 | 79 | st.ConfigureServices(builder.Services) 80 | 81 | let app = builder.Build() 82 | 83 | st.Configure(app) 84 | 85 | app 86 | 87 | [] 88 | let main args = 89 | 90 | let app = createHost args 91 | 92 | app.Run() 93 | 94 | 0 //exit 95 | -------------------------------------------------------------------------------- /ApiStub.FSharp.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32328.378 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "app", "src\app.fsproj", "{BF90DE53-4318-4F58-9889-D4173C24EB18}" 7 | EndProject 8 | Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "test", "test\ApiStub.FSharp.Tests.fsproj", "{8756BCBB-995D-436E-8D2F-CADAA325948B}" 9 | EndProject 10 | Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ApiStub.FSharp", "ApiStub.FSharp\ApiStub.FSharp.fsproj", "{F7EE43A1-C472-4B78-97AD-51B5435CC1BE}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D4C589F1-03B9-4E1D-BB6C-BFDFDD7AD169}" 13 | ProjectSection(SolutionItems) = preProject 14 | .gitignore = .gitignore 15 | .github\workflows\dotnet.yml = .github\workflows\dotnet.yml 16 | README.md = README.md 17 | testNuget.fsx = testNuget.fsx 18 | EndProjectSection 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {BF90DE53-4318-4F58-9889-D4173C24EB18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {BF90DE53-4318-4F58-9889-D4173C24EB18}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {BF90DE53-4318-4F58-9889-D4173C24EB18}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {BF90DE53-4318-4F58-9889-D4173C24EB18}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {8756BCBB-995D-436E-8D2F-CADAA325948B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {8756BCBB-995D-436E-8D2F-CADAA325948B}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {8756BCBB-995D-436E-8D2F-CADAA325948B}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {8756BCBB-995D-436E-8D2F-CADAA325948B}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {F7EE43A1-C472-4B78-97AD-51B5435CC1BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {F7EE43A1-C472-4B78-97AD-51B5435CC1BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {F7EE43A1-C472-4B78-97AD-51B5435CC1BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {F7EE43A1-C472-4B78-97AD-51B5435CC1BE}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {24264817-88F6-4E55-B1E2-18FD5BA8397D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {24264817-88F6-4E55-B1E2-18FD5BA8397D}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {24264817-88F6-4E55-B1E2-18FD5BA8397D}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {24264817-88F6-4E55-B1E2-18FD5BA8397D}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {38596924-DBFF-404B-B9F2-5F0449EC1F64} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /samples/web/src/Web.Sample/Program.fs: -------------------------------------------------------------------------------- 1 | namespace Web.Sample 2 | 3 | #nowarn 20 // to avoid |> ignore everywhere in aspnet config files 4 | 5 | open System 6 | open Microsoft.AspNetCore.Builder 7 | open Microsoft.Extensions.Hosting 8 | open Microsoft.Extensions.DependencyInjection 9 | open System.Threading.Tasks 10 | open Microsoft.AspNetCore.Http 11 | 12 | module Clients = 13 | open System.Net.Http 14 | open System.Net.Http.Json 15 | 16 | module Routes = 17 | let name = "/hello/name" 18 | let age = "/hello/age" 19 | 20 | let ``localhost:5000`` (httpClient: HttpClient) = 21 | httpClient.BaseAddress <- "http://localhost" |> Uri 22 | 23 | type ClientOne(httpClient: HttpClient) = 24 | member this.GetNameAsync() = 25 | httpClient.GetFromJsonAsync<{| Name: string |}>(Routes.name) 26 | 27 | type ClientTwo(httpClient: HttpClient) = 28 | member this.GetAgeAsync() = 29 | httpClient.GetFromJsonAsync<{| Age: int |}>(Routes.age) 30 | 31 | 32 | module Services = 33 | open Clients 34 | 35 | let routeOne = "/service-one" 36 | 37 | type ServiceOne(clientOne: ClientOne, clientTwo: ClientTwo) = 38 | member this.GetAndPrintAsync() = 39 | task { 40 | let! name = clientOne.GetNameAsync() 41 | let! age = clientTwo.GetAgeAsync() 42 | 43 | return $"name: {name}, age:{age}" 44 | } 45 | 46 | // IMPORTANT: needed for WebApplicationFactory 47 | type Program() = class end 48 | 49 | // entry point is allowed only in let function bindings, so we need to also have this 50 | module Program = 51 | 52 | [] 53 | let main args = 54 | 55 | let builder = 56 | WebApplication.CreateBuilder(args) 57 | |> fun x -> 58 | x.Services.AddHttpClient(Clients.``localhost:5000``) 59 | x.Services.AddHttpClient(Clients.``localhost:5000``) 60 | x.Services.AddTransient() 61 | x 62 | 63 | let app = builder.Build() 64 | 65 | // our app service is invoked in this route 66 | app.MapPost(Services.routeOne, Func(fun c -> 67 | task { 68 | let s = c.RequestServices.GetRequiredService() 69 | 70 | let! r = s.GetAndPrintAsync() 71 | 72 | return r 73 | }) 74 | ) 75 | 76 | // test api client against these endpoints to avoid extra server hosting in app / containers etc 77 | app.MapGet("/hello/name", Func<{| Name: string |}>(fun () -> {| Name = "john" |})) 78 | app.MapGet("/hello/age", Func<{| Age: int |}>(fun () -> {| Age = 25 |})) 79 | 80 | app.Run() 81 | 82 | 0 // Exit code 83 | 84 | -------------------------------------------------------------------------------- /test/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.1", 3 | "info": { 4 | "title": "app", 5 | "version": "1.0" 6 | }, 7 | "paths": { 8 | "/Hello": { 9 | "get": { 10 | "tags": [ 11 | "Hello" 12 | ], 13 | "responses": { 14 | "200": { 15 | "description": "Success", 16 | "content": { 17 | "text/plain": { 18 | "schema": { 19 | "$ref": "#/components/schemas/Hello" 20 | } 21 | }, 22 | "application/json": { 23 | "schema": { 24 | "$ref": "#/components/schemas/Hello" 25 | } 26 | }, 27 | "text/json": { 28 | "schema": { 29 | "$ref": "#/components/schemas/Hello" 30 | } 31 | } 32 | } 33 | } 34 | } 35 | } 36 | }, 37 | "/WeatherForecast": { 38 | "get": { 39 | "tags": [ 40 | "WeatherForecast" 41 | ], 42 | "responses": { 43 | "200": { 44 | "description": "Success", 45 | "content": { 46 | "text/plain": { 47 | "schema": { 48 | "type": "array", 49 | "items": { 50 | "$ref": "#/components/schemas/WeatherForecast" 51 | } 52 | } 53 | }, 54 | "application/json": { 55 | "schema": { 56 | "type": "array", 57 | "items": { 58 | "$ref": "#/components/schemas/WeatherForecast" 59 | } 60 | } 61 | }, 62 | "text/json": { 63 | "schema": { 64 | "type": "array", 65 | "items": { 66 | "$ref": "#/components/schemas/WeatherForecast" 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | } 74 | } 75 | }, 76 | "components": { 77 | "schemas": { 78 | "Hello": { 79 | "type": "object", 80 | "properties": { 81 | "ok": { 82 | "type": "string", 83 | "nullable": true 84 | } 85 | }, 86 | "additionalProperties": false 87 | }, 88 | "WeatherForecast": { 89 | "type": "object", 90 | "properties": { 91 | "date": { 92 | "type": "string", 93 | "format": "date-time" 94 | }, 95 | "temperatureC": { 96 | "type": "integer", 97 | "format": "int32" 98 | }, 99 | "summary": { 100 | "type": "string", 101 | "nullable": true 102 | }, 103 | "temperatureF": { 104 | "type": "number", 105 | "format": "double", 106 | "readOnly": true 107 | } 108 | }, 109 | "additionalProperties": false 110 | } 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /ApiStub.FSharp/DelegatingHandlers.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp 2 | 3 | open System.Threading.Tasks 4 | open System.Net.Http 5 | open System 6 | open Microsoft.AspNetCore.Routing.Template 7 | open Microsoft.AspNetCore.Routing 8 | open Microsoft.AspNetCore.Http 9 | open ApiStub.FSharp.HttpResponseHelpers 10 | open System.Net 11 | 12 | module DelegatingHandlers = 13 | 14 | /// necessary to wrap base calls in handlers 15 | type internal AsyncCallableHandler(messageHandler) = 16 | inherit DelegatingHandler(messageHandler) 17 | 18 | member internal x.CallSendAsync(request, cancellationToken) = 19 | base.SendAsync(request, cancellationToken) 20 | 21 | /// This is the main stub/mock handler 22 | type MockClientHandler(handler: HttpMessageHandler, methods, templateMatcher: TemplateMatcher, responseStubber) = 23 | inherit DelegatingHandler(handler) 24 | 25 | override this.SendAsync(request, token) = 26 | let wrappedBase = new AsyncCallableHandler(base.InnerHandler) 27 | 28 | task { 29 | let routeDict = new RouteValueDictionary() 30 | 31 | if methods |> Array.contains (request.Method) |> not then 32 | return! wrappedBase.CallSendAsync(request, token) 33 | else if 34 | templateMatcher.TryMatch(request.RequestUri.AbsolutePath |> PathString, routeDict) 35 | |> not 36 | then 37 | return! wrappedBase.CallSendAsync(request, token) 38 | else 39 | // HTTP response stubbing happens here, the request has matched, go on with the stub 40 | let! (expected: HttpResponseMessage) = responseStubber request routeDict 41 | // reattach original request!!! 42 | expected.RequestMessage <- request 43 | return expected 44 | } 45 | 46 | /// This handler comes into play when no matches are happening, returning a BAD REQUEST 400 to the client 47 | type MockTerminalHandler() = 48 | inherit HttpMessageHandler() 49 | 50 | override this.SendAsync(_, token) = 51 | task { 52 | token.ThrowIfCancellationRequested() 53 | 54 | return 55 | new StringContent("No Stubs Specified for This Call") 56 | |> R_ERROR HttpStatusCode.BadRequest 57 | } 58 | 59 | 60 | /// NOT IN USE, check if needed 61 | type ResponseStreamWrapperHandler(handler: HttpMessageHandler) = 62 | inherit DelegatingHandler(handler) 63 | 64 | override this.SendAsync(request, cancellationToken) = 65 | 66 | let wrappedBase = new AsyncCallableHandler(base.InnerHandler) 67 | 68 | task { 69 | let! response = wrappedBase.CallSendAsync(request, cancellationToken) 70 | 71 | let! bytes = response.Content.ReadAsByteArrayAsync(cancellationToken) 72 | 73 | let newContent = new ByteArrayContent(bytes) 74 | 75 | for sourceHeader in response.Content.Headers do 76 | let vals = sourceHeader.Value |> Seq.toArray 77 | newContent.Headers.Add(sourceHeader.Key, vals) 78 | 79 | response.Content <- newContent 80 | 81 | return response 82 | } 83 | -------------------------------------------------------------------------------- /test/BuilderExtensionsTests.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp.Tests 2 | 3 | open Xunit 4 | open fsharpintegrationtests 5 | open Microsoft.AspNetCore.Mvc.Testing 6 | open Microsoft.Extensions.DependencyInjection 7 | open Microsoft.AspNetCore.Hosting 8 | open SwaggerProvider 9 | open System.Threading.Tasks 10 | open System.Net.Http 11 | open System 12 | open Microsoft.AspNetCore.TestHost 13 | open Microsoft.Extensions.Http 14 | open Microsoft.AspNetCore.Routing.Template 15 | open Microsoft.AspNetCore.Routing.Patterns 16 | open Microsoft.AspNetCore.Routing 17 | open System.Net 18 | open System.Text.Json 19 | open Microsoft.AspNetCore.Http 20 | open System.Net.Http.Json 21 | open Swensen.Unquote 22 | open ApiStub.FSharp.CE 23 | open ApiStub.FSharp.BuilderExtensions 24 | open ApiStub.FSharp.HttpResponseHelpers 25 | open ApiStub.FSharp 26 | open ApiStub.FSharp.BDD 27 | open HttpResponseMessageExtensions 28 | open Xunit.Abstractions 29 | 30 | type ISomeSingleton = interface end 31 | 32 | type SomeSingleton(name: string) = 33 | class 34 | interface ISomeSingleton 35 | end 36 | 37 | type BuilderExtensionsTests(testOutput: ITestOutputHelper) = 38 | 39 | let testce = new CE.TestWebAppFactoryBuilder() 40 | 41 | interface IDisposable with 42 | member this.Dispose() = (testce :> IDisposable).Dispose() 43 | 44 | [] 45 | member this.``WITH_SERVICES registers correctly``() = 46 | task { 47 | 48 | let testApp = 49 | testce { 50 | GETJ "hello" {| ResponseCode = 1001 |} 51 | 52 | WITH_SERVICES(fun (s: IServiceCollection) -> 53 | s.AddSingleton(new SomeSingleton("John"))) 54 | } 55 | 56 | let fac = testApp.GetFactory() 57 | 58 | let singleton = fac.Services.GetRequiredService() 59 | 60 | Assert.NotNull(singleton) 61 | 62 | let client = fac.Services.GetRequiredService() 63 | 64 | let! resp = client.GetFromJsonAsync<{| ResponseCode: int |}>("hello") 65 | 66 | Assert.Equal(1001, resp.ResponseCode) 67 | } 68 | 69 | 70 | [] 71 | member this.``WITH_TEST_SERVICES registers correctly``() = 72 | task { 73 | 74 | let singletonMock = { new ISomeSingleton } 75 | 76 | let testApp = 77 | testce { 78 | GETJ "hello" {| ResponseCode = 1001 |} 79 | 80 | WITH_SERVICES(fun (s: IServiceCollection) -> 81 | s.AddSingleton(new SomeSingleton("John"))) 82 | 83 | WITH_TEST_SERVICES(fun s -> s.AddSingleton(singletonMock)) 84 | } 85 | 86 | let fac = testApp.GetFactory() 87 | 88 | let singleton = fac.Services.GetRequiredService() 89 | 90 | Assert.NotNull(singleton) 91 | Assert.Same(singletonMock, singleton) 92 | 93 | let client = fac.Services.GetRequiredService() 94 | 95 | let! resp = client.GetFromJsonAsync<{| ResponseCode: int |}>("hello") 96 | 97 | Assert.Equal(1001, resp.ResponseCode) 98 | } 99 | 100 | [] 101 | member this.``HTTP MOCKS can use task async functions OK``() = 102 | task { 103 | 104 | let testApp = 105 | testce { GET_ASYNC "hello" (fun r args -> task { return {| ResponseCode = 1001 |} |> R_JSON }) } 106 | 107 | use fac = testApp.GetFactory() 108 | 109 | let client = fac.Services.GetRequiredService() 110 | 111 | let! resp = client.GetFromJsonAsync<{| ResponseCode: int |}>("hello") 112 | 113 | Assert.Equal(1001, resp.ResponseCode) 114 | } 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ApiStub.FSharp [![NuGet Badge](https://img.shields.io/nuget/v/ApiStub.FSharp)](https://www.nuget.org/packages/ApiStub.FSharp) 🦔 2 | 3 | ![alt text](docs/img/ApiStub.FSharp.png) 4 | 5 | JUST_STOP_OIL 6 | [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua) 7 | [![Ceasefire Now](https://badge.techforpalestine.org/ceasefire-now)](https://techforpalestine.org/learn-more) 8 | 9 | ## Easy API Testing 🧞‍♀️ 10 | 11 | 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. 12 | 13 | An "antique" C# API (👴🏽🦖🦕) is also available since v.1.1 for enhanced accessibility 😺. 14 | 15 | ## Documentation 16 | 17 | Access the [documentation website](https://jkone27.github.io/fsharp-integration-tests/) for more info on how to use this library. 18 | 19 | ## Scenario 20 | 21 | ```mermaid 22 | sequenceDiagram 23 | participant TestWebAppFactoryBuilder as Test 24 | participant MainApp as App 25 | participant DependencyApp as Dep 26 | 27 | TestWebAppFactoryBuilder->>MainApp: GET /Hello 28 | MainApp->>DependencyApp: GET /externalApi 29 | DependencyApp-->>MainApp: Response 30 | MainApp-->>TestWebAppFactoryBuilder: Response 31 | 32 | ``` 33 | 34 | ## Test 🧪 35 | 36 | using `F#` 37 | 38 | ```fsharp 39 | open ApiStub.FSharp.CE 40 | open ApiStub.FSharp.BuilderExtensions 41 | open ApiStub.FSharp.HttpResponseHelpers 42 | open Xunit 43 | 44 | module Tests = 45 | 46 | // build your aspnetcore integration testing CE 47 | let test = new TestWebAppFactoryBuilder() 48 | 49 | [] 50 | let ``Calls Hello and returns OK`` () = task { 51 | 52 | let client = 53 | test { 54 | GETJ "/externalApi" {| Ok = "yeah" |} 55 | } 56 | |> _.GetFactory() 57 | |> _.CreateClient() 58 | 59 | let! r = client.GetAsync("/Hello") 60 | 61 | // rest of your tests... 62 | 63 | } 64 | ``` 65 | 66 | or in `C#` if you prefer 67 | 68 | ```csharp 69 | using ApiStub.FSharp; 70 | using Xunit; 71 | using static ApiStub.Fsharp.CsharpExtensions; 72 | 73 | public class Tests 74 | { 75 | [Fact] 76 | async Task CallsHelloAndReturnsOk() 77 | { 78 | 79 | var client = 80 | new CE.TestWebAppFactoryBuilder() 81 | .GETJ("/externalApi", new { Ok = "Yeah" }) 82 | .GetFactory() 83 | .CreateClient(); 84 | 85 | var r = await client.GetAsync("/Hello"); 86 | 87 | // rest of your tests... 88 | } 89 | } 90 | ``` 91 | 92 | ### Test .NET C# 🤝 from F# 93 | 94 | F# is a great language, but it doesn't have to be scary to try it. Integration and Unit tests are a great way to introduce F# to your team if you are already using .NET or ASPNETCORE. 95 | 96 | In fact you can add an `.fsproj` within a C# aspnetcore solution `.sln`, and just have a single F# assembly test your C# application from F#, referencing a `.csproj` file is easy! just use regular [dotnet add reference command](https://learn.microsoft.com/bs-latn-ba/dotnet/core/tools/dotnet-add-reference). 97 | 98 | ## How to Contribute ✍️ 99 | 100 | * Search for an open issue or report one, and check if a similar issue was reported first 101 | * feel free to get in touch, to fork and check out the repo 102 | * test and find use cases for this library, testing in F# is awesome!!!! 103 | 104 | ## Commit linting 📝 105 | 106 | This project uses [Commitlint](https://commitlint.js.org/) npm package and [ConventionalCommits](https://www.conventionalcommits.org/en/v1.0.0/#summary) specification for commits, so be aware to follow them when committing, via [Husky.NET](https://alirezanet.github.io/Husky.Net/guide/getting-started.html#add-your-first-hook) 107 | 108 | ## Versioning 📚 109 | 110 | This repository uses [Versionize](https://github.com/versionize/versionize/blob/master/.github/workflows/publish.yml) as a local dotnet tool to version packages when publishing. **Versionize** relies on [conventional commits](#commit-linting) to work properly. 111 | 112 | ### References 113 | 114 | * more info on [F# xunit testing](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-dotnet-test). 115 | * more general info on aspnetcore integration testing if you use [Nunit](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-nunit) instead. 116 | * [aspnetcore integration testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0) docs in C# 117 | 118 | -------------------------------------------------------------------------------- /ApiStub.FSharp/BDD.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp 2 | 3 | open System 4 | open System.Net.Http 5 | open System.Threading.Tasks 6 | open ApiStub.FSharp.CE 7 | open Microsoft.AspNetCore.Mvc.Testing 8 | open ApiStub.FSharp.HttpResponseHelpers 9 | 10 | module BDD = 11 | 12 | 13 | /// Defines a BDD scenario 14 | type Scenario<'TStartup when 'TStartup: not struct> = 15 | { UseCase: string 16 | TestWAFBuilder: TestWebAppFactoryBuilder<'TStartup> } 17 | 18 | /// Defines the context propagated through the test 19 | type Environment<'TStartup, 'FeatureStubData when 'TStartup: not struct> = 20 | { Scenario: Scenario<'TStartup> 21 | FeatureStubData: 'FeatureStubData 22 | Factory: 'TStartup WebApplicationFactory 23 | Client: HttpClient } 24 | 25 | /// Result of a Given gherkin clause 26 | type GivenResult<'ArrangeData, 'FeatureStubData, 'TStartup when 'TStartup: not struct> = 27 | { Environment: Environment<'TStartup, 'FeatureStubData> 28 | ArrangeData: 'ArrangeData } // once preconditions are set 29 | 30 | /// Result of a When gherkin clause 31 | type WhenResult<'ArrangeData, 'FeatureStubData, 'AssertData, 'TStartup when 'TStartup: not struct> = 32 | { Given: GivenResult<'ArrangeData, 'FeatureStubData, 'TStartup> 33 | AssertData: 'AssertData } 34 | 35 | /// Generic step type for the BDD steps 36 | type Step<'TStartup, 'FeatureStubData, 'ArrangeData, 'AssertData when 'TStartup: not struct> = 37 | | Scenario of Scenario<'TStartup> 38 | | Environment of Environment<'TStartup, 'FeatureStubData> 39 | | Given of GivenResult<'ArrangeData, 'FeatureStubData, 'TStartup> 40 | | When of WhenResult<'ArrangeData, 'FeatureStubData, 'AssertData, 'TStartup> 41 | | Invalid of error: string 42 | 43 | 44 | /// Scenario builder 45 | let SCENARIO useCase (builder: TestWebAppFactoryBuilder<_>) = 46 | { UseCase = useCase 47 | TestWAFBuilder = builder } 48 | |> Step.Scenario 49 | 50 | /// Setup the Environment for the given scenario 51 | let SETUP arrangeTestEnvironment customizeClient step = 52 | task { 53 | 54 | match step with 55 | | Step.Scenario(scenario) -> 56 | 57 | let! environment = arrangeTestEnvironment scenario 58 | 59 | let newEnv = 60 | { environment with 61 | Client = environment.Client |> customizeClient } 62 | 63 | return Step.Environment(newEnv) 64 | | _ -> return Step.Invalid("only environment is supported for ENVIRONMENT_SETUP") 65 | } 66 | 67 | /// specify a GIVEN gherkin clause 68 | let GIVEN setPreconditions stepTask = 69 | task { 70 | 71 | let! step = stepTask 72 | 73 | let environmentResult = 74 | match step with 75 | | Step.Environment(e) -> Result.Ok(e) 76 | | Step.Given(g) -> Result.Ok(g.Environment) 77 | | _ -> Result.Error($"{step} is not supported in GIVEN clause") 78 | 79 | let! (preResult: Result<_ * 'ArrangeData, string>) = 80 | task { 81 | match environmentResult with 82 | | Ok(e) -> 83 | let! pre = setPreconditions e 84 | return Ok(e, pre) 85 | | Error(e) -> return Error(e) 86 | } 87 | 88 | return 89 | match preResult with 90 | | Result.Ok(e, pre) -> 91 | let given = { ArrangeData = pre; Environment = e } 92 | 93 | Step.Given(given) 94 | 95 | | Result.Error(e) -> Step.Invalid(e) 96 | } 97 | 98 | /// specify a WHEN gherkin clause 99 | let WHEN action stepTask = 100 | task { 101 | 102 | let! step = stepTask 103 | 104 | let givenResult = 105 | match step with 106 | | Step.Given(g) -> Result.Ok(g) 107 | | Step.When(w) -> Result.Ok(w.Given) 108 | | _ -> Result.Error($"{step} is not supported in WHEN clause") 109 | 110 | let! r = 111 | task { 112 | match givenResult with 113 | | Ok(g) -> 114 | 115 | let! assertData = action g 116 | 117 | let w = { Given = g; AssertData = assertData } 118 | return Step.When(w) 119 | | Error(e) -> return Step.Invalid(e) 120 | } 121 | 122 | return r 123 | } 124 | 125 | /// Specify an assert in THEN gherkin format 126 | let THEN assertAction stepTask = 127 | task { 128 | 129 | let! step = stepTask 130 | 131 | match step with 132 | | Step.When(w) -> 133 | do assertAction w 134 | return Step.When(w) 135 | | _ -> return Step.Invalid($"{step} is not supported in WHEN clause") 136 | } 137 | 138 | /// Conclude the pipeline of steps 139 | let END stepTask = 140 | task { 141 | 142 | let! step = stepTask 143 | 144 | match step with 145 | | Step.When(w) -> 146 | // dispose and return 147 | use d = w.Given.Environment.Client 148 | use dd = w.Given.Environment.Factory 149 | () 150 | | _ -> () 151 | } 152 | 153 | 154 | // [] sample 155 | // let ``when i call /hello i get 'world' back with 200 ok`` (TestWebAppFactoryBuilder: TestWebAppFactoryBuilder<_>) = 156 | 157 | // let stubData = [ 1, 2, 3 ] 158 | 159 | // TestWebAppFactoryBuilder { 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.TestWebAppFactoryBuilder 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 186 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | # FSharp.Formatting 353 | .fsdocs/ 354 | output/ 355 | tmp/ 356 | 357 | .DS_Store -------------------------------------------------------------------------------- /test/CETests.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp.Tests 2 | 3 | open Xunit 4 | open fsharpintegrationtests 5 | open Microsoft.AspNetCore.Mvc.Testing 6 | open Microsoft.Extensions.DependencyInjection 7 | open Microsoft.AspNetCore.Hosting 8 | open SwaggerProvider 9 | open System.Threading.Tasks 10 | open System.Net.Http 11 | open System 12 | open Microsoft.AspNetCore.TestHost 13 | open Microsoft.Extensions.Http 14 | open Microsoft.AspNetCore.Routing.Template 15 | open Microsoft.AspNetCore.Routing.Patterns 16 | open Microsoft.AspNetCore.Routing 17 | open System.Net 18 | open System.Text.Json 19 | open Microsoft.AspNetCore.Http 20 | open System.Net.Http.Json 21 | open Swensen.Unquote 22 | open ApiStub.FSharp.CE 23 | open ApiStub.FSharp.BuilderExtensions 24 | open ApiStub.FSharp.HttpResponseHelpers 25 | open ApiStub.FSharp 26 | 27 | type MyOpenapi = OpenApiClientProvider<"swagger.json"> 28 | 29 | type CETests() = 30 | 31 | let testce = new CE.TestWebAppFactoryBuilder() 32 | 33 | interface IDisposable with 34 | member this.Dispose() = (testce :> IDisposable).Dispose() 35 | 36 | [] 37 | member this.``GET weather returns a not null Date``() = 38 | 39 | let application = new WebApplicationFactory() 40 | 41 | let client = application.CreateClient() 42 | 43 | let typedClient = MyOpenapi.Client(client) 44 | 45 | task { 46 | 47 | let! forecast = typedClient.GetWeatherForecast() 48 | 49 | Assert.NotNull(forecast.[0].Date) 50 | } 51 | 52 | 53 | [] 54 | member this.``test CE works stubbed client had valid http response and inner request with content``() = 55 | 56 | task { 57 | 58 | let testApp = testce { POSTJ "/stub-this-post" {| Ok = "yeah" |} } 59 | 60 | use internalClient: HttpClient = 61 | testApp.GetFactory().Services.GetRequiredService() 62 | 63 | // call an endpoint not invoked/used with a body, to check request content 64 | let! response = internalClient.PostAsJsonAsync("/stub-this-post", {| Test = "hey" |}) 65 | 66 | // can be used by client "middleware" in http client factory (delegating handlers / http message handlers) 67 | Assert.NotNull(response.RequestMessage) 68 | 69 | let! testMessage = response.RequestMessage.Content.ReadFromJsonAsync<{| Test: string |}>() 70 | 71 | Assert.Equal("hey", testMessage.Test) 72 | 73 | // read response and check it matched the stub body 74 | 75 | let! responseObj = response.Content.ReadFromJsonAsync<{| Ok: string |}>() 76 | 77 | Assert.Equal("yeah", responseObj.Ok) 78 | } 79 | 80 | 81 | [] 82 | member this.``test CE works stubbing multiple endpoints``() = 83 | 84 | task { 85 | 86 | let expected = {| Ok = "yeah" |} 87 | 88 | let testApp = 89 | testce { 90 | GETJ "/externalApi" expected 91 | POSTJ "/another/anotherApi" {| Test = "hello"; Time = 1 |} 92 | POST "/notUsed" (fun _ _ -> "ok" |> R_TEXT) 93 | POST "/notUsed2" (fun _ _ -> "ok" |> R_TEXT) 94 | POST "/errRoute" (fun _ _ -> R_ERROR HttpStatusCode.NotAcceptable (new StringContent("err"))) 95 | } 96 | 97 | let factory = testApp.GetFactory() 98 | 99 | use internalClient: HttpClient = factory.Services.GetRequiredService() 100 | 101 | let! internalResponse = internalClient.GetAsync("externalApi") 102 | 103 | // can be used by client middleware 104 | Assert.NotNull(internalResponse.RequestMessage) 105 | 106 | use client = factory.CreateClient() 107 | 108 | let! r = client.GetAsync("/Hello") 109 | 110 | r.EnsureSuccessStatusCode() |> ignore 111 | 112 | let! rr = r.Content.ReadFromJsonAsync() 113 | 114 | Assert.Equal(expected.Ok, rr.Ok) 115 | } 116 | 117 | [] 118 | member this.``test with extension works two clients``() = 119 | 120 | task { 121 | 122 | let expected = {| Ok = "yeah" |} 123 | 124 | let testApp = 125 | testce { 126 | GETJ "/externalApi" expected 127 | POST "/another/anotherApi" (fun _ _ -> {| Test = "hello"; Time = 1 |} |> R_JSON) 128 | POST "/notUsed" (fun _ _ -> "ok" |> R_TEXT) 129 | POST "/notUsed2" (fun _ _ -> "ok" |> R_TEXT) 130 | POST "/errRoute" (fun _ _ -> R_ERROR HttpStatusCode.NotAcceptable (new StringContent("err"))) 131 | } 132 | 133 | let factory = testApp.GetFactory() 134 | 135 | let client = factory.CreateClient() 136 | 137 | let! r = client.GetAsync("/Hello") 138 | 139 | r.EnsureSuccessStatusCode() |> ignore 140 | 141 | let! rr = r.Content.ReadFromJsonAsync() 142 | 143 | Assert.Equal(expected.Ok, rr.Ok) 144 | 145 | let! r2 = client.GetAsync("/Hello") 146 | 147 | r2.EnsureSuccessStatusCode() |> ignore 148 | 149 | } 150 | 151 | [] 152 | member this.``test with swagger gen client for json apis``() = 153 | 154 | task { 155 | let expected = {| Ok = "yeah" |} 156 | 157 | use testApp = 158 | testce { 159 | GETJ "/notUsed" expected 160 | GETJ "/externalApi" expected 161 | POSTJ "/another/anotherApi" expected 162 | } 163 | 164 | let client = testApp.GetFactory().CreateClient() 165 | let typedClient = new MyOpenapi.Client(client) 166 | 167 | let! r = typedClient.GetHello() 168 | 169 | Assert.Equal(expected.Ok, r.Ok) 170 | } 171 | 172 | [] 173 | member this.``check custom client override still allowed before``() = 174 | 175 | task { 176 | let expected = {| Ok = "yeah" |} 177 | 178 | use testApp = 179 | testce { 180 | GETJ "externalApi" expected 181 | POSTJ "another/anotherApi" expected 182 | } 183 | 184 | let factory = testApp.GetFactory() 185 | 186 | let clientFactory = factory.Services.GetRequiredService() 187 | let customClient = clientFactory.CreateClient("anotherApiClient") 188 | 189 | Assert.True(customClient.BaseAddress.ToString().EndsWith("another/")) 190 | 191 | let client = factory.CreateClient() 192 | let typedClient = new MyOpenapi.Client(client) 193 | 194 | let! r = typedClient.GetHello() 195 | 196 | test <@ expected.Ok = r.Ok @> 197 | } 198 | 199 | [] 200 | member this.``check custom client override still allowed after``() = 201 | 202 | task { 203 | 204 | let expected = {| Ok = "yeah" |} 205 | 206 | use testApp = 207 | testce { 208 | GETJ "externalApi" expected 209 | POSTJ "test/anotherApi" expected 210 | } 211 | 212 | let factory = 213 | testApp.GetFactory() 214 | |> web_configure_test_services (fun t -> 215 | t.AddHttpClient( 216 | "anotherApiClient", 217 | configureClient = (fun c -> c.BaseAddress <- new Uri("http://localhost/test/")) 218 | )) 219 | 220 | let clientFactory = factory.Services.GetRequiredService() 221 | let customClient = clientFactory.CreateClient("anotherApiClient") 222 | 223 | Assert.Equal("http://localhost/test/", customClient.BaseAddress.ToString()) 224 | 225 | let client = factory.CreateClient() 226 | let typedClient = new MyOpenapi.Client(client) 227 | 228 | let! r = typedClient.GetHello() 229 | 230 | test <@ expected.Ok = r.Ok @> 231 | } 232 | -------------------------------------------------------------------------------- /ApiStub.FSharp/CE.fs: -------------------------------------------------------------------------------- 1 | namespace ApiStub.FSharp 2 | 3 | open Microsoft.AspNetCore.Mvc.Testing 4 | open Microsoft.Extensions.DependencyInjection 5 | open System.Threading.Tasks 6 | open System.Net.Http 7 | open System 8 | open Microsoft.Extensions.Http 9 | open Microsoft.AspNetCore.Routing.Template 10 | open Microsoft.AspNetCore.Routing 11 | 12 | /// computation expression module (builder CE), contains `TestWebAppFactoryBuilder` (former `TestWebAppFactoryBuilder`) that wraps `WebApplicationFactory` 13 | module CE = 14 | open BuilderExtensions 15 | open HttpResponseHelpers 16 | open DelegatingHandlers 17 | 18 | let private toAsync stub = 19 | fun req args -> task { return stub req args } 20 | 21 | /// `TestWebAppFactoryBuilder` wraps `WebApplicationFactory` and exposes a builder CE with utility to define api client stubs and other features 22 | type TestWebAppFactoryBuilder<'T when 'T: not struct>() = 23 | 24 | let factory = new WebApplicationFactory<'T>() 25 | let mutable httpMessageHandler: DelegatingHandler = null 26 | 27 | let customConfigureServices = 28 | ResizeArray IServiceCollection>() 29 | 30 | let customConfigureTestServices = 31 | ResizeArray IServiceCollection>() 32 | 33 | interface IDisposable with 34 | member this.Dispose() = factory.Dispose() 35 | 36 | interface IAsyncDisposable with 37 | member this.DisposeAsync() = factory.DisposeAsync() 38 | 39 | member this.Yield(()) = 40 | (factory, httpMessageHandler, customConfigureServices) 41 | 42 | 43 | /// generic stub operation with stub function 44 | [] 45 | member this.StubWithOptions 46 | ( 47 | _, 48 | methods, 49 | routeTemplate: string, 50 | stubAsync: HttpRequestMessage -> RouteValueDictionary -> HttpResponseMessage Task, 51 | useRealHttpClient 52 | ) = 53 | 54 | let routeValueDict = RouteValueDictionary() 55 | 56 | let templateMatcher = 57 | try 58 | let rt = TemplateParser.Parse(routeTemplate.TrimStart('/')) 59 | let tm = TemplateMatcher(rt, routeValueDict) 60 | Some(tm) 61 | with _ -> 62 | None 63 | 64 | if templateMatcher.IsNone then 65 | failwith $"stub: error parsing route template for {routeTemplate}" 66 | 67 | if httpMessageHandler = null then 68 | // add nested handler 69 | let baseClient: HttpMessageHandler = 70 | if useRealHttpClient then 71 | new HttpClientHandler() 72 | else 73 | new ResponseStreamWrapperHandler(new MockTerminalHandler()) 74 | 75 | httpMessageHandler <- new MockClientHandler(baseClient, methods, templateMatcher.Value, stubAsync) 76 | else 77 | httpMessageHandler <- 78 | new MockClientHandler(httpMessageHandler, methods, templateMatcher.Value, stubAsync) 79 | 80 | this 81 | 82 | 83 | [] 84 | member this.Stub 85 | (x, methods, routeTemplate, stub: HttpRequestMessage -> RouteValueDictionary -> HttpResponseMessage) 86 | = 87 | this.StubWithOptions(x, methods, routeTemplate, stub |> toAsync, false) 88 | 89 | [] 90 | member this.StubAsync 91 | (x, methods, routeTemplate, stub: HttpRequestMessage -> RouteValueDictionary -> HttpResponseMessage Task) 92 | = 93 | this.StubWithOptions(x, methods, routeTemplate, stub, false) 94 | 95 | /// stub operation with stub object (HttpResponseMessage) 96 | [] 97 | member this.StubObj(x, methods, routeTemplate, stub: unit -> HttpResponseMessage) = 98 | this.Stub(x, methods, routeTemplate, (fun _ _ -> stub ())) 99 | 100 | /// string stub 101 | [] 102 | member this.StubString(x, methods, routeTemplate, stub: string) = 103 | this.StubObj(x, methods, routeTemplate, (fun _ -> stub |> R_TEXT)) 104 | 105 | /// json stub 106 | [] 107 | member this.StubJson(x, methods, routeTemplate, stub: obj) = 108 | this.StubObj(x, methods, routeTemplate, (fun _ -> stub |> R_JSON)) 109 | 110 | /// stub GET request with stub function 111 | [] 112 | member this.GetAsync(x, route, stub) = 113 | this.StubAsync(x, [| HttpMethod.Get |], route, stub) 114 | 115 | /// stub GET request with stub function 116 | [] 117 | member this.Get(x, route, stub) = 118 | this.Stub(x, [| HttpMethod.Get |], route, stub) 119 | 120 | /// stub GET request with stub object 121 | [] 122 | member this.Get2(x, route, stub) = 123 | this.StubObj(x, [| HttpMethod.Get |], route, stub) 124 | 125 | /// stub GET json 126 | [] 127 | member this.GetJson(x, route, stub: obj) = 128 | this.StubJson(x, [| HttpMethod.Get |], route, stub) 129 | 130 | /// stub POST 131 | [] 132 | member this.PostAsync(x, route, stub) = 133 | this.StubAsync(x, [| HttpMethod.Post |], route, stub) 134 | 135 | /// stub POST 136 | [] 137 | member this.Post(x, route, stub) = 138 | this.Stub(x, [| HttpMethod.Post |], route, stub) 139 | 140 | /// stub POST json 141 | [] 142 | member this.PostJson(x, route, stub: obj) = 143 | this.StubJson(x, [| HttpMethod.Post |], route, stub) 144 | 145 | /// stub PUT 146 | [] 147 | member this.PutAsync(x, route, stub) = 148 | this.StubAsync(x, [| HttpMethod.Put |], route, stub) 149 | 150 | /// stub PUT 151 | [] 152 | member this.Put(x, route, stub) = 153 | this.Stub(x, [| HttpMethod.Put |], route, stub) 154 | 155 | /// stub PUT json 156 | [] 157 | member this.PutJson(x, route, stub: obj) = 158 | this.StubJson(x, [| HttpMethod.Put |], route, stub) 159 | 160 | /// stub PATCH json 161 | [] 162 | member this.PatchAsync(x, route, stub) = 163 | this.StubAsync(x, [| HttpMethod.Patch |], route, stub) 164 | 165 | /// stub PATCH 166 | [] 167 | member this.Patch(x, route, stub) = 168 | this.Stub(x, [| HttpMethod.Patch |], route, stub) 169 | 170 | /// stub PATCH json 171 | [] 172 | member this.PatchJson(x, route, stub: obj) = 173 | this.StubJson(x, [| HttpMethod.Patch |], route, stub) 174 | 175 | /// stub DELETE 176 | [] 177 | member this.Delete(x, route, stub) = 178 | this.Stub(x, [| HttpMethod.Delete |], route, stub) 179 | 180 | /// stub DELETE 181 | [] 182 | member this.DeleteAsync(x, route, stub) = 183 | this.StubAsync(x, [| HttpMethod.Delete |], route, stub) 184 | 185 | /// stub DELETE json 186 | [] 187 | member this.DeleteJson(x, route, stub: obj) = 188 | this.StubJson(x, [| HttpMethod.Delete |], route, stub) 189 | 190 | [] 191 | member this.CustomConfigServices(x, customAction) = 192 | customConfigureServices.Add(customAction) 193 | this 194 | 195 | [] 196 | member this.CustomConfigTestServices(x, customAction) = 197 | customConfigureTestServices.Add(customAction) 198 | this 199 | 200 | member this.GetFactory() = 201 | factory 202 | |> web_configure_services (fun s -> 203 | s.ConfigureAll(fun options -> 204 | options.HttpMessageHandlerBuilderActions.Add(fun builder -> 205 | //builder.AdditionalHandlers.Add(httpMessageHandler) |> ignore 206 | builder.PrimaryHandler <- httpMessageHandler) 207 | 208 | options.HttpClientActions.Add(fun c -> 209 | let path = 210 | if c.BaseAddress <> null then 211 | c.BaseAddress.AbsolutePath 212 | else 213 | String.Empty 214 | 215 | let newBase = Uri(Uri("http://127.0.0.1/"), path) 216 | c.BaseAddress <- newBase) 217 | |> ignore) 218 | |> ignore 219 | 220 | for custom_config in customConfigureServices do 221 | custom_config (s) |> ignore 222 | 223 | ) 224 | |> web_configure_test_services (fun s -> 225 | for custom_config in customConfigureTestServices do 226 | custom_config (s) |> ignore) 227 | 228 | /// `TestClient` is a type backfill for `TestWebAppFactoryBuilder`, please switch to the new name if possible 229 | [] 230 | type TestClient<'T when 'T: not struct> = TestWebAppFactoryBuilder<'T> 231 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ![alt text](img/ApiStub.FSharp.png) 4 | 5 | ## Easy API Testing 🧞‍♀️ 6 | 7 | This library makes use of [F# computation expressions](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions) or CEs to wrap some complexities of `WebApplicationFactory` when setting up `integration tests` for a `.NET` Web app. It comes with a *domain specific language* (DSL) for "mocking" HttpClient factory in integration tests, and more. 8 | 9 | ### Test .NET C# 🤝 from F# 10 | 11 | F# is a great language, but it doesn't have to be scary to try it. Integration and Unit tests are a great way to introduce F# to your team if you are already using .NET or ASPNETCORE. 12 | 13 | In fact you can add an `.fsproj` within a C# aspnetcore solution `.sln`, and just have a single F# assembly test your C# application from F#, referencing a `.csproj` file is easy! just use regular [dotnet add reference command](https://learn.microsoft.com/bs-latn-ba/dotnet/core/tools/dotnet-add-reference). 14 | 15 | ## Usage 16 | 17 | To use the CE, you must build your CE object first by passing the generic `Program` (minimal api) or `Startup` (mvc) type argument to `TestWebAppFactoryBuilder`. 18 | 19 | ### Sample Use Case 20 | 21 | Suppose in your main app (`Program` or `Startup`) you call `Services.AddHttpClient`(or its variants) twice, registering 2 API clients to make calls to other services, say to the outbound routes `/externalApi` and `/anotherApi` (let's skip the base address for now). 22 | suppose `ExternalApiClient` invokes an http `GET` method and the other client makes a `POST` http call, inside your API client code. 23 | 24 |
25 |
26 | sequenceDiagram 27 | Test->>App: GET /Hello 28 | App->>Dep1: GET /externalApi 29 | Dep1-->>App: Response 30 | App->>Dep2: POST /anotherApi 31 | Dep2-->>App: Response 32 | App-->>Test: Response 33 |
34 |
35 | 36 | ### HTTP Mocks 🤡 37 | 38 | It's easy to **mock** those http clients dependencies (with data stubs) during integration tests making use of `ApiStub.FSharp` lib, saving quite some code compared to manually implementing the `WebApplicationFactory` pattern, let's see how below. 39 | 40 | ## F# 🦔 ✨ 41 | 42 | * `Program`: to be able to make use of `Program.fs` (e.g. minimal api) as `TestWebAppFactoryBuilder()`, make sure to declare an empty `type Program = end class` on top of your Program module containing the `[] main args` method. For older porjects `Startup` can be passed as` TEntryPoint` instead. 43 | 44 | 45 | ```fsharp 46 | open ApiStub.FSharp.CE 47 | open ApiStub.FSharp.BuilderExtensions 48 | open ApiStub.FSharp.HttpResponseHelpers 49 | open Xunit 50 | 51 | module Tests = 52 | 53 | // build your aspnetcore integration testing CE 54 | let test = new TestWebAppFactoryBuilder() 55 | 56 | [] 57 | let ``Calls Hello and returns OK`` () = task { 58 | 59 | let testApp = 60 | test { 61 | GETJ "/externalApi" {| Ok = "yeah" |} 62 | POSTJ "/anotherApi" {| Whatever = "yeah" |} 63 | } 64 | 65 | use client = testApp.GetFactory().CreateClient() 66 | 67 | let! r = client.GetAsync("/Hello") 68 | 69 | r.EnsureSuccessStatusCode() 70 | } 71 | ``` 72 | 73 | ## C# 🤖 for 👴🏽🦖🦕 74 | 75 | if you prefer to use C# for testing, some extension methods are provided to use with C# as well: 76 | 77 | `GETJ, PUTJ, POSTJ, DELETEJ, PATCHJ` 78 | 79 | Remember to add this snippet at the end of your `Program.cs` file for the `TestWebAppFactoryBuilder` to be able to pick up your configuration: 80 | 81 | ```csharp 82 | // Program.cs 83 | 84 | // ... all your code, until end of file. 85 | 86 | public partial class Program { } 87 | ``` 88 | 89 | If you want to access more overloads, you can access the inspect `TestWebAppFactoryBuilder` members and create your custom extension methods easilly. 90 | 91 | ```csharp 92 | using ApiStub.FSharp; 93 | using static ApiStub.Fsharp.CsharpExtensions; 94 | using Xunit; 95 | 96 | public class Tests 97 | { 98 | 99 | [Fact] 100 | public async Task CallsHelloAndReturnsOk() 101 | { 102 | var webAppFactory = new CE.TestWebAppFactoryBuilder() 103 | .GETJ(Clients.Routes.name, new { Name = "Peter" }) 104 | .GETJ(Clients.Routes.age, new { Age = 100 }) 105 | .GetFactory(); 106 | 107 | // factory.CreateClient(); // as needed later in your tests 108 | } 109 | } 110 | ``` 111 | 112 | ## Mechanics 👨🏽‍🔧⚙️ 113 | 114 | 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. 115 | 116 | 🪆📦 > The main "idea" behind this library is having a CE builder that wraps the creation of a [**russian doll**](https://github.com/jkone27/fsharp-integration-tests/blob/7082d89870bcf353a879c6fcacc74174cea81add/ApiStub.FSharp/CE.fs#L69) or **chinese boxes** of [MockHttpHandler](https://github.com/jkone27/fsharp-integration-tests/blob/7082d89870bcf353a879c6fcacc74174cea81add/ApiStub.FSharp/DelegatingHandlers.fs#L22) to handle mocking requests to http client instances in your application under test or SUT. 117 | 118 | The TestsClient CE acts as a reusable and shareable/composable builder CE for WebApplicationFactory... 119 | 120 | ```fsharp 121 | 122 | (new TestWebAppFactoryBuilder()) // TestWebAppFactoryBuilder is here a WebApplicationFactory (WAF) builder in essence basically 123 | { 124 | // --> add stub to builder for WAF 125 | GETJ "A" {| Response = "OK" |} 126 | // --> add stub to builder for WAF 127 | GETJ "B" {| Response = "OK" |} 128 | // --> add stub to builder for WAF 129 | GETJ "C" {| Response = "OK" |} 130 | 131 | // each call adds to WAF builder 132 | } 133 | |> _.GetFactory() // until this point the builder can be decorated further / shared / reused in specific test flows 134 | ``` 135 | 136 | 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. 137 | 138 | If you have ideas for improvements feel free to open an issue/discussion! 139 | I do this on my own time, so support is limited but contributions/PRs are welcome 🙏 140 | 141 | ## Features 👨🏻‍🔬 142 | 143 | * **HTTP client mock DSL**: 144 | * supports main HTTP verbs 145 | * support for JSON payload for automatic object serialization 146 | * **BDD spec dsl extension** (behaviour driven development) 147 | * to express tests in gherkin GIVEN, WHEN, THEN format if you want to 148 | * EXTRAS 149 | * utilities for test setup and more... 150 | 151 | ## HTTP Methods 🚕 152 | 153 | Available HTTP methods in the test dsl to "mock" HTTP client responses are the following: 154 | 155 | ### Basic 156 | 157 | * `GET`, `PUT`, `POST`, `DELETE`, `PATCH` - for accessing request, route parameters and sending back HttpResponseMessage (e.g. using R_JSON or other constructors) 158 | 159 | ```fsharp 160 | // example of control on request and route value dictionary 161 | PUT "/externalApi" (fun r rvd -> 162 | // read request properties or route, but not content... 163 | // unless you are willing to wait the task explicitly as result 164 | {| Success = true |} |> R_JSON 165 | ) 166 | ``` 167 | 168 | ### JSON 📒 169 | 170 | * `GETJ`, `PUTJ`, `POSTJ`, `DELETEJ`, `PATCHJ` - for objects converted to JSON content 171 | 172 | ```fsharp 173 | GETJ "/yetAnotherOne" {| Success = true |} 174 | ``` 175 | 176 | ### ASYNC Overloads (task) ⚡️ 177 | 178 | * `GET_ASYNC`, `PUT_ASYNC`, `POST_ASYNC`, `DELETE_ASYNC`, `PATCH_ASYNC` - for handling asynchronous requests inside a task computation expression (async/await) and mock dynamically 179 | 180 | ```fsharp 181 | // example of control on request and route value dictionary 182 | // asynchronously 183 | POST_ASYNC "/externalApi" (fun r rvd -> 184 | task { 185 | // read request content and meddle here... 186 | return {| Success = true |} |> R_JSON 187 | } 188 | ) 189 | ``` 190 | 191 | ### HTTP response helpers 👨🏽‍🔧 192 | 193 | Available HTTP content constructors are: 194 | 195 | * `R_TEXT`: returns plain text 196 | * `R_JSON`: returns JSON 197 | * `R_ERROR`: returns an HTTP error 198 | 199 | ## Configuration helpers 🪈 200 | 201 | * `WITH_SERVICES`: to override your ConfigureServices for tests 202 | * `WITH_TEST_SERVICES`: to override your specific test services (a bit redundant in some cases, depending on the need) 203 | 204 | ## BDD (gherkin) Extensions 🥒 205 | 206 | You can use some BDD extension to perform [Gherkin-like setups and assertions](https://cucumber.io/docs/gherkin/reference/) 207 | 208 | they are all async `task` computations so they can be simply chained together: 209 | 210 | * `SCENARIO`: takes a `TestWebAppFactoryBuilder` as input and needs a name for your test scenario 211 | * `SETUP`: takes a scenario as input and can be used to configure the "test environmenttest": factory and the API client, additionally takes a separate API client configuration 212 | * `GIVEN`: takes a "test environment" or another "given" and returns a "given" step 213 | * `WHEN`: takes a "given" or another "when" step, and returns a a "when" step 214 | * `THEN`: takes a "when" step and asserts on it, returns the same "when" step as result to continue asserts 215 | * `END`: disposes the "test environment" and concludes the task computation 216 | 217 | ```fsharp 218 | // open ... 219 | open ApiStub.FSharp.BDD 220 | open HttpResponseMessageExtensions 221 | 222 | module BDDTests = 223 | 224 | let testce = new TestWebAppFactoryBuilder() 225 | 226 | [] 227 | let ``when i call /hello i get 'world' back with 200 ok`` () = 228 | 229 | let mutable expected = "_" 230 | let stubData = { Ok = "undefined" } 231 | 232 | // ARRANGE step is divided in CE (arrange client stubs) 233 | // SETUP: additional factory or service or client configuration 234 | // and GIVEN the actual arrange for the test 3As. 235 | 236 | // setup your test as usual here, test_ce is an instance of TestWebAppFactoryBuilder() 237 | test_ce { 238 | POSTJ "/another/anotherApi" {| Test = "NOT_USED_VAL" |} 239 | GET_ASYNC "/externalApi" (fun r _ -> task { 240 | return { stubData with Ok = expected } |> R_JSON 241 | }) 242 | } 243 | |> SCENARIO "when i call /Hello i get 'world' back with 200 ok" 244 | |> SETUP (fun s -> task { 245 | 246 | let test = s.TestWebAppFactoryBuilder 247 | 248 | // any additiona services or factory configuration before this point 249 | let f = test.GetFactory() 250 | 251 | return { 252 | Client = f.CreateClient() 253 | Factory = f 254 | Scenario = s 255 | FeatureStubData = stubData 256 | } 257 | }) (fun c -> c) // configure test client here if needed 258 | |> GIVEN (fun g -> //ArrangeData 259 | expected <- "world" 260 | expected |> Task.FromResult 261 | ) 262 | |> WHEN (fun g -> task { //ACT and AssertData 263 | let! (r : HttpResponseMessage) = g.Environment.Client.GetAsync("/Hello") 264 | return! r.Content.ReadFromJsonAsync() 265 | 266 | }) 267 | |> THEN (fun w -> // ASSERT 268 | Assert.Equal(w.Given.ArrangeData, w.AssertData.Ok) 269 | ) 270 | |> END 271 | 272 | ``` 273 | 274 | 275 | ## More Examples? 276 | 277 | Please take a look at the examples in the `test` folder for more details on the usage. 278 | 279 | ## How to Contribute ✍️ 280 | 281 | * Search for an open issue or report one, and check if a similar issue was reported first 282 | * feel free to get in touch, to fork and check out the repo 283 | * test and find use cases for this library, testing in F# is awesome!!!! 284 | 285 | 286 | ## Commit linting 📝 287 | 288 | This project uses [Commitlint](https://commitlint.js.org/) npm package and [ConventionalCommits](https://www.conventionalcommits.org/en/v1.0.0/#summary) specification for commits, so be aware to follow them when committing, via [Husky.NET](https://alirezanet.github.io/Husky.Net/guide/getting-started.html#add-your-first-hook) 289 | 290 | ## Versioning 📚 291 | 292 | This repository uses [Versionize](https://github.com/versionize/versionize/blob/master/.github/workflows/publish.yml) as a local dotnet tool to version packages when publishing. **Versionize** relies on [conventional commits](#commit-linting) to work properly. 293 | 294 | ### References 🤓 295 | 296 | * more info on [F# xunit testing](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-dotnet-test). 297 | * more general info on aspnetcore integration testing if you use [Nunit](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-nunit) instead. 298 | * [aspnetcore integration testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0) docs in C# 299 | 300 | ### 🕊️🌎🌳 301 | 302 | JUST_STOP_OIL 303 | 304 | [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua) 305 | 306 | [![Ceasefire Now](https://badge.techforpalestine.org/ceasefire-now)](https://techforpalestine.org/learn-more) 307 | 308 | 309 | -------------------------------------------------------------------------------- /bun.lock: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1, 3 | "workspaces": { 4 | "": { 5 | "devDependencies": { 6 | "@commitlint/cli": "^19.8.1", 7 | "@commitlint/config-conventional": "^19.8.1", 8 | }, 9 | }, 10 | }, 11 | "packages": { 12 | "@babel/code-frame": ["@babel/code-frame@7.27.1", "", { "dependencies": { "@babel/helper-validator-identifier": "^7.27.1", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" } }, "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg=="], 13 | 14 | "@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.27.1", "", {}, "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow=="], 15 | 16 | "@commitlint/cli": ["@commitlint/cli@19.8.1", "", { "dependencies": { "@commitlint/format": "^19.8.1", "@commitlint/lint": "^19.8.1", "@commitlint/load": "^19.8.1", "@commitlint/read": "^19.8.1", "@commitlint/types": "^19.8.1", "tinyexec": "^1.0.0", "yargs": "^17.0.0" }, "bin": { "commitlint": "./cli.js" } }, "sha512-LXUdNIkspyxrlV6VDHWBmCZRtkEVRpBKxi2Gtw3J54cGWhLCTouVD/Q6ZSaSvd2YaDObWK8mDjrz3TIKtaQMAA=="], 17 | 18 | "@commitlint/config-conventional": ["@commitlint/config-conventional@19.8.1", "", { "dependencies": { "@commitlint/types": "^19.8.1", "conventional-changelog-conventionalcommits": "^7.0.2" } }, "sha512-/AZHJL6F6B/G959CsMAzrPKKZjeEiAVifRyEwXxcT6qtqbPwGw+iQxmNS+Bu+i09OCtdNRW6pNpBvgPrtMr9EQ=="], 19 | 20 | "@commitlint/config-validator": ["@commitlint/config-validator@19.8.1", "", { "dependencies": { "@commitlint/types": "^19.8.1", "ajv": "^8.11.0" } }, "sha512-0jvJ4u+eqGPBIzzSdqKNX1rvdbSU1lPNYlfQQRIFnBgLy26BtC0cFnr7c/AyuzExMxWsMOte6MkTi9I3SQ3iGQ=="], 21 | 22 | "@commitlint/ensure": ["@commitlint/ensure@19.8.1", "", { "dependencies": { "@commitlint/types": "^19.8.1", "lodash.camelcase": "^4.3.0", "lodash.kebabcase": "^4.1.1", "lodash.snakecase": "^4.1.1", "lodash.startcase": "^4.4.0", "lodash.upperfirst": "^4.3.1" } }, "sha512-mXDnlJdvDzSObafjYrOSvZBwkD01cqB4gbnnFuVyNpGUM5ijwU/r/6uqUmBXAAOKRfyEjpkGVZxaDsCVnHAgyw=="], 23 | 24 | "@commitlint/execute-rule": ["@commitlint/execute-rule@19.8.1", "", {}, "sha512-YfJyIqIKWI64Mgvn/sE7FXvVMQER/Cd+s3hZke6cI1xgNT/f6ZAz5heND0QtffH+KbcqAwXDEE1/5niYayYaQA=="], 25 | 26 | "@commitlint/format": ["@commitlint/format@19.8.1", "", { "dependencies": { "@commitlint/types": "^19.8.1", "chalk": "^5.3.0" } }, "sha512-kSJj34Rp10ItP+Eh9oCItiuN/HwGQMXBnIRk69jdOwEW9llW9FlyqcWYbHPSGofmjsqeoxa38UaEA5tsbm2JWw=="], 27 | 28 | "@commitlint/is-ignored": ["@commitlint/is-ignored@19.8.1", "", { "dependencies": { "@commitlint/types": "^19.8.1", "semver": "^7.6.0" } }, "sha512-AceOhEhekBUQ5dzrVhDDsbMaY5LqtN8s1mqSnT2Kz1ERvVZkNihrs3Sfk1Je/rxRNbXYFzKZSHaPsEJJDJV8dg=="], 29 | 30 | "@commitlint/lint": ["@commitlint/lint@19.8.1", "", { "dependencies": { "@commitlint/is-ignored": "^19.8.1", "@commitlint/parse": "^19.8.1", "@commitlint/rules": "^19.8.1", "@commitlint/types": "^19.8.1" } }, "sha512-52PFbsl+1EvMuokZXLRlOsdcLHf10isTPlWwoY1FQIidTsTvjKXVXYb7AvtpWkDzRO2ZsqIgPK7bI98x8LRUEw=="], 31 | 32 | "@commitlint/load": ["@commitlint/load@19.8.1", "", { "dependencies": { "@commitlint/config-validator": "^19.8.1", "@commitlint/execute-rule": "^19.8.1", "@commitlint/resolve-extends": "^19.8.1", "@commitlint/types": "^19.8.1", "chalk": "^5.3.0", "cosmiconfig": "^9.0.0", "cosmiconfig-typescript-loader": "^6.1.0", "lodash.isplainobject": "^4.0.6", "lodash.merge": "^4.6.2", "lodash.uniq": "^4.5.0" } }, "sha512-9V99EKG3u7z+FEoe4ikgq7YGRCSukAcvmKQuTtUyiYPnOd9a2/H9Ak1J9nJA1HChRQp9OA/sIKPugGS+FK/k1A=="], 33 | 34 | "@commitlint/message": ["@commitlint/message@19.8.1", "", {}, "sha512-+PMLQvjRXiU+Ae0Wc+p99EoGEutzSXFVwQfa3jRNUZLNW5odZAyseb92OSBTKCu+9gGZiJASt76Cj3dLTtcTdg=="], 35 | 36 | "@commitlint/parse": ["@commitlint/parse@19.8.1", "", { "dependencies": { "@commitlint/types": "^19.8.1", "conventional-changelog-angular": "^7.0.0", "conventional-commits-parser": "^5.0.0" } }, "sha512-mmAHYcMBmAgJDKWdkjIGq50X4yB0pSGpxyOODwYmoexxxiUCy5JJT99t1+PEMK7KtsCtzuWYIAXYAiKR+k+/Jw=="], 37 | 38 | "@commitlint/read": ["@commitlint/read@19.8.1", "", { "dependencies": { "@commitlint/top-level": "^19.8.1", "@commitlint/types": "^19.8.1", "git-raw-commits": "^4.0.0", "minimist": "^1.2.8", "tinyexec": "^1.0.0" } }, "sha512-03Jbjb1MqluaVXKHKRuGhcKWtSgh3Jizqy2lJCRbRrnWpcM06MYm8th59Xcns8EqBYvo0Xqb+2DoZFlga97uXQ=="], 39 | 40 | "@commitlint/resolve-extends": ["@commitlint/resolve-extends@19.8.1", "", { "dependencies": { "@commitlint/config-validator": "^19.8.1", "@commitlint/types": "^19.8.1", "global-directory": "^4.0.1", "import-meta-resolve": "^4.0.0", "lodash.mergewith": "^4.6.2", "resolve-from": "^5.0.0" } }, "sha512-GM0mAhFk49I+T/5UCYns5ayGStkTt4XFFrjjf0L4S26xoMTSkdCf9ZRO8en1kuopC4isDFuEm7ZOm/WRVeElVg=="], 41 | 42 | "@commitlint/rules": ["@commitlint/rules@19.8.1", "", { "dependencies": { "@commitlint/ensure": "^19.8.1", "@commitlint/message": "^19.8.1", "@commitlint/to-lines": "^19.8.1", "@commitlint/types": "^19.8.1" } }, "sha512-Hnlhd9DyvGiGwjfjfToMi1dsnw1EXKGJNLTcsuGORHz6SS9swRgkBsou33MQ2n51/boIDrbsg4tIBbRpEWK2kw=="], 43 | 44 | "@commitlint/to-lines": ["@commitlint/to-lines@19.8.1", "", {}, "sha512-98Mm5inzbWTKuZQr2aW4SReY6WUukdWXuZhrqf1QdKPZBCCsXuG87c+iP0bwtD6DBnmVVQjgp4whoHRVixyPBg=="], 45 | 46 | "@commitlint/top-level": ["@commitlint/top-level@19.8.1", "", { "dependencies": { "find-up": "^7.0.0" } }, "sha512-Ph8IN1IOHPSDhURCSXBz44+CIu+60duFwRsg6HqaISFHQHbmBtxVw4ZrFNIYUzEP7WwrNPxa2/5qJ//NK1FGcw=="], 47 | 48 | "@commitlint/types": ["@commitlint/types@19.8.1", "", { "dependencies": { "@types/conventional-commits-parser": "^5.0.0", "chalk": "^5.3.0" } }, "sha512-/yCrWGCoA1SVKOks25EGadP9Pnj0oAIHGpl2wH2M2Y46dPM2ueb8wyCVOD7O3WCTkaJ0IkKvzhl1JY7+uCT2Dw=="], 49 | 50 | "@types/conventional-commits-parser": ["@types/conventional-commits-parser@5.0.1", "", { "dependencies": { "@types/node": "*" } }, "sha512-7uz5EHdzz2TqoMfV7ee61Egf5y6NkcO4FB/1iCCQnbeiI1F3xzv3vK5dBCXUCLQgGYS+mUeigK1iKQzvED+QnQ=="], 51 | 52 | "@types/node": ["@types/node@22.15.17", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-wIX2aSZL5FE+MR0JlvF87BNVrtFWf6AE6rxSE9X7OwnVvoyCQjpzSRJ+M87se/4QCkCiebQAqrJ0y6fwIyi7nw=="], 53 | 54 | "JSONStream": ["JSONStream@1.3.5", "", { "dependencies": { "jsonparse": "^1.2.0", "through": ">=2.2.7 <3" }, "bin": { "JSONStream": "./bin.js" } }, "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ=="], 55 | 56 | "ajv": ["ajv@8.17.1", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g=="], 57 | 58 | "ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], 59 | 60 | "ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="], 61 | 62 | "argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="], 63 | 64 | "array-ify": ["array-ify@1.0.0", "", {}, "sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng=="], 65 | 66 | "callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="], 67 | 68 | "chalk": ["chalk@5.4.1", "", {}, "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w=="], 69 | 70 | "cliui": ["cliui@8.0.1", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="], 71 | 72 | "color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="], 73 | 74 | "color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="], 75 | 76 | "compare-func": ["compare-func@2.0.0", "", { "dependencies": { "array-ify": "^1.0.0", "dot-prop": "^5.1.0" } }, "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA=="], 77 | 78 | "conventional-changelog-angular": ["conventional-changelog-angular@7.0.0", "", { "dependencies": { "compare-func": "^2.0.0" } }, "sha512-ROjNchA9LgfNMTTFSIWPzebCwOGFdgkEq45EnvvrmSLvCtAw0HSmrCs7/ty+wAeYUZyNay0YMUNYFTRL72PkBQ=="], 79 | 80 | "conventional-changelog-conventionalcommits": ["conventional-changelog-conventionalcommits@7.0.2", "", { "dependencies": { "compare-func": "^2.0.0" } }, "sha512-NKXYmMR/Hr1DevQegFB4MwfM5Vv0m4UIxKZTTYuD98lpTknaZlSRrDOG4X7wIXpGkfsYxZTghUN+Qq+T0YQI7w=="], 81 | 82 | "conventional-commits-parser": ["conventional-commits-parser@5.0.0", "", { "dependencies": { "JSONStream": "^1.3.5", "is-text-path": "^2.0.0", "meow": "^12.0.1", "split2": "^4.0.0" }, "bin": { "conventional-commits-parser": "cli.mjs" } }, "sha512-ZPMl0ZJbw74iS9LuX9YIAiW8pfM5p3yh2o/NbXHbkFuZzY5jvdi5jFycEOkmBW5H5I7nA+D6f3UcsCLP2vvSEA=="], 83 | 84 | "cosmiconfig": ["cosmiconfig@9.0.0", "", { "dependencies": { "env-paths": "^2.2.1", "import-fresh": "^3.3.0", "js-yaml": "^4.1.0", "parse-json": "^5.2.0" }, "peerDependencies": { "typescript": ">=4.9.5" }, "optionalPeers": ["typescript"] }, "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg=="], 85 | 86 | "cosmiconfig-typescript-loader": ["cosmiconfig-typescript-loader@6.1.0", "", { "dependencies": { "jiti": "^2.4.1" }, "peerDependencies": { "@types/node": "*", "cosmiconfig": ">=9", "typescript": ">=5" } }, "sha512-tJ1w35ZRUiM5FeTzT7DtYWAFFv37ZLqSRkGi2oeCK1gPhvaWjkAtfXvLmvE1pRfxxp9aQo6ba/Pvg1dKj05D4g=="], 87 | 88 | "dargs": ["dargs@8.1.0", "", {}, "sha512-wAV9QHOsNbwnWdNW2FYvE1P56wtgSbM+3SZcdGiWQILwVjACCXDCI3Ai8QlCjMDB8YK5zySiXZYBiwGmNY3lnw=="], 89 | 90 | "dot-prop": ["dot-prop@5.3.0", "", { "dependencies": { "is-obj": "^2.0.0" } }, "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q=="], 91 | 92 | "emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="], 93 | 94 | "env-paths": ["env-paths@2.2.1", "", {}, "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A=="], 95 | 96 | "error-ex": ["error-ex@1.3.2", "", { "dependencies": { "is-arrayish": "^0.2.1" } }, "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g=="], 97 | 98 | "escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="], 99 | 100 | "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="], 101 | 102 | "fast-uri": ["fast-uri@3.0.6", "", {}, "sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw=="], 103 | 104 | "find-up": ["find-up@7.0.0", "", { "dependencies": { "locate-path": "^7.2.0", "path-exists": "^5.0.0", "unicorn-magic": "^0.1.0" } }, "sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g=="], 105 | 106 | "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="], 107 | 108 | "git-raw-commits": ["git-raw-commits@4.0.0", "", { "dependencies": { "dargs": "^8.0.0", "meow": "^12.0.1", "split2": "^4.0.0" }, "bin": { "git-raw-commits": "cli.mjs" } }, "sha512-ICsMM1Wk8xSGMowkOmPrzo2Fgmfo4bMHLNX6ytHjajRJUqvHOw/TFapQ+QG75c3X/tTDDhOSRPGC52dDbNM8FQ=="], 109 | 110 | "global-directory": ["global-directory@4.0.1", "", { "dependencies": { "ini": "4.1.1" } }, "sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q=="], 111 | 112 | "import-fresh": ["import-fresh@3.3.1", "", { "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" } }, "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ=="], 113 | 114 | "import-meta-resolve": ["import-meta-resolve@4.1.0", "", {}, "sha512-I6fiaX09Xivtk+THaMfAwnA3MVA5Big1WHF1Dfx9hFuvNIWpXnorlkzhcQf6ehrqQiiZECRt1poOAkPmer3ruw=="], 115 | 116 | "ini": ["ini@4.1.1", "", {}, "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g=="], 117 | 118 | "is-arrayish": ["is-arrayish@0.2.1", "", {}, "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg=="], 119 | 120 | "is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="], 121 | 122 | "is-obj": ["is-obj@2.0.0", "", {}, "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w=="], 123 | 124 | "is-text-path": ["is-text-path@2.0.0", "", { "dependencies": { "text-extensions": "^2.0.0" } }, "sha512-+oDTluR6WEjdXEJMnC2z6A4FRwFoYuvShVVEGsS7ewc0UTi2QtAKMDJuL4BDEVt+5T7MjFo12RP8ghOM75oKJw=="], 125 | 126 | "jiti": ["jiti@2.4.2", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A=="], 127 | 128 | "js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="], 129 | 130 | "js-yaml": ["js-yaml@4.1.0", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA=="], 131 | 132 | "json-parse-even-better-errors": ["json-parse-even-better-errors@2.3.1", "", {}, "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="], 133 | 134 | "json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], 135 | 136 | "jsonparse": ["jsonparse@1.3.1", "", {}, "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg=="], 137 | 138 | "lines-and-columns": ["lines-and-columns@1.2.4", "", {}, "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg=="], 139 | 140 | "locate-path": ["locate-path@7.2.0", "", { "dependencies": { "p-locate": "^6.0.0" } }, "sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA=="], 141 | 142 | "lodash.camelcase": ["lodash.camelcase@4.3.0", "", {}, "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA=="], 143 | 144 | "lodash.isplainobject": ["lodash.isplainobject@4.0.6", "", {}, "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA=="], 145 | 146 | "lodash.kebabcase": ["lodash.kebabcase@4.1.1", "", {}, "sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g=="], 147 | 148 | "lodash.merge": ["lodash.merge@4.6.2", "", {}, "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="], 149 | 150 | "lodash.mergewith": ["lodash.mergewith@4.6.2", "", {}, "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ=="], 151 | 152 | "lodash.snakecase": ["lodash.snakecase@4.1.1", "", {}, "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw=="], 153 | 154 | "lodash.startcase": ["lodash.startcase@4.4.0", "", {}, "sha512-+WKqsK294HMSc2jEbNgpHpd0JfIBhp7rEV4aqXWqFr6AlXov+SlcgB1Fv01y2kGe3Gc8nMW7VA0SrGuSkRfIEg=="], 155 | 156 | "lodash.uniq": ["lodash.uniq@4.5.0", "", {}, "sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ=="], 157 | 158 | "lodash.upperfirst": ["lodash.upperfirst@4.3.1", "", {}, "sha512-sReKOYJIJf74dhJONhU4e0/shzi1trVbSWDOhKYE5XV2O+H7Sb2Dihwuc7xWxVl+DgFPyTqIN3zMfT9cq5iWDg=="], 159 | 160 | "meow": ["meow@12.1.1", "", {}, "sha512-BhXM0Au22RwUneMPwSCnyhTOizdWoIEPU9sp0Aqa1PnDMR5Wv2FGXYDjuzJEIX+Eo2Rb8xuYe5jrnm5QowQFkw=="], 161 | 162 | "minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="], 163 | 164 | "p-limit": ["p-limit@4.0.0", "", { "dependencies": { "yocto-queue": "^1.0.0" } }, "sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ=="], 165 | 166 | "p-locate": ["p-locate@6.0.0", "", { "dependencies": { "p-limit": "^4.0.0" } }, "sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw=="], 167 | 168 | "parent-module": ["parent-module@1.0.1", "", { "dependencies": { "callsites": "^3.0.0" } }, "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g=="], 169 | 170 | "parse-json": ["parse-json@5.2.0", "", { "dependencies": { "@babel/code-frame": "^7.0.0", "error-ex": "^1.3.1", "json-parse-even-better-errors": "^2.3.0", "lines-and-columns": "^1.1.6" } }, "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg=="], 171 | 172 | "path-exists": ["path-exists@5.0.0", "", {}, "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ=="], 173 | 174 | "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], 175 | 176 | "require-directory": ["require-directory@2.1.1", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="], 177 | 178 | "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], 179 | 180 | "resolve-from": ["resolve-from@5.0.0", "", {}, "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw=="], 181 | 182 | "semver": ["semver@7.7.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA=="], 183 | 184 | "split2": ["split2@4.2.0", "", {}, "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg=="], 185 | 186 | "string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="], 187 | 188 | "strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], 189 | 190 | "text-extensions": ["text-extensions@2.4.0", "", {}, "sha512-te/NtwBwfiNRLf9Ijqx3T0nlqZiQ2XrrtBvu+cLL8ZRrGkO0NHTug8MYFKyoSrv/sHTaSKfilUkizV6XhxMJ3g=="], 191 | 192 | "through": ["through@2.3.8", "", {}, "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg=="], 193 | 194 | "tinyexec": ["tinyexec@1.0.1", "", {}, "sha512-5uC6DDlmeqiOwCPmK9jMSdOuZTh8bU39Ys6yidB+UTt5hfZUPGAypSgFRiEp+jbi9qH40BLDvy85jIU88wKSqw=="], 195 | 196 | "typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="], 197 | 198 | "undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], 199 | 200 | "unicorn-magic": ["unicorn-magic@0.1.0", "", {}, "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ=="], 201 | 202 | "wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="], 203 | 204 | "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="], 205 | 206 | "yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="], 207 | 208 | "yargs-parser": ["yargs-parser@21.1.1", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="], 209 | 210 | "yocto-queue": ["yocto-queue@1.2.1", "", {}, "sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg=="], 211 | 212 | "import-fresh/resolve-from": ["resolve-from@4.0.0", "", {}, "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g=="], 213 | } 214 | } 215 | --------------------------------------------------------------------------------