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 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); }
public void WhenUserPlacesACorrectOrderThenAnOrderNumberShouldBeReturned1() { // Arrange var itemId = Guid.NewGuid(); var shoppingCart = new ShoppingCart(); 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); 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.AreEqual(expectedOrderId, result); Mock.Assert(_orderDataService); Mock.Assert(_orderFulfillmentService); }
private void CloseOrderFulfillmentService(Guid orderFulfillmentSessionId) { _orderFulfillmentService.CloseSession(orderFulfillmentSessionId); }