public void GetCategoryDiscount() { CategoryDiscount expected = new CategoryDiscount("d1", "MTG_Cards", "T", DateTime.Parse("01/01/2018"), DateTime.Parse("31/12/2018"), 50); var find = handler.GetCategoryDiscount("MTG_Cards", "T"); Assert.AreEqual(expected, find); }
public void CategoryDiscount_ProductDiscountDisabled() { //Arrange Brand brand = new Brand(1, "b1"); Category category = new Category(1, "c1"); Product p1 = new Product("p1", 800, 700, brand, category); Brand brand2 = new Brand(2, "b2"); Category category2 = new Category(2, "c2"); Product p2 = new Product("p2", 400, 250, brand2, category2); User u = new User("user", MemberShipTypeEnum.GOLD); Basket = new Basket(u, DateTime.Now); Basket.AddOrderProduct(new BasketProduct(p1, 1)); Basket.AddOrderProduct(new BasketProduct(p2, 1)); Dictionary <int, Double> categoryDiscounts = new Dictionary <int, double> { { 1, 0.1 }, { 3, 0.15 } }; DiscountBase productDiscountStrategy = new ProductDiscount(false); DiscountBase categoryDiscountStrategy = new CategoryDiscount(categoryDiscounts, productDiscountStrategy); DiscountBase memberShipDiscountStrategy = new BasketDiscountGoldUser(categoryDiscountStrategy); double discountedPrice = Basket.calcDiscountedTotal(memberShipDiscountStrategy); //Act //800+400 =1200 total after product discount //1200 - 80 = 1120 total after category discount //1120 - 112 = 783 total after gold membership discount discountedPrice.Should().Be(1008); }
public void NoCategoryDiscount() { CategoryDiscount nullvalue = null; _handler.Setup(x => x.GetCategoryDiscount("BLA", "WWW")).Returns(nullvalue); _slave.RemoveCategoryDiscount("BLA"); Assert.AreEqual((int)StoreEnum.CategoryDiscountNotExistsInStore, _slave.Answer.Status); }
public void AddCategoryDiscount() { CategoryDiscount expected = new CategoryDiscount("d2", "WanderlandItems", "T", DateTime.Parse("1/1/2018"), DateTime.Parse("31/12/2018"), 50); handler.AddCategoryDiscount(expected); var find = handler.GetCategoryDiscount("WanderlandItems", "T"); Assert.AreEqual(expected, find); }
public void BuildStore() { marketDbMocker = new Mock <IMarketBackUpDB>(); MarketException.SetDB(marketDbMocker.Object); MarketLog.SetDB(marketDbMocker.Object); handler = new Mock <IStoreDL>(); userService = new Mock <IUserSeller>(); slave = new EditCategoryDiscountSlave("WWW", userService.Object, handler.Object); MarketYard.SetDateTime(new DateTime(2018, 4, 14)); category = new Category("C0", "BLA"); handler.Setup(x => x.GetCategoryByName("BLA")).Returns(category); categoryDiscount = new CategoryDiscount("d0", "BLA", "WWW", DateTime.Parse("01/01/2019"), DateTime.Parse("20/01/2019"), 10); handler.Setup(x => x.GetCategoryDiscount("BLA", "WWW")).Returns(categoryDiscount); handler.Setup(x => x.IsStoreExistAndActive("WWW")).Returns(true); }
public static async Task SeedAsync(AppDbContext context) { if (context.Customers.Any()) { return; } var categories = new Category[] { new Category("Produce"), new Category("Dairy") }; var categoriesDiscount = new CategoryDiscount[] { new CategoryDiscount("10% off", 10, categories[0]), new CategoryDiscount("15% off", 15, categories[1]) }; var subCategories = new SubCategory[] { new SubCategory("Fruits", categories[0]), new SubCategory("Veg", categories[0]), new SubCategory("Milk", categories[1]), new SubCategory("Cheese", categories[1]), }; var subCategoriesDiscount = new SubCategoryDiscount[] { new SubCategoryDiscount("18% off", 18, subCategories[0]), new SubCategoryDiscount("5% off", 5, subCategories[1]), new SubCategoryDiscount("20% off", 20, subCategories[2]), new SubCategoryDiscount("20% off", 20, subCategories[3]), }; var products = new Product[] { new Product("Apple", 1, Domain.Enums.EUnitOfMeasurement.Kilogram, 50, "/img/apples.jpg", subCategories[0]), new Product("Orange", 1, Domain.Enums.EUnitOfMeasurement.Kilogram, 80, "/img/orange.jpg", subCategories[0]), new Product("Potato", 1, Domain.Enums.EUnitOfMeasurement.Kilogram, 30, "/img/potato.jpg", subCategories[1]), new Product("Tomato", 1, Domain.Enums.EUnitOfMeasurement.Kilogram, 70, "/img/tomato.jpg", subCategories[1]), new Product("Cow Milk", 1, Domain.Enums.EUnitOfMeasurement.Liter, 50, "/img/cow-milk.jpg", subCategories[2]), new Product("Soy Milk", 1, Domain.Enums.EUnitOfMeasurement.Liter, 40, "/img/soymilk.jpg", subCategories[2]), new Product("Cheddar", 1, Domain.Enums.EUnitOfMeasurement.Kilogram, 50, "/img/cheddar.jpg", subCategories[3]), new Product("Gouda", 1, Domain.Enums.EUnitOfMeasurement.Kilogram, 80, "/img/gouda.png", subCategories[3]), }; var productDiscount = new ProductDiscount[] { new ProductDiscount("3Kg + 1Kg", 3, 1, products[0]), new ProductDiscount("20% off", 20, products[1]), new ProductDiscount("5Kg + 2Kg", 5, 2, products[2]), new ProductDiscount("10% off", 10, products[3]), new ProductDiscount("3Lt + 1Lt", 3, 2, products[4]), new ProductDiscount("10% off", 10, products[5]), new ProductDiscount("2Kg + 1Kg", 2, 1, products[6]), new ProductDiscount("10% off", 10, products[7]) }; var customer = new Customer("Anish Kumar", "*****@*****.**"); await context.Categories.AddRangeAsync(categories); await context.CategoryDiscounts.AddRangeAsync(categoriesDiscount); await context.SubCategories.AddRangeAsync(subCategories); await context.SubCategoryDiscounts.AddRangeAsync(subCategoriesDiscount); await context.Products.AddRangeAsync(products); await context.ProductDiscounts.AddRangeAsync(productDiscount); await context.Customers.AddAsync(customer); await context.SaveChangesAsync(new System.Threading.CancellationToken()); }
public void TestGetDiscountAmount() { var categoryDiscount = new CategoryDiscount(); categoryDiscount.GetDiscountAmount(cartItems).Should().Be(90); }