Пример #1
0
        public void VerifyCalledWithStore()
        {
            //Act
            var products = _service.GetAvailableProducts(_order);

            //Assert
            _repo.Verify(repo => repo.GetAvailableProducts(_store));
        }
Пример #2
0
        public void AddLineItem_AddsLineItem()
        {
            //Arrange
            const int quantity = 1;
            var       product  = _service.GetAvailableProducts(_order).First();

            //Act
            _order.AddLineItem(quantity, product);

            //Assert
            _order.LineItems.Count.ShouldBe(quantity);
            var lineItem = _order.LineItems.Single();

            lineItem.Quantity.ShouldBe(quantity);
            lineItem.Product.ShouldBe(product);
        }
Пример #3
0
        public void FullWalkthrough()
        {
            const decimal price                 = 100.00m;
            const double  customerDiscount      = 0.1;
            const int     startQuantity         = 100;
            const int     purchaseQuantity      = 20;
            const int     expectedFinalQuantity = startQuantity - purchaseQuantity;
            decimal       expectedTotalPrice    = purchaseQuantity * (price - (price * Convert.ToDecimal(customerDiscount)));

            int  storeId;
            Guid membershipNumber;
            int  productId;
            {//Arrange
                var db = _unitOfWork.CreateDbContext <RetailDbContext>();

                var customer = db.CreateCustomer()
                               .With(customer => customer.Discount = customerDiscount);
                var store   = db.CreateStore();
                var product = db.CreateProduct()
                              .With(product => product.Price      = price)
                              .With(product => product.SalesPrice = null)
                              .AddInventory(store, startQuantity);
                db.SaveChanges();
                membershipNumber = customer.MembershipNumber;
                storeId          = store.StoreId;
                productId        = product.ProductId;
            }

            {//Act
                var storeLocator    = new StoreLocatorService(new StoreRepository(_unitOfWork));
                var customerService = new CustomerService(new CustomerRepository(_unitOfWork));
                var orderService    = new OrderCreationService(new OrderRepository(_unitOfWork));

                var store    = storeLocator.GetStoreById(storeId);
                var customer = customerService.GetCustomerByMembershipNumber(membershipNumber);

                var order    = orderService.CreateOrder(customer, store);
                var products = orderService.GetAvailableProducts(order);
                foreach (var product in products)
                {
                    order.AddLineItem(purchaseQuantity, product);
                }

                orderService.SubmitOrder(order);
            }

            {//Assert
                var db = _unitOfWork.CreateDbContext <RetailDbContext>();

                var inventory = db.Inventories
                                .Single(inventory => inventory.ProductId == productId && inventory.StoreId == storeId);
                inventory.Quantity.ShouldBe(expectedFinalQuantity);

                db.Orders
                .Single(order => order.StoreId == storeId)
                .TotalPrice.ShouldBe(expectedTotalPrice);
            }
        }