public void When_Applies_Discount_To_Products_And_There_Are_Discounts_For_This_Products_Then_Returns_Correct_List_Of_Products_With_Discounts()
        {
            // Arrange
            var productCategory = new ProductCategory("", "");

            productCategory.AddProduct(Product);
            Product.SetProductCategory(productCategory);
            var discountCategory = new DiscountCategory(productCategory, ProductCategoryDiscount);

            ProductCategoryDiscount.AddProductCategory(new[] { discountCategory });
            var expected = new List <ApplyDiscountsToProductsResult>
            {
                new ApplyDiscountsToProductsResult(Product, ProductCategoryDiscount)
            };

            // Act
            var result = sut.ApplyDiscountsToProducts(new List <Product> {
                Product
            },
                                                      new List <ProductCategoryDiscount> {
                ProductCategoryDiscount
            });

            // Assert
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(expected);
        }
예제 #2
0
        public async Task DeleteRangeAsync(ProductCategoryDiscount discounts)
        {
            var discountsCategory = await dbContext
                                    .DiscountCategories
                                    .Where(s => s.ProductCategoryDiscount == discounts)
                                    .ToListAsync();

            dbContext.DiscountCategories.RemoveRange(discountsCategory);
        }
        public async Task AddAsync(string name, string nameEng, string description, string descriptionEng, int percentValue,
                                   DateTime availableFrom, DateTime availableTo)
        {
            var discount = new ProductCategoryDiscount(name, nameEng, description, descriptionEng, percentValue,
                                                       availableFrom, availableTo);

            await productCategoryDiscountRepository.AddAsync(discount);

            await productCategoryDiscountRepository.SaveChangesAsync();
        }
예제 #4
0
        public async Task <IList <ProductCategory> > GetCategories(ProductCategoryDiscount discount)
        {
            var categories = await dbContext
                             .DiscountCategories
                             .Where(s => s.ProductCategoryDiscount == discount)
                             .Select(s => s.ProductCategory)
                             .ToListAsync();

            return(categories);
        }
예제 #5
0
        private void CreateProductCategoryDiscount()
        {
            var rnd          = new Random();
            var percentValue = rnd.Next(1, 99);

            ProductCategoryDiscount = new ProductCategoryDiscount(
                Fixture.Create <string>(),
                Fixture.Create <string>(),
                Fixture.Create <string>(),
                Fixture.Create <string>(),
                percentValue,
                DateTime.Now,
                DateTime.Now.AddDays(5)
                );
        }
예제 #6
0
        private (List <Product>, List <ProductCategoryDiscount>) PrepareProductsWithDiscounts()
        {
            var product1 = new Product("Test", "Test", 50, "Test", "Test", true, "", "")
            {
                Id = 1
            };
            var product2 = new Product("Test2", "Test2", 40, "Test2", "Test2", true, "", "")
            {
                Id = 2
            };
            var product3 = new Product("Test3", "Test3", 30, "Test3", "Test3", true, "", "")
            {
                Id = 3
            };
            var product4 = new Product("Test4", "Test3", 30, "Test3", "Test3", true, "", "")
            {
                Id = 4
            };

            var category1 = new ProductCategory("Test1", "Test1");
            var category2 = new ProductCategory("Test2", "Test2");

            product1.SetProductCategory(category1);
            product2.SetProductCategory(category1);
            product3.SetProductCategory(category2);

            var productCategoryDiscount1 = new ProductCategoryDiscount("Test1", "Test1", "Test1", "Test1", 30, DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10));
            var productCategoryDiscount2 = new ProductCategoryDiscount("Test2", "Test2", "Test2", "Test2", 30, DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10));

            var discountCategory1 = new DiscountCategory(category1, productCategoryDiscount1);
            var discountCategory2 = new DiscountCategory(category2, productCategoryDiscount2);

            productCategoryDiscount1.AddProductCategory(new[] { discountCategory1 });
            productCategoryDiscount2.AddProductCategory(new[] { discountCategory2 });

            var products = new List <Product> {
                product1, product2, product3, product4
            };
            var discounts = new List <ProductCategoryDiscount> {
                productCategoryDiscount1, productCategoryDiscount2
            };

            return(products, discounts);
        }
 public ApplyDiscountsToProductsResult(Product product, ProductCategoryDiscount productCategoryDiscount)
 {
     Product = product;
     ProductCategoryDiscount = productCategoryDiscount;
 }
 public ProductWithDiscount(Product product, ProductCategoryDiscount productCategoryDiscount)
 {
     Product = product;
     ProductCategoryDiscount = productCategoryDiscount;
 }