public async Task GetProductAsync_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 ProductCatalogueService(mockProductContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetProductAsync(0)); }
public async Task GetProductAsync_IdPresent_RequestedProductReturned() { 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 ProductCatalogueService(mockProductContext.Object, mockUserContext.Object); var product = await service.GetProductAsync(1); Assert.Equal(1, product.Id); }
public async void GetProductAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { Configure(context, fixture); var id = 0; await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetProductAsync(id)); }
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 GetProductAsync_OneValidEntity_ValidEntityReturns([Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { Configure(context, fixture); var result = await service.GetProductAsync(_product[0].Id); result.Code.Should().Be(_product[0].Code); result.Name.Should().Be(_product[0].Name); }
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 GetProduct_ValidData_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(c => c.Products) .ReturnsEntitySet(listEntity); var foundProduct = await productCatalogueService.GetProductAsync(listEntity[0].Id); Assert.Equal(listEntity[0].Id, foundProduct.Id); }
public async Task GetProductAsync_ById_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.GetProductAsync(0); act.Should().Throw <RequestedResourceNotFoundException>(); }
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 GetProductAsync_ById_ReturnOneElement( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(products); var result = await service.GetProductAsync(products[0].Id); result.Id.Should().Be(products[0].Id); }
public async Task GetProduct_Found_Entity_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(c => c.Products).ReturnsEntitySet(listEntity); var products = await productCatalogueService.GetProductAsync(listEntity[0].Id); Assert.Equal(listEntity[0].Id, products.Id); Assert.Equal(listEntity[0].Code, products.Code); Assert.Equal(listEntity[0].Name, products.Name); Assert.Equal(listEntity[0].IsDeleted, products.IsDeleted); }
public async Task ProductUpdateAsync_UpdateOneItem_ReturnOneItem( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { var products = fixture.CreateMany <CatalogueProduct>(5).ToList(); var updateProduct = fixture.Create <UpdateProductRequest>(); context.Setup(x => x.Products).ReturnsEntitySet(products); var result = await service.UpdateProductAsync(products[0].Id, updateProduct); result.Code.Should().Be(service.GetProductAsync(products[0].Id).Result.Code); }
public async Task GetProductAsync_ProductId_RequestedResourceNotFoundException( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { // arrange var dbProducts = fixture.CreateMany <DbProduct>(3).ToList(); var productId = dbProducts[0].Id + dbProducts[1].Id + dbProducts[2].Id; context.Setup(s => s.Products).ReturnsEntitySet(dbProducts); // assert await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetProductAsync(productId)); }
public async Task UpdateProduct_UpdateSuccessfuly_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(x => x.Products).ReturnsEntitySet(listEntity); var createRequest = fixture.Create <UpdateProductRequest>(); var addedProduct = await productCatalogueService.UpdateProductAsync(listEntity[0].Id, createRequest); var product = await productCatalogueService.GetProductAsync(addedProduct.Id); Assert.Equal(product.Name, createRequest.Name); Assert.Equal(product.ManufacturerCode, createRequest.ManufacturerCode); Assert.Equal(product.Code, createRequest.Code); Assert.Equal(product.Description, createRequest.Description); }
public async Task GetProductAsync_ProductId_Product( [Frozen] Mock <IProductCatalogueContext> context, ProductCatalogueService service, IFixture fixture) { // arrange var dbProducts = fixture.CreateMany <DbProduct>(5).ToList(); var productId = dbProducts[2].Id; context.Setup(s => s.Products).ReturnsEntitySet(dbProducts); // act var product = await service.GetProductAsync(productId); // assert Assert.Equal(dbProducts[2].Code, product.Code); }
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 GetProduct_NotFound_Entity_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService, int productCatalogId) { var listEntity = fixture.CreateMany <CatalogueProduct>(13).ToList(); context.Setup(c => c.Products).ReturnsEntitySet(listEntity); var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => productCatalogueService.GetProductAsync(productCatalogId)); Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType()); }