public void ShouldAddDiscountToDiscounts( DiscountService sut) { IProductDiscount discount = new FakeProductDiscount(); sut.AddProductDiscount(discount); sut.ProductDiscounts.Should().Contain(discount); }
public Product(Guid id, string name, string shortDescription, string description, decimal price, Brand brand, CategoryBase category, string mainImage, FakeProductDiscount fakeProductDiscount) { Id = id; Name = name; MainImage = mainImage; ShortDescription = shortDescription; Description = description; Price = price; IsActive = true; Brand = brand; Category = category; CreationTime = DateTime.Now; Discount = fakeProductDiscount; }
public void ProductsShouldOnlyBeValidForOneDiscount( DiscountService sut) { IProduct product = new ProductFaker().Generate(); Price discountPrice = new Price(product.Price * 0.1m); IProductDiscount discount = new FakeProductDiscount(discountPrice, product); // Adding the same discount twice, to it would apply to the product multiple times, sut.AddProductDiscount(discount); sut.AddProductDiscount(discount); Price result = sut.ApplyDiscounts(new[] { product }); result.Should().Be(new Price(product.Price - discountPrice)); }
public void ShouldApplyDiscountToValidProducts( DiscountService sut) { // product1 is valid for discount, product2 is not. ProductFaker productFaker = new ProductFaker(); IProduct product1 = productFaker.Generate(); IProduct product2 = productFaker.Generate(); Price discountPrice = new Price(product2.Price * 0.5m); IProductDiscount discount = new FakeProductDiscount(discountPrice, product2); sut.AddProductDiscount(discount); Price result = sut.ApplyDiscounts(new[] { product1, product2 }); result.Should().Be(new Price(product1.Price + discountPrice)); }
public void LowestPriceFromAllDiscountsShouldBeApplied( DiscountService sut) { IProduct product = new ProductFaker().Generate(); Price discountPrice1 = new Price(product.Price * 0.1m); IProductDiscount discount1 = new FakeProductDiscount(discountPrice1, product); Price discountPrice2 = new Price(product.Price * 0.2m); IProductDiscount discount2 = new FakeProductDiscount(discountPrice2, product); // discount2 provides more saving that discount1, so that should be applied. sut.AddProductDiscount(discount1); sut.AddProductDiscount(discount2); Price result = sut.ApplyDiscounts(new[] { product }); result.Should().Be(new Price(product.Price - discountPrice2)); }