This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Bogus; | |
| public static class Arg | |
| { | |
| private static readonly Faker Bogus = new(); | |
| public static class String | |
| { | |
| public static Arg<string> Ignore() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Arg<T> | |
| { | |
| public Arg(T value, bool canOverwrite) | |
| { | |
| Value = value; | |
| CanOverwrite = canOverwrite; | |
| } | |
| public T Value { get; private set; } | |
| public bool CanOverwrite { get; private set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyTestContext | |
| { | |
| private string _tag; | |
| public static MyTestContext Given() | |
| { | |
| return new MyTestContext(); | |
| } | |
| public void WhenRequest(string tag = "#a1b23") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| info: Request GET http://localhost:5056/tag/VwJzlzk0XW | |
| info: Request GET http://localhost:5056/tag/VwJzlzk0X | |
| info: Request GET http://localhost:5056/tag/VwJzlzk0X | |
| info: Request GET http://localhost:5056/tag/VwJzlzk0 | |
| info: Request GET http://localhost:5056/tag/VwJzlzk | |
| info: Request GET http://localhost:5056/tag/VwJzlz | |
| info: Request GET http://localhost:5056/tag/VwJzl | |
| info: Request GET http://localhost:5056/tag/VwJz | |
| info: Request GET http://localhost:5056/tag/VwJ | |
| info: Request GET http://localhost:5056/tag/Vw |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open Expecto | |
| open FsCheck | |
| module Arb = | |
| let tag = Arb.fromGenShrink (Gen.tag, Shrink.tag) | |
| let tagAppFixture = | |
| Fixture.Giraffe.app (routef "/tag/%s" (fun x -> | |
| text $"tagged #{x}") >=> setStatusCode 200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open FsCheck | |
| let withProperty arb body = async { | |
| let config = | |
| Config.QuickThrowOnFailure | |
| .WithNoParallelRunConfig() | |
| .WithMaxTest(1) | |
| do Check.One ( | |
| config, | |
| Prop.forAll arb body) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Fact] | |
| public async Task GetListOfBooks_WithSingleAvailableBook_Succeeds() | |
| { | |
| // Arrange | |
| await using LibraryApiContext context = await GivenLibraryApiAsync(); | |
| Book[] expected = await context.WhenAvailableBooksAsync(count: 3); | |
| context.WhenRequest(amount: 1); | |
| // Act |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Fact] | |
| public async Task GetListOfBooks_WithSingleAvailableBook_Succeeds() | |
| { | |
| // Arrange | |
| await using var app = await TemporaryLibraryApi.StartNewAsync(Configuration, Logger); | |
| var books = new[] | |
| { | |
| Book.Create("Annihilation", "Jeff VanderMeer"), | |
| Book.Create("A Man of Shadows", "Jeff Noon"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let fixture = | |
| Fixture.Giraffe.app 6001 (route "/one" >=> Http.get 7001 "/two") | |
| |> Fixture.add (Fixture.Giraffe.app 7001 (route "/two" >=> text "three")) | |
| |> Fixture.usingSync | |
| (fun () -> Environment.SetEnvironmentVariable("Testing", "Temp")) | |
| (fun () -> Environment.SetEnvironmentVariable("Testing", null)) | |
| |> Fixture.apply | |
| testFixtureAsync fixture [ | |
| "one-two-three", fun (client, _) -> async { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let using setup teardown fixture = | |
| { fixture with | |
| Setup = async { | |
| let! first = catchExceptions setup | |
| match! fixture.Setup with | |
| | Ok v when first = [] -> return Ok v | |
| | Ok _ -> return Error first | |
| | Error err -> return Error (first @ err) } | |
| Teardown = fun x -> async { | |
| let! second = fixture.Teardown x |