public async Task DeleteProductAsync_IdPresent_RequestedProductDeleted() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <CatalogueProduct> productList = new List <CatalogueProduct>() { new CatalogueProduct() { Id = 1, IsDeleted = true }, new CatalogueProduct() { Id = 2 } }; mockProductContext.Setup(c => c.Products).ReturnsEntitySet(productList); var service = new ProductCatalogueService(mockProductContext.Object, mockUserContext.Object); await service.DeleteProductAsync(1); var products = await service.GetProductsAsync(0, productList.Count); Assert.DoesNotContain(products, h => h.Id == 1); }
public async void DeleteProductAsync_ExistedIdentifierFlagIsDeletedFalse_CustomExceptionThrows([Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { Configure(context, fixture); var id = _product[0].Id; _product[0].IsDeleted = false; await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteProductAsync(id)); }
public async void DeleteAsync_ExistedIdentifierFlagIsDeletedTrue_SuccessfulDeleting([Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { Configure(context, fixture); var id = _product[0].Id; _product[0].IsDeleted = true; await service.DeleteProductAsync(id); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetProductAsync(id)); }
public async Task DeleteProduct_Successfuly_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(listEntity); ; await productCatalogueService.SetStatusAsync(listEntity[0].Id, true); await productCatalogueService.DeleteProductAsync(listEntity[0].Id); var products = await productCatalogueService.GetProductsAsync(0, 12); Assert.Equal(12, products.Count); }
public async Task SetStatusProductAsync_SetDeleteStatus( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(products); await service.SetStatusAsync(products[0].Id, true); Func <Task> act = async() => await service.DeleteProductAsync(products[0].Id); act.Should().NotThrow(); }
public async Task DeleteProductAsync_RequestedResourceHasConflictException( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); products[0].IsDeleted = false; context.Setup(x => x.Products).ReturnsEntitySet(products); Func <Task> act = async() => await service.DeleteProductAsync(products[0].Id); act.Should().Throw <RequestedResourceHasConflictException>(); }
public async Task DeleteProductAsync_DeleteOneElement( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); products[0].IsDeleted = true; var id = products[0].Id; context.Setup(x => x.Products).ReturnsEntitySet(products); await service.DeleteProductAsync(id); Func <Task> act = async() => await service.GetProductAsync(id); act.Should().Throw <RequestedResourceNotFoundException>(); }
public async Task DeleteProductAsync_ProductId_RequestedResourceHasConflictException( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { // arrange var productId = 1; var dbProducts = fixture.CreateMany <DbProduct>(3).ToList(); dbProducts[0].Id = productId + 1; dbProducts[1].Id = productId; dbProducts[1].IsDeleted = false; dbProducts[2].Id = productId + 1; context.Setup(s => s.Products).ReturnsEntitySet(dbProducts); // assert await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteProductAsync(productId)); }
public async Task DeleteProductAsync_StatusIsNotDeleted_RequestedResourceHasConflictThrown() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <CatalogueProduct> productList = new List <CatalogueProduct>() { new CatalogueProduct() { Id = 1, IsDeleted = false }, new CatalogueProduct() { Id = 2 } }; mockProductContext.Setup(c => c.Products).ReturnsEntitySet(productList); var service = new ProductCatalogueService(mockProductContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteProductAsync(1)); }
public async Task DeleteProductAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <CatalogueProduct> productList = new List <CatalogueProduct>() { new CatalogueProduct() { Id = 1 }, new CatalogueProduct() { Id = 2 } }; mockProductContext.Setup(c => c.Products).ReturnsEntitySet(productList); var service = new ProductCatalogueService(mockProductContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteProductAsync(3)); }
public async Task DeleteProduct_ConflictException_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(listEntity); await productCatalogueService.SetStatusAsync(listEntity[0].Id, false); var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => productCatalogueService.DeleteProductAsync(listEntity[0].Id)); Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType()); }