public async Task SetStatusAsync_SetProductStatus(int productId, bool productStatusBefor, bool productStatusAfter) { // arrange var dbProduct = new DbProduct(); dbProduct.Id = productId; dbProduct.IsDeleted = productStatusBefor; Assert.Equal(productStatusBefor, dbProduct.IsDeleted); var dbProducts = new[] { dbProduct }; var context = new Mock <IProductCatalogueContext>(); context.Setup(s => s.Products).ReturnsEntitySet(dbProducts); var userContext = new Mock <IUserContext>(); userContext.Setup(s => s.UserId).Returns(1); var service = new ProductCatalogueService(context.Object, userContext.Object); // act await service.SetStatusAsync(productId, productStatusAfter); // assert Assert.Equal(productStatusAfter, dbProduct.IsDeleted); }
public async Task SetStatusAsync_IdPresent_RequestedProductStatusChanged() { 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 } }; mockUserContext.Setup(c => c.UserId).Returns(1); mockProductContext.Setup(c => c.Products).ReturnsEntitySet(productList); var service = new ProductCatalogueService(mockProductContext.Object, mockUserContext.Object); await service.SetStatusAsync(1, false); var product = await service.GetProductAsync(1); Assert.False(product.IsDeleted); }
public async void SetStatusAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { Configure(context, fixture); var id = 0; await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(id, false)); }
public async void SetStatusAsync_EntityHasFlagIsDeletedFalseSetTrue_SuccsessfulChange([Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { Configure(context, fixture); _product[0].IsDeleted = false; await service.SetStatusAsync(_product[0].Id, true); _product[0].IsDeleted.Should().Be(true); }
public async Task Setstatus_NotFound_Entity_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService, int productCatalogId, bool deletedStatus) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(c => c.Products).ReturnsEntitySet(listEntity); var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => productCatalogueService.SetStatusAsync(productCatalogId, deletedStatus)); Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType()); }
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()); }
public async Task SetStatus_ValidData_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService, bool deletedStatus) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(c => c.Products).ReturnsEntitySet(listEntity); await productCatalogueService.SetStatusAsync(listEntity[0].Id, deletedStatus); var productAfter = await productCatalogueService.GetProductAsync(listEntity[0].Id); Assert.Equal(productAfter.IsDeleted, deletedStatus); }
public async Task SetStatusProductAsync_RequestedResourceNotFoundException( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(products); Func <Task> act = async() => await service.SetStatusAsync(0, true); act.Should().Throw <RequestedResourceNotFoundException>(); }
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 SetStatusAsync_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.SetStatusAsync(3, false)); }