public void PlaceOrderReturnsOrder()
        {
            var orderRepository     = new Mock <IOrderRepository>(MockBehavior.Strict);
            var orderItemRepository = new Mock <IOrderItemRepository>(MockBehavior.Strict);
            var cartRepository      = new Mock <IShoppingCartRepository>(MockBehavior.Strict);
            var cartItemRepository  = new Mock <IShoppingCartItemRepository>(MockBehavior.Strict);

            var orderService = new ca_service.Services.OrderService(orderRepository.Object, orderItemRepository.Object, cartRepository.Object, cartItemRepository.Object);

            int shoppingCartId = 33, userId = 99, productId = 42;

            OrderPaymentMethod paymentMethod = OrderPaymentMethod.CaliforniaDepartmentofEducation;

            ShoppingCart theCart             = new ShoppingCart(shoppingCartId)
            {
                Items  = new List <ShoppingCartItem>(),
                UserId = userId
            };

            cartRepository.Setup(x => x.Get(shoppingCartId)).Returns(() => theCart);

            ShoppingCartItem theItem = new ShoppingCartItem()
            {
                ShoppingCartId = shoppingCartId,
                ProductId      = productId,
                Quantity       = 1,
                Price          = 25.00m,
            };

            List <ShoppingCartItem> cartItems = new List <ShoppingCartItem>()
            {
                theItem
            };

            cartItemRepository.Setup(x => x.Fetch(shoppingCartId)).Returns(() => cartItems);

            orderRepository.Setup(x => x.Add(It.IsAny <Order>()));

            orderItemRepository.Setup(x => x.Add(It.IsAny <OrderItem>()));

            cartItemRepository.Setup(x => x.Delete(It.IsAny <int>()));

            string address1 = "", address2 = "", address3 = "", city = "", state = "", zip = "", email = "";

            var result = orderService.Create(shoppingCartId, userId, paymentMethod, address1, address2, address3, city, state, zip, email);

            Assert.NotNull(result);

            Assert.Equal(paymentMethod, result.PaymentMethod);

            Assert.Equal(1, result.Items.Count);

            Assert.Equal(productId, result.Items.First().ProductId);

            orderRepository.VerifyAll();
            orderItemRepository.VerifyAll();
            cartRepository.VerifyAll();
            cartItemRepository.VerifyAll();
        }
        public void PlaceOrderThrowsExceptionIfNoShoppingCartOrItems()
        {
            Mock <IOrderRepository>            orderRepository     = new Mock <IOrderRepository>(MockBehavior.Strict);
            Mock <IOrderItemRepository>        orderItemRepository = new Mock <IOrderItemRepository>(MockBehavior.Strict);
            Mock <IShoppingCartRepository>     cartRepository      = new Mock <IShoppingCartRepository>(MockBehavior.Strict);
            Mock <IShoppingCartItemRepository> cartItemRepository  = new Mock <IShoppingCartItemRepository>(MockBehavior.Strict);

            var orderService = new ca_service.Services.OrderService(orderRepository.Object, orderItemRepository.Object, cartRepository.Object, cartItemRepository.Object);

            int shoppingCartId = 33, userId = 99, productId = 42;

            ShoppingCart theCart = null;

            cartRepository.Setup(x => x.Get(shoppingCartId)).Returns(() => theCart);

            string address1 = "", address2 = "", address3 = "", city = "", state = "", zip = "", email = "";

            Assert.Throws <Exception>(() => orderService.Create(shoppingCartId, userId, OrderPaymentMethod.CaliforniaDepartmentofEducation, address1, address2, address3, city, state, zip, email));

            theCart = new ShoppingCart(shoppingCartId)
            {
                Items  = new List <ShoppingCartItem>(),
                UserId = userId
            };

            ShoppingCartItem theItem = new ShoppingCartItem()
            {
                ShoppingCartId = shoppingCartId,
                ProductId      = productId,
                Quantity       = 1,
                Price          = 25.00m,
            };

            List <ShoppingCartItem> cartItems = null;

            cartItemRepository.Setup(x => x.Fetch(shoppingCartId)).Returns(() => cartItems);

            Assert.Throws <Exception>(() => orderService.Create(shoppingCartId, userId, OrderPaymentMethod.CaliforniaDepartmentofEducation, address1, address2, address3, city, state, zip, email));

            orderRepository.VerifyAll();
            orderItemRepository.VerifyAll();
            cartRepository.VerifyAll();
            cartItemRepository.VerifyAll();
        }