Skip to content

Commit

Permalink
Handle Cart Sample corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Dec 21, 2018
1 parent a946bf0 commit f443417
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion samples/Store/Domain.Tests/CartTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ let verifyIdempotency (cmd: Command) (originState: State) =
// Assert we decided nothing needs to happen
test <@ List.isEmpty events @>

[<DomainProperty(MaxTest = 1000)>]
/// These cases are assumed to be covered by external validation, so logic can treat them as hypotheticals rather than have to reject
let isValid = function
| PatchItem (_, _, Some quantity, _)
| AddItem (_, _, quantity) -> quantity >= 0
| _ -> true

[<DomainProperty>]
let ``interpret yields correct events, idempotently`` (cmd: Command) (originState: State) =
if not (isValid cmd) then () else
verifyCanProcessInInitialState cmd originState
verifyCorrectEventGenerationWhenAppropriate cmd originState
verifyIdempotency cmd originState
2 changes: 1 addition & 1 deletion samples/Store/Domain/Cart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Commands =
let itemExistsWithDifferentWaiveStatus skuId waive = itemExists (fun x -> x.skuId = skuId && x.returnsWaived <> waive)
let itemExistsWithDifferentQuantity skuId quantity = itemExists (fun x -> x.skuId = skuId && x.quantity <> quantity)
let itemExistsWithSameQuantity skuId quantity = itemExists (fun x -> x.skuId = skuId && x.quantity = quantity)
let itemExistsWithSkuId skuId = itemExists (fun x -> x.skuId = skuId)
let itemExistsWithSkuId skuId = itemExists (fun x -> x.skuId = skuId && x.quantity <> 0)
let toEventContext (reqContext: Context) = { requestId = reqContext.requestId; time = reqContext.time } : Events.ContextInfo
let (|Context|) (context : Context) = toEventContext context
match command with
Expand Down

0 comments on commit f443417

Please sign in to comment.