public async Task ProductsWithLessThenOneQuantityDontCountTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); dbContext.Categories.Add(new Category { Id = 1, Description = "Test", Name = "Test1", ImageUrl = "Picture1", Products = new List <Product> { new Product { CategoryId = 1, Quantity = 3, }, new Product { CategoryId = 1, Quantity = 3, }, new Product { CategoryId = 1, Quantity = 0, }, new Product { CategoryId = 1, Quantity = 0, }, }, }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Category>(dbContext); var service = new CategoriesService(repository); var categories = service.AllCategoriesWithTheirePictures(); Assert.Equal(2, categories.Where(a => a.Id == 1).First().ProductsCount); }
public async Task AllCategoriesWithPicturesTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); dbContext.Categories.Add(new Category { Id = 1, Description = "Test", Name = "Test1", ImageUrl = "Picture1", Products = new List <Product> { new Product { CategoryId = 1, Quantity = 3, }, new Product { CategoryId = 1, Quantity = 3, }, new Product { CategoryId = 1, Quantity = 3, }, new Product { CategoryId = 1, Quantity = 3, }, }, }); dbContext.Categories.Add(new Category { Id = 2, Description = "Test2", Name = "Test2", ImageUrl = "Picture2", Products = new List <Product> { new Product { CategoryId = 2, Quantity = 1, }, new Product { CategoryId = 2, Quantity = 1, }, new Product { CategoryId = 2, Quantity = 1, }, }, }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Category>(dbContext); var service = new CategoriesService(repository); var categories = service.AllCategoriesWithTheirePictures(); Assert.NotNull(categories); Assert.Equal(typeof(CategoryByNameAndPicture), categories.First().GetType()); Assert.Equal("Test1", categories.Where(a => a.Id == 1).First().Name); Assert.Equal(4, categories.Where(a => a.Id == 1).First().ProductsCount); Assert.Equal(3, categories.Where(a => a.Id == 2).First().ProductsCount); }