public void Creates_A_Cart()
        {
            var cartBuilder            = new CartBuilder();
            var address                = Builders.Utility.AddressGenerate();
            var shoppingCartRepository = new ShoppingCartRepository(_shoppingCartDatabaseSettings);
            var cartOne                = cartBuilder.GenerateCart(address, CustomerType.Premium, ShippingMethod.Expedited);
            var cartTwo                = cartBuilder.GenerateCart(address, CustomerType.Premium, ShippingMethod.Express);
            var cartThree              = cartBuilder.GenerateCart(address, CustomerType.Premium, ShippingMethod.Priority);

            shoppingCartRepository.Create(cartOne);
            shoppingCartRepository.Create(cartTwo);
            shoppingCartRepository.Create(cartThree);

            var result = shoppingCartRepository.FindAll();

            result.Should().HaveCount(3);
        }
        public void Finds_A_New_Cart()
        {
            var cartBuilder            = new CartBuilder();
            var address                = Builders.Utility.AddressGenerate();
            var shoppingCartRepository = new ShoppingCartRepository(_shoppingCartDatabaseSettings);
            var cart       = cartBuilder.GenerateCart(address, CustomerType.Premium, ShippingMethod.Expedited);
            var storedCart = shoppingCartRepository.Create(cart);

            var result = shoppingCartRepository.FindById(storedCart.Id);

            result.Should().BeEquivalentTo(cart);
        }
예제 #3
0
        public void Calculate_Totals(CustomerType customerType, double total, double discount, double shippingCost)
        {
            Address     address            = Utility.AddressGenerate();
            CartBuilder cartBuilder        = new CartBuilder();
            Cart        cart               = cartBuilder.GenerateCart(address, customerType, ShippingMethod.Expedited);
            var         shippingCalculator = Substitute.For <IShippingCalculator>();

            shippingCalculator.CalculateShippingCost(cart).Returns(10);
            var config = new MapperConfiguration(cfg => {
                cfg.AddProfile <MappingProfile>();
            });
            var mapper = config.CreateMapper();

            var sut = new CheckOutEngine(shippingCalculator, mapper);

            var result = sut.CalculateTotals(cart);

            result.Total.Should().Be(total);
            result.CustomerDiscount.Should().Be(discount);
            result.ShippingCost.Should().Be(shippingCost);
            result.ShoppingCart.Items.Should().NotContainNulls();
            result.ShoppingCart.CustomerType.Should().Be(customerType);
            result.ShoppingCart.ShippingMethod.Should().Be(ShippingMethod.Expedited);
        }