public async Task GetCategoryAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <CatalogueProduct> productList = new List <CatalogueProduct>() { new CatalogueProduct() { Id = 1, CategoryId = 1 }, new CatalogueProduct() { Id = 2, CategoryId = 2 } }; List <DbCategory> categoryList = new List <DbCategory>() { new DbCategory() { Id = 1 }, new DbCategory() { Id = 2 } }; mockProductContext.Setup(c => c.Products).ReturnsEntitySet(productList); mockProductContext.Setup(c => c.Categories).ReturnsEntitySet(categoryList); var service = new ProductCategoryService(mockProductContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetCategoryAsync(0)); }
public async Task GetCategoryAsync_IdPresent_RequestedCategoryReturned() { var mockUserContext = new Mock <IUserContext>(); var mockProductContext = new Mock <IProductCatalogueContext>(); List <CatalogueProduct> productList = new List <CatalogueProduct>() { new CatalogueProduct() { Id = 1, CategoryId = 1 }, new CatalogueProduct() { Id = 2, CategoryId = 2 } }; List <DbCategory> categoryList = new List <DbCategory>() { new DbCategory() { Id = 1 }, new DbCategory() { Id = 2 } }; mockProductContext.Setup(c => c.Products).ReturnsEntitySet(productList); mockProductContext.Setup(c => c.Categories).ReturnsEntitySet(categoryList); var service = new ProductCategoryService(mockProductContext.Object, mockUserContext.Object); var category = await service.GetCategoryAsync(1); Assert.Equal(1, category.Id); }
public async Task SetStatusAsync_IdPresent_RequestedProductStatusChanged() { 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); mockUserContext.Setup(c => c.UserId).Returns(1); var service = new ProductCategoryService(mockProductContext.Object, mockUserContext.Object); await service.SetStatusAsync(1, false); var product = await service.GetCategoryAsync(1); Assert.False(product.IsDeleted); }
public async Task GetProductCategory_ValidData_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService) { var listEntity = fixture.CreateMany <ProductCategory>(13).ToList(); context.Setup(c => c.Categories) .ReturnsEntitySet(listEntity); var foundHive = await productCategoryService.GetCategoryAsync(listEntity[0].Id); Assert.Equal(listEntity[0].Id, foundHive.Id); }
public async Task SetStatus_ValidData_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService, bool deletedStatus) { var listEntity = fixture.CreateMany <ProductCategory>(13).ToList(); context.Setup(c => c.Categories).ReturnsEntitySet(listEntity); await productCategoryService.SetStatusAsync(listEntity[0].Id, deletedStatus); var categoryAfter = await productCategoryService.GetCategoryAsync(listEntity[0].Id); Assert.Equal(categoryAfter.IsDeleted, deletedStatus); }
public async Task GetProductCategory_Found_Entity_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService) { var listEntity = fixture.CreateMany <ProductCategory>(13).ToList(); context.Setup(c => c.Categories).ReturnsEntitySet(listEntity); var category = await productCategoryService.GetCategoryAsync(listEntity[0].Id); Assert.Equal(listEntity[0].Id, category.Id); Assert.Equal(listEntity[0].Code, category.Code); Assert.Equal(listEntity[0].Name, category.Name); Assert.Equal(listEntity[0].IsDeleted, category.IsDeleted); }
public async Task CreateProductCategory_AddedSuccessfuly_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService) { var listEntity = fixture.CreateMany <ProductCategory>(13).ToList(); context.Setup(x => x.Categories).ReturnsEntitySet(listEntity); var createRequest = fixture.Create <UpdateProductCategoryRequest>(); var addedCategory = await productCategoryService.CreateCategoryAsync(createRequest); var category = await productCategoryService.GetCategoryAsync(addedCategory.Id); Assert.Equal(category.Name, createRequest.Name); Assert.Equal(category.Description, createRequest.Description); Assert.Equal(category.Code, createRequest.Code); }
public async Task GetCategoryAsync_CreqteFiveElement_ReturnOneFiveElement( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { var categories = fixture.CreateMany <DbProductCategory>(5).ToList(); var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(products); context.Setup(x => x.Categories).ReturnsEntitySet(categories); var result = await service.GetCategoryAsync(categories[0].Id); result.Id.Should().Be(categories[0].Id); }
public async Task GetCategoryAsync_RequestedResourceNotFoundException( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { var categories = fixture.CreateMany <DbProductCategory>(5).ToList(); var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(products); context.Setup(x => x.Categories).ReturnsEntitySet(categories); Func <Task> act = async() => await service.GetCategoryAsync(0); act.Should().Throw <RequestedResourceNotFoundException>(); }
public async Task GetCategoryAsync_CategoryId_RequestedResourceNotFoundException( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { // arrange var dbCategories = fixture.CreateMany <DbProductCategory>(3).ToList(); var categoryId = dbCategories[0].Id + dbCategories[1].Id + dbCategories[2].Id; context.Setup(s => s.Categories).ReturnsEntitySet(dbCategories); // assert await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetCategoryAsync(categoryId)); }
public async Task SetStatusAsync_SetTrueStatus( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { var categories = fixture.CreateMany <DbProductCategory>(5).ToList(); var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(products); context.Setup(x => x.Categories).ReturnsEntitySet(categories); await service.SetStatusAsync(categories[0].Id, true); var result = await service.GetCategoryAsync(categories[0].Id); result.IsDeleted.Should().BeTrue(); }
public async Task GetCategoryAsync_CategoryId_ProductCategoryInstance( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { // arrange var dbCategories = fixture.CreateMany <DbProductCategory>(5).ToList(); var categoryId = dbCategories[3].Id; context.Setup(s => s.Categories).ReturnsEntitySet(dbCategories); // act var category = await service.GetCategoryAsync(categoryId); // assert Assert.NotNull(category); Assert.Equal(categoryId, category.Id); }
public async Task UpdateCategoryAsync_UpdateOneElement( [Frozen] Mock <IProductCatalogueContext> context, ProductCategoryService service, IFixture fixture) { var categories = fixture.CreateMany <DbProductCategory>(5).ToList(); var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); var updateCategory = fixture.Create <UpdateProductCategoryRequest>(); context.Setup(x => x.Products).ReturnsEntitySet(products); context.Setup(x => x.Categories).ReturnsEntitySet(categories); await service.UpdateCategoryAsync(categories[0].Id, updateCategory); var result = await service.GetCategoryAsync(categories[0].Id); result.Code.Should().Be(updateCategory.Code); //Func<Task> act = async () => await service.CreateCategoryAsync(updateCategory); //act.Should().Throw<RequestedResourceHasConflictException>(); }
public async Task DeleteCategoryAsync_CategoryId_Success( [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 = true; context.Setup(s => s.Categories).ReturnsEntitySet(dbCategory); // act await service.DeleteCategoryAsync(categoryId); // assert await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetCategoryAsync(categoryId)); }
public async Task GetProductCategory_NotFound_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService, int productCategoeyId) { var listEntity = fixture.CreateMany <ProductCategory>(0).ToList(); context.Setup(c => c.Categories).ReturnsEntitySet(listEntity); var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => productCategoryService.GetCategoryAsync(productCategoeyId)); Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType()); }
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()); }