Esempio n. 1
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);
            }
        }
Esempio n. 2
0
 public void Setup()
 {
     _repo    = new StoreRepository();
     _service = new StoreLocatorService(_repo);
 }