public void WhenUserPlacesACorrectOrderThenAnOrderNumberShouldBeReturned()
        {
            // Arrange
            var shoppingCart = new ShoppingCart();

            shoppingCart.Items.Add(new ShoppingCartItem {
                ItemId = Guid.NewGuid(), Quantity = 1
            });
            var customerId = Guid.NewGuid();
            var customer   = new Customer {
                Id = customerId
            };
            var expectedOrderId = Guid.NewGuid();

            Mock.Arrange(() => _customerService.GetCustomer(customerId)).Returns(customer);
            Mock.Arrange(() => _orderDataService.Save(Arg.IsAny <Order>()))
            .Returns(expectedOrderId)
            .OccursOnce();

            // Act
            var result = _orderService.PlaceOrder(customerId, shoppingCart);

            // Assert
            Assert.AreEqual(expectedOrderId, result);
            Mock.Assert(_orderDataService);
        }
        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 object PlaceOrder(Guid customerId, ShoppingCart shoppingCart)
        {
            var order = new Order();

            return(_orderDataService.Save(order));
            //return Guid.NewGuid();
        }
Exemplo n.º 4
0
        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);
            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);
        }
Exemplo n.º 5
0
        public void WhenUserPlacesACorrectOrderThenAnOrderNumberShouldBeReturned()
        {
            var shoppingCart = new ShoppingCart();

            shoppingCart.Items.Add(new ShoppingCartItem {
                ItemId = Guid.NewGuid(), Quantity = 1
            });
            var customerId      = Guid.NewGuid();
            var expectedOrderId = Guid.NewGuid();

            Mock.Arrange(() => _orderDataService.Save(Arg.IsAny <Order>()))
            .Returns(expectedOrderId)
            .OccursOnce();

            //OrderService orderService = new OrderService(orderDataService);

            var result = _orderService.PlaceOrder(customerId, shoppingCart);

            Assert.AreEqual(expectedOrderId, result);
            // calls to Mock to verify that its rules have been followed
            Mock.Assert(_orderDataService);
        }
Exemplo n.º 6
0
        public object PlaceOrder(Guid customerId, ShoppingCart shoppingCart)
        {
            if (shoppingCart.Items.Where(el => el.Quantity == 0).Count() > 0)
            {
                throw new InvalidOrderException();
            }
            var customer = _customerService.GetCustomer(customerId);

            PlaceOrderWithFulfillmentService(shoppingCart, customer);
            var order = new Order();

            return(_orderDataService.Save(order));
        }
Exemplo n.º 7
0
        public Guid PlaceOrder(Guid customerId, ShoppingCart shoppingCart)
        {
            foreach (ShoppingCartItem item in shoppingCart.Items)
            {
                if (item.Quantity == 0)
                {
                    throw new InvalidOrderException();
                }
            }
            var customer = _customerService.GetCustomer(customerId);
            var order    = new Order();

            return(_orderDataService.Save(order));
        }
Exemplo n.º 8
0
        public object PlaceOrder(Guid customerId, ShoppingCart shoppingCart)
        {
            if (shoppingCart.Items.Any(x => x.Quantity == 0))
            {
                return(new BadRequestResult());
            }

            var customer = customerService.GetCustomer(customerId);

            PlaceOrderWithFulfillmentService(shoppingCart, customer);

            var order = new Order();

            return(_orderDataService.Save(order));
        }
Exemplo n.º 9
0
        public object PlaceOrder(Guid customerId, ShoppingCart shoppingCart)
        {
            foreach (var item in shoppingCart.Items)
            {
                if (item.Quantity == 0)
                {
                    throw new InvalidOrderException();
                }
            }

            var customer = _customerService.GetCustomer(customerId);

            PlaceOrderWithFulfillmentService(shoppingCart, customer);

            var order = new Order();

            return(_orderDataService.Save(order));
        }
Exemplo n.º 10
0
 private Guid Save(Order order)
 {
     return(_orderDataService.Save(order));
 }