Skip to content

Commit

Permalink
Added business logic tests for mixed version
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed May 3, 2024
1 parent 22a8fcd commit 972180c
Show file tree
Hide file tree
Showing 15 changed files with 726 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void CantAddProductItemToNotExistingShoppingCart() =>
Spec.Given([])
.When(state =>
Handle(
FakeProductPriceCalculator.Returning(price),
new AddProductItemToShoppingCart(shoppingCartId, productItem, now),
FakeProductPriceCalculator.Returning(Price),
new AddProductItemToShoppingCart(shoppingCartId, ProductItem, now),
state
)
)
Expand All @@ -36,15 +36,15 @@ public void AddsProductItemToEmptyShoppingCart() =>
])
.When(state =>
Handle(
FakeProductPriceCalculator.Returning(price),
new AddProductItemToShoppingCart(shoppingCartId, productItem, now),
FakeProductPriceCalculator.Returning(Price),
new AddProductItemToShoppingCart(shoppingCartId, ProductItem, now),
state
)
)
.Then(
new ProductItemAddedToShoppingCart(
shoppingCartId,
new PricedProductItem(productItem.ProductId, productItem.Quantity, price),
new PricedProductItem(ProductItem.ProductId, ProductItem.Quantity, Price),
now
)
);
Expand All @@ -58,15 +58,15 @@ public void AddsProductItemToNonEmptyShoppingCart() =>
])
.When(state =>
Handle(
FakeProductPriceCalculator.Returning(otherPrice),
new AddProductItemToShoppingCart(shoppingCartId, otherProductItem, now),
FakeProductPriceCalculator.Returning(OtherPrice),
new AddProductItemToShoppingCart(shoppingCartId, OtherProductItem, now),
state
)
)
.Then(
new ProductItemAddedToShoppingCart(
shoppingCartId,
new PricedProductItem(otherProductItem.ProductId, otherProductItem.Quantity, otherPrice),
new PricedProductItem(OtherProductItem.ProductId, OtherProductItem.Quantity, OtherPrice),
now
)
);
Expand All @@ -80,8 +80,8 @@ public void CantAddProductItemToConfirmedShoppingCart() =>
])
.When(state =>
Handle(
FakeProductPriceCalculator.Returning(price),
new AddProductItemToShoppingCart(shoppingCartId, productItem, now),
FakeProductPriceCalculator.Returning(Price),
new AddProductItemToShoppingCart(shoppingCartId, ProductItem, now),
state
)
)
Expand All @@ -96,8 +96,8 @@ public void CantAddProductItemToCanceledShoppingCart() =>
])
.When(state =>
Handle(
FakeProductPriceCalculator.Returning(price),
new AddProductItemToShoppingCart(shoppingCartId, productItem, now),
FakeProductPriceCalculator.Returning(Price),
new AddProductItemToShoppingCart(shoppingCartId, ProductItem, now),
state
)
)
Expand Down Expand Up @@ -136,7 +136,7 @@ public void RemovesExistingProductItemFromShoppingCart() =>
);

[Fact]
public void CantRemoveNonExistingProductItemFromEmptyShoppingCart() =>
public void CantRemoveNonExistingProductItemFromNonEmptyShoppingCart() =>
Spec.Given([
new ShoppingCartOpened(shoppingCartId, clientId, now),
new ProductItemAddedToShoppingCart(shoppingCartId, pricedProductItem, now),
Expand Down Expand Up @@ -298,16 +298,16 @@ public void CantCancelConfirmedShoppingCart() =>
private readonly DateTimeOffset now = DateTimeOffset.Now;
private readonly Guid clientId = Guid.NewGuid();
private readonly Guid shoppingCartId = Guid.NewGuid();
private readonly ProductItem productItem = new(Guid.NewGuid(), Random.Shared.Next(1, 200));
private readonly ProductItem otherProductItem = new(Guid.NewGuid(), Random.Shared.Next(1, 200));
private static readonly int price = Random.Shared.Next(1, 1000);
private static readonly int otherPrice = Random.Shared.Next(1, 1000);
private readonly PricedProductItem pricedProductItem = new(Guid.NewGuid(), Random.Shared.Next(1, 200), price);

private static readonly ProductItem ProductItem = new(Guid.NewGuid(), Random.Shared.Next(1, 200));
private static readonly ProductItem OtherProductItem = new(Guid.NewGuid(), Random.Shared.Next(1, 200));
private static readonly int Price = Random.Shared.Next(1, 1000);
private static readonly int OtherPrice = Random.Shared.Next(1, 1000);
private readonly PricedProductItem pricedProductItem =
new(ProductItem.ProductId, ProductItem.Quantity, Price);
private readonly PricedProductItem otherPricedProductItem =
new(Guid.NewGuid(), Random.Shared.Next(1, 200), otherPrice);
new(OtherProductItem.ProductId, OtherProductItem.Quantity, Price);


private readonly HandlerSpecification<ShoppingCartEvent, ShoppingCart> Spec =
Specification.For<ShoppingCartEvent, ShoppingCart>(ShoppingCart.Evolve, ShoppingCart.Default);
Specification.For<ShoppingCartEvent, ShoppingCart>(ShoppingCart.Evolve, ShoppingCart.Initial);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public bool HasEnough(PricedProductItem productItem)
return currentQuantity >= quantity;
}

public static ShoppingCart Default() =>
public static ShoppingCart Initial() =>
new (default, default, default, [], default);

public static ShoppingCart Evolve(ShoppingCart shoppingCart, ShoppingCartEvent @event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static ShoppingCartConfirmed Handle(ConfirmShoppingCart command, Shopping
throw new InvalidOperationException($"Confirming cart in '{shoppingCart.Status}' status is not allowed.");

if(shoppingCart.ProductItems.Length == 0)
throw new InvalidOperationException($"Cannot confirm empty shopping cart");
throw new InvalidOperationException("Cannot confirm empty shopping cart");

return new ShoppingCartConfirmed(
shoppingCart.Id,
Expand Down
Loading

0 comments on commit 972180c

Please sign in to comment.