public void ShouldCalculateCorrectDiscountPercentage2(double expectedDiscountInPercent, int numberOfOrderCups, CustomerMembership customerMembership)
        {
            var discountInPercent =
                OrderCreationService.CalculateDiscountPercentage(customerMembership, numberOfOrderCups);

            Assert.Equal(expectedDiscountInPercent, discountInPercent);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public void Setup()
        {
            _repo = new Mock <IOrderRepository>();

            _customer = new Customer();
            _store    = new Store();
            _order    = new Order(_customer, _store);

            _service = new OrderCreationService(_repo.Object);
        }
Exemplo n.º 4
0
        public void testInitialize()
        {
            _noOfCupsInStock = 10;
            var orderRepoMock = new Mock <IOrderRepository>();

            orderRepoMock.Setup(x => x.SaveAsync(It.IsAny <Order>())).ReturnsAsync((Order x) => x);
            var coffeeRepoMock = new Mock <ICoffeeCupRepository>();

            coffeeRepoMock.Setup(x => x.GetCoffeeCupsInStockCountAsync()).ReturnsAsync(_noOfCupsInStock);

            _orderCreationService = new OrderCreationService(orderRepoMock.Object, coffeeRepoMock.Object);
        }
        public OrderCreationServiceTest()
        {
            var orderRepositoryMock = new Mock <IOrderRepository>();

            orderRepositoryMock.Setup(x => x.SaveAsync(It.IsAny <Order>())).ReturnsAsync((Order x) => x);
            var coffeCupRepositoryMock = new Mock <ICoffeeCupRepository>();

            _numberOfCupsInStock = 10;
            coffeCupRepositoryMock.Setup(x => x.GetCoffeeCupsInStockCountAsync()).ReturnsAsync(_numberOfCupsInStock);
            coffeCupRepositoryMock.Setup(x => x.GetCoffeeCupsInStockAsync(It.IsAny <int>())).ReturnsAsync(
                (int numberOfOrderedCups) => Enumerable.Range(1, numberOfOrderedCups).Select(p => new CoffeeCup()));

            _orderCreationService = new OrderCreationService(orderRepositoryMock.Object, coffeCupRepositoryMock.Object);
        }