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 command makes this orderDataService mock object into a stub. // Arg.IsAny<Order>()) is a matcher, not with any specific functionality, //orther than being an object of Order. 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); // IsInInventory method is called with the expected item id (the same itemId in the shopping cart). If two itemsIds are different, the test will fail. 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)); //Act var result = orderService.PlaceOrder(customerId, shoppingCart); //Assert Assert.That(expectedOrderId, Is.EqualTo(result)); Mock.Assert(orderDataService); Mock.Assert(orderFulfillmentService); }
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); }
private Dictionary <Guid, int> CheckInventoryLevels(Guid orderFulfillmentSessionId, ShoppingCart shoppingCart) { var itemsInInventory = shoppingCart.Items.Where(item => _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, item.ItemId, item.Quantity)); var orderForFulfillmentService = new Dictionary <Guid, int>(); itemsInInventory.ToList().ForEach(item => { orderForFulfillmentService.Add(item.ItemId, item.Quantity); }); return(orderForFulfillmentService); }
public void WhenUserPlacesOrderWithItemThatIsInInventoryOrderFulfillmentWorkflowShouldComplete() { //Arrange var shoppingCart = new ShoppingCart(); var itemId = Guid.NewGuid(); shoppingCart.Items.Add(new ShoppingCartItem { ItemId = itemId, Quantity = 1 }); var customerId = Guid.NewGuid(); var customer = new Customer { Id = customerId }; var orderFulfillmentSessionId = Guid.NewGuid(); Mock.Arrange(() => _customerService.GetCustomer(customerId)).Returns(customer).OccursOnce(); Mock.Arrange(() => _orderFulfillmentService.OpenSession(Arg.IsAny <string>(), Arg.IsAny <string>())) .Returns(orderFulfillmentSessionId) .InOrder(); Mock.Arrange(() => _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, itemId, 1)) .Returns(true) .InOrder(); Mock.Arrange(() => _orderFulfillmentService. PlaceOrder(orderFulfillmentSessionId, Arg.IsAny <IDictionary <Guid, int> >(), Arg.IsAny <string>())) .Returns(true) .InOrder(); Mock.Arrange(() => _orderFulfillmentService.CloseSession(orderFulfillmentSessionId)) .InOrder(); //Act _orderService.PlaceOrder(customerId, shoppingCart); //Assert Mock.Assert(_orderFulfillmentService); }
private Dictionary <Guid, int> CheckInventoryLevels(Guid orderFulfillmentSessionId, ShoppingCart shoppingCart) { var orderForFulfillmentService = new Dictionary <Guid, int>(); foreach (var shoppingCartItem in shoppingCart.Items) { var itemId = shoppingCartItem.ItemId; var itemQuantity = shoppingCartItem.Quantity; // check inventory var itemIsInInventory = _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, itemId, itemQuantity); orderForFulfillmentService.Add(itemId, itemQuantity); } return(orderForFulfillmentService); }
private void PlaceOrderWithFulfillmentService(Guid orderFulfillmentSessionId, ShoppingCart shoppingCart, Customer customer) { var firstItemId = shoppingCart.Items[0].ItemId; var firstItemQuantity = shoppingCart.Items[0].Quantity; //Check Inventory Level var itemIsInInventory = _orderFulfillmentService.IsInInventory(orderFulfillmentSessionId, firstItemId, firstItemQuantity); //Place Orders var orderForFulfillmentService = new Dictionary <Guid, int>(); orderForFulfillmentService.Add(firstItemId, firstItemQuantity); var orderPlaced = _orderFulfillmentService.PlaceOrder(orderFulfillmentSessionId, orderForFulfillmentService, customer.ShippingAddress.ToString()); }