public async Task DeleteAsync_ById_CallsRepoDeleteOnce() { this.CreateService(); await _service.DeleteAsync(0); _mock.Verify(repo => repo.DeleteAsync(It.IsAny <int>()), Times.Once); }
public async Task DeleteAsyncShouldDeleteProduct() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var repository = new EfDeletableEntityRepository <Product>(dbContext); var productsService = new ProductsService(repository); // Create var product = new Product() { Name = "TestProduct", Description = "none", CategoryId = 3, Category = new Category() { Id = 1, Name = "Test Category " }, ImageUrl = null, ImageStorageName = null, Ratings = null, }; await productsService.CreateAsync(product); // Delete await productsService.DeleteAsync(product.Id); // Get var productsFromDb = dbContext.Products.ToList(); Assert.Equal(0, productsFromDb.Count); }
public async Task DeleteAsync_Calls_Mediator() { //Arrange //Act await _productsService.DeleteAsync(1); //Assert _mockMediator.Verify(x => x.Send(It.IsAny <DeleteProductCommand>(), default(CancellationToken)), Times.Once()); }
public async Task CheckDeletingProductAsync() { ApplicationDbContext db = GetDb(); var repository = new EfDeletableEntityRepository <Product>(db); var service = new ProductsService( repository, this.clientProductLikesRepository.Object, this.cloudinaryService.Object); string productId = await this.PrepareProductAsync(service); await service.DeleteAsync(productId); Assert.Empty(repository.All()); }
public async Task DeleteAsyncShouldDeleteProductSuccessfully() { var productDto = new ProductDto { Id = "1234", Name = "Diablo", Description = "Pizza diavola means the devils pizza and is quite a spicy little devil and one of my favourite pizzas. If you like spicy hot and chilli flavours you will enjoy this pizza.", Price = 8.90m, Weight = 500, Image = "https://images.pizza33.ua/products/product/yQfkJqZweoLn9omo68oz5BnaGzaIE0UJ.jpg" }; await _productsService.CreateAsync(productDto); Assert.Equal(1, _productsRepository.All().Count()); await _productsService.DeleteAsync(productDto.Id); Assert.Equal(0, _productsRepository.All().Count()); }