public void CalculateTotals_TotalItemCostIsCalculatedCorrectly(CustomerType customerType, List <Item> items) { var origin = GetAddress(); var destination = GetAddress(street: "12 Main St"); var target = new CheckOutEngine(new ShippingCalculator(origin), _mapper); var cart = CreateCart(customerType, destination, items); var result = target.CalculateTotals(cart); Assert.Equal(GetExpectedTotalCost(items, result.ShippingCost, customerType), result.Total); }
public void CalculateTotals_DiscountBasedOnCustomerType(CustomerType customerType, double expectedDiscount) { var address = CreateAddress(); var target = new CheckOutEngine(new ShippingCalculator(address), _mapper, new CouponEngine()); var cart = new CartBuilder() .WithCustomerType(customerType) .WithShippingAddress(address) .Build(); var result = target.CalculateTotals(cart); Assert.Equal(expectedDiscount, result.CustomerDiscount); }
public void CalculateTotals_PremiumCustomer_TotalEqualsCostPlusShippingMinusDiscount() { var originAddress = CreateAddress(city: "city 1"); var destinationAddress = CreateAddress(city: "city 2"); var target = new CheckOutEngine(new ShippingCalculator(originAddress), _mapper); var cart = new CartBuilder() .WithCustomerType(CustomerType.Premium) .WithShippingAddress(destinationAddress) .WithItems(new List <Item> { CreateItem(price: 2, quantity: 3) }) .Build(); var result = target.CalculateTotals(cart); Assert.Equal((((2 * 3) + result.ShippingCost) * 0.9), result.Total); }
public void CalculateTotals_TestCustomerDiscount(CustomerType customerType, int expectedResult) { var address = GetAddress(); var checkOutEngine = new CheckOutEngine(new ShippingCalculator(address), _mapper); var cart = new Cart { CustomerType = customerType, Items = new() { new Item { ProductId = "1", Price = 1, Quantity = 1 } }, ShippingAddress = address }; var result = checkOutEngine.CalculateTotals(cart); Assert.Equal(expectedResult, result.CustomerDiscount); }
public void CalculateTotals_StandardCustomer_TotalEqualsCostPlusShipping(ShippingMethod shippingMethod) { var originAddress = CreateAddress(city: "city 1"); var destinationAddress = CreateAddress(city: "city 2"); var target = new CheckOutEngine(new ShippingCalculator(originAddress), _mapper); var cart = new CartBuilder() .WithShippingAddress(destinationAddress) .WithShippingMethod(shippingMethod) .WithItems(new List <Item> { CreateItem(price: 2, quantity: 3) }) .Build(); var result = target.CalculateTotals(cart); Assert.Equal((2 * 3) + result.ShippingCost, result.Total); }
public void CalculateTotals_MoreThanOneItem_TotalEqualsCostPlusShipping() { var originAddress = CreateAddress(city: "city 1"); var destinationAddress = CreateAddress(city: "city 2"); var target = new CheckOutEngine(new ShippingCalculator(originAddress), _mapper, new CouponEngine()); var cart = new CartBuilder() .WithShippingAddress(destinationAddress) .WithShippingMethod(ShippingMethod.Standard) .WithItems(new List <Item> { CreateItem(price: 2, quantity: 3), CreateItem(price: 4, quantity: 5) }) .Build(); var result = target.CalculateTotals(cart, null); Assert.Equal((2 * 3) + (4 * 5) + result.ShippingCost, result.Total); }
public void Calculate_Totals(CustomerType customerType, double total, double discount, double shippingCost) { Cart cart = GenerateCart(customerType); 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); }