public async Task RemoveFavouriteProductSuccefully() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <ApplicationUserFavouriteProduct>(dbContext); var service = new FavouriteProductService(repository); var favProducts = this.GetFavProducts(UserId); for (int i = 0; i < favProducts.Count(); i++) { await repository.AddAsync(favProducts[i]); } await repository.SaveChangesAsync(); Assert.Equal(4, repository.All().Count()); // before removing await service.RemoveFavouriteProductAsync(1, UserId); Assert.Equal(3, repository.All().Count()); // after removing }
public async Task GetAllFavProductsByUserId(string userId) { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <ApplicationUserFavouriteProduct>(dbContext); var service = new FavouriteProductService(repository); var productRepository = new EfDeletableEntityRepository <Product>(dbContext); var product1 = new Product { CategoryId = 1, Name = "Caffe", ImageUrl = null, Price = 5.5m, }; var product2 = new Product { CategoryId = 2, Name = "Bolognese", ImageUrl = null, Price = 15.5m, }; var product3 = new Product { CategoryId = 3, Name = "Margheritta", ImageUrl = null, Price = 8.5m, }; await productRepository.AddAsync(product1); await productRepository.AddAsync(product2); await productRepository.AddAsync(product3); await productRepository.SaveChangesAsync(); var favProducts = this.GetFavProducts(userId); for (int i = 0; i < favProducts.Count(); i++) { await repository.AddAsync(favProducts[i]); } await repository.SaveChangesAsync(); var favProductsByUserId = service.GetAllFavouriteProducts(userId); Assert.Equal(3, favProductsByUserId.Count()); }
public async Task AddProductToUserSucefully(int productId, string userId) { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <ApplicationUserFavouriteProduct>(dbContext); var service = new FavouriteProductService(repository); await service.AddProductToUserAsync(productId, userId); Assert.Equal(1, repository.All().Count()); }
public async Task IsProductAlreadyAddedSuccesfully() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <ApplicationUserFavouriteProduct>(dbContext); var service = new FavouriteProductService(repository); var favProducts = this.GetFavProducts(UserId); for (int i = 0; i < favProducts.Count(); i++) { await repository.AddAsync(favProducts[i]); } await repository.SaveChangesAsync(); var isAdded = service.IsProductAdded(1, UserId); Assert.True(isAdded); }