public async Task DeleteCategoryAsync_IdPresent_RequestedProductDeleted() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <DbCategory> categoryList = new List <DbCategory>() { new DbCategory() { Id = 1, IsDeleted = true }, new DbCategory() { Id = 2 } }; mockProductContext.Setup(c => c.Categories).ReturnsEntitySet(categoryList); mockProductContext.Setup(c => c.Products).ReturnsEntitySet(new List <CatalogueProduct>()); var service = new ProductCategoryService(mockProductContext.Object, mockUserContext.Object); await service.DeleteCategoryAsync(1); var categories = await service.GetCategoriesAsync(0, categoryList.Count); Assert.DoesNotContain(categories, h => h.Id == 1); }
public async Task DeleteProductCategory_Successfuly_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService) { var listEntity = fixture.CreateMany <ProductCategory>(13).ToList(); var idDeleted = listEntity[0].Id; context.Setup(x => x.Categories).ReturnsEntitySet(listEntity); await productCategoryService.SetStatusAsync(listEntity[0].Id, true); await productCategoryService.DeleteCategoryAsync(listEntity[0].Id); var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => productCategoryService.GetCategoryAsync(idDeleted)); Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType()); }
public async Task DeleteCategoryAsync_RequestedResourceNotFoundException( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { var categories = fixture.CreateMany <DbProductCategory>(5).ToList(); var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); categories[0].IsDeleted = true; context.Setup(x => x.Products).ReturnsEntitySet(products); context.Setup(x => x.Categories).ReturnsEntitySet(categories); Func <Task> act = async() => await service.DeleteCategoryAsync(0); act.Should().Throw <RequestedResourceNotFoundException>(); }
public async Task DeleteCategoryAsync_OneElementDelete( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { var categories = fixture.CreateMany <DbProductCategory>(5).ToList(); var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); categories[0].IsDeleted = true; context.Setup(x => x.Products).ReturnsEntitySet(products); context.Setup(x => x.Categories).ReturnsEntitySet(categories); await service.DeleteCategoryAsync(categories[0].Id); var result = await service.GetCategoriesAsync(0, 6); result.Count.Should().Be(4); }
public async Task DeleteCategoryAsync_CategoryId_RequestedResourceHasConflictException( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { // arrange var dbCategory = fixture.CreateMany <DbProductCategory>(1).ToList(); var categoryId = 1; dbCategory[0].Id = categoryId; dbCategory[0].IsDeleted = false; context.Setup(s => s.Categories).ReturnsEntitySet(dbCategory); // assert await Assert.ThrowsAsync <RequestedResourceHasConflictException>( () => service.DeleteCategoryAsync(categoryId)); }
public async Task DeleteCategoryAsync_StatusIsNotDeleted_RequestedResourceHasConflictThrown() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <DbCategory> categoryList = new List <DbCategory>() { new DbCategory() { Id = 1, IsDeleted = false }, new DbCategory() { Id = 2 } }; mockProductContext.Setup(c => c.Categories).ReturnsEntitySet(categoryList); var service = new ProductCategoryService(mockProductContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteCategoryAsync(1)); }
public async Task DeleteCategoryAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <DbCategory> categoryList = new List <DbCategory>() { new DbCategory() { Id = 1 }, new DbCategory() { Id = 2 } }; mockProductContext.Setup(c => c.Categories).ReturnsEntitySet(categoryList); var service = new ProductCategoryService(mockProductContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteCategoryAsync(3)); }