Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Test]
public void WhenUserPlacesACorrectOrderWithMoreThenOneItemThenAnOrderNumberShouldBeReturned()
{
//Arrange
var shoppingCart = new ShoppingCart();
var itemOneId = Guid.NewGuid();
var itemTwoId = Guid.NewGuid();
int itemOneQuantity = 1;
int itemTwoQuantity = 4;
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = itemOneId, Quantity = itemOneQuantity });
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = itemTwoId, Quantity = itemTwoQuantity });
var customerId = Guid.NewGuid();
var expectedOrderId = Guid.NewGuid();
var orderFulfillmentSessionId = Guid.NewGuid();
var customer = new Customer { Id = customerId };
Mock.Arrange(() => _orderDataService.Save(Arg.IsAny<Order>()))
.Returns(expectedOrderId)
.OccursOnce();
Mock.Arrange(() => _customerService.GetCustomer(customerId)).Returns(customer).OccursOnce();
Mock.Arrange(() => _orderFulfillmentService.OpenSession(Arg.IsAny<string>(), Arg.IsAny<string>()))
.Returns(orderFulfillmentSessionId);
Mock.Arrange(() => _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, itemOneId, itemOneQuantity))
.Returns(true)
.OccursOnce();
Mock.Arrange(() => _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, itemTwoId, itemTwoQuantity))
.Returns(true)
.OccursOnce();
Mock.Arrange(() =>
_orderFulfillmentService.
PlaceOrder(orderFulfillmentSessionId, Arg.IsAny<IDictionary<Guid, int>>(), Arg.IsAny<string>()))
.Returns(true);
//Act
var result = _orderService.PlaceOrder(customerId, shoppingCart);
//Assert
Assert.AreEqual(expectedOrderId, result);
Mock.Assert(_orderDataService);
Mock.Assert(_orderFulfillmentService);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment