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
[Fact]
public void Delete_WithMessageId_ShouldDeleteMessage()
{
// Arrange
var messageId = Guid.NewGuid().ToString();
var repo = new Mock<IMessageRepository>();
repo.Setup(r => r.DeleteMessage(messageId)).Returns(1);
var cache = new Mock<IMessageCache>();
cache.Setup(c => c.Get(messageId)).Returns(Cache.NotInCache);
restaurant fully booked always exceeds capacity failed
{ Name = GuestName "xycQKLpdXBCspKq"
Quantity = Quantity 1
Date = Date 30/11/2023 00:00:00 +00:00 } [{ Name = GuestName "kWWQQebC"
Quantity = Quantity 15
Date = Date 18/11/2023 00:00:00 +00:00 };
{ Name = GuestName "mnvWmFjdYSwqlfJDh"
Quantity = Quantity 14
Date = Date 19/11/2023 00:00:00 +00:00 };
{ Name = GuestName "ICg"
restaurant tests.restaurant accepts reservation within two weeks if the requested quantity is available failed
Failed after 2 tests. Parameters:
({ Name = GuestName "jd"
Quantity = Quantity 19
Date = Date 01/12/2023 00:00:00 +00:00 }, [])
Label of failing property:
capacity on 2023-12-01: 0
module Label =
let capacityOn d current =
List.filter (fun x -> x.Date = d) current
|> List.sumBy Reservation.quantity
|> (sprintf "\n\tcapacity on %A: %i" d)
testProperty "restaurant accepts reservation within two weeks if the requested quantity is available" <| fun () ->
withGen Gen.Reservation.available <| fun (addition, current) ->
reserveTable current addition = Ok (addition :: current)
|@ (Label.capacityOn addition.Date current)
restaurant tests.restaurant with no reservations always accepts reservation failed
Failed after 18 tests. Parameters:
{ Name = GuestName "GA"
Quantity = Quantity 20
Date = Date 23/11/2023 00:00:00 +00:00 }
reserveTable [] r = Ok([r])
reserveTable [] { Name = GuestName "GA"
Quantity = Quantity 20
Date = Date 23/11/2023 00:00:00 +00:00 } = Ok([{ Name = GuestName "GA"
open Swensen.Unquote
testProperty "restaurant with no reservations always accepts reservation" <| fun r ->
test <@ reserveTable [] r = Ok [r] @>
open FPrimitive
module Folder =
/// Alphanum10 -> Folder list -> Result<Folder, ErrorsByTag>
let create id xs = result {
let! children = specResult xs {
tag "folder.width"
inclusiveBetweenOf List.length 0 Folder.Limits.maxWidth $"require a max of {Folder.Limits.maxWidth} children on each level" }
let x = { Id = id; Children = children }
type Folder =
private { Id : Alphanum10
Children : Folder list }
open FsCheck
module Gen =
module FolderDto =
let tooWide =
tree 0 maxDepth 10 10 (fun xs ->
Folder.id
|> Gen.map (fun x -> Tree.create x.Value xs))
|> Gen.filter (fun t -> t.Branches <> [])
|> Gen.map treeToDto
open FsCheck
module Gen =
// int -> int -> int -> int -> ('a list -> Gen<'a>) -> Gen<'a>
let tree minDepth maxDepth minWidth maxWidth factory =
Gen.sized <| fun s ->
let rec recurse depth s =
if s = 0 || depth >= maxDepth
then factory []
else gen {