public void Given_add_an_item_to_basket_Then_should_be_added(string item, string expected) { //Arrange //Act //Assert var listOfProducts = new List <Product>(); listOfProducts.Add( new Product { SKU = 'A', Price = 10 }); listOfProducts.Add( new Product { SKU = 'B', Price = 15 }); listOfProducts.Add( new Product { SKU = 'C', Price = 40 }); listOfProducts.Add( new Product { SKU = 'D', Price = 55 }); var listOfDiscounts = new List <Discount>(); listOfDiscounts.Add( new Discount { SKU = 'B', Quantity = 3, Value = 5 }); listOfDiscounts.Add( new Discount { SKU = 'D', Quantity = 2, Value = 27.5m }); // Mock Allows me to test an isolated Repository Mock <IRepository> mockRepository = new Mock <IRepository>(); mockRepository.Setup(x => x.GetProducts()).Returns(listOfProducts); mockRepository.Setup(x => x.GetDiscounts()).Returns(listOfDiscounts); checkout = new Checkout(mockRepository.Object); //Assert Assert.Equal(expected, checkout.AddtoBasket(item).AddedProducts); }
public void Given_added_multiple_of_2_of_SKU_D_25_percent_off(string items, decimal expected) { //Arrange //Act //Assert var listOfProducts = new List <Product>(); listOfProducts.Add( new Product { SKU = 'A', Price = 10 }); listOfProducts.Add( new Product { SKU = 'B', Price = 15 }); listOfProducts.Add( new Product { SKU = 'C', Price = 40 }); listOfProducts.Add( new Product { SKU = 'D', Price = 55 }); var listOfDiscounts = new List <Discount>(); listOfDiscounts.Add( new Discount { SKU = 'B', Quantity = 3, Value = 5 }); listOfDiscounts.Add( new Discount { SKU = 'D', Quantity = 2, Value = 27.5m }); // Mock Allows me to test an isolated Repository Mock <IRepository> mockRepository = new Mock <IRepository>(); mockRepository.Setup(x => x.GetProducts()).Returns(listOfProducts); mockRepository.Setup(x => x.GetDiscounts()).Returns(listOfDiscounts); checkout = new Checkout(mockRepository.Object); //Assert Assert.Equal(expected, checkout.AddtoBasket(items).Total()); }