Skip to content

Instantly share code, notes, and snippets.

View stijnmoreels's full-sized avatar
🧪
Testing better than yesterday

Stijn Moreels stijnmoreels

🧪
Testing better than yesterday
View GitHub Profile
using Bogus;
public static class Arg
{
private static readonly Faker Bogus = new();
public static class String
{
public static Arg<string> Ignore()
{
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; }
public class MyTestContext
{
private string _tag;
public static MyTestContext Given()
{
return new MyTestContext();
}
public void WhenRequest(string tag = "#a1b23")
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
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)
open FsCheck
let withProperty arb body = async {
let config =
Config.QuickThrowOnFailure
.WithNoParallelRunConfig()
.WithMaxTest(1)
do Check.One (
config,
Prop.forAll arb body) }
[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
[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"),
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 {
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