Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Test]
public void WhenUserPlacesACorrectOrderThenAnOrderNumberShouldBeReturned()
{
//Arrange
var shoppingCart = new ShoppingCart();
var itemId = Guid.NewGuid();
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = itemId, Quantity = 1 });
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).OccursOnce();
Mock.Arrange(() => _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, itemId, 1))
.Returns(true).OccursOnce();
Mock.Arrange(() =>
_orderFulfillmentService.
PlaceOrder(orderFulfillmentSessionId, Arg.IsAny<IDictionary<Guid, int>>(), Arg.IsAny<string>()))
.Returns(true);
Mock.Arrange(() => _orderFulfillmentService.CloseSession(orderFulfillmentSessionId)).OccursOnce();
//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
You can’t perform that action at this time.