public async Task Get_catalog_item_success() { //Arrange var dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: $"{VersionPrefix}{nameof(Get_catalog_item_success)}") .Options; using var dbContext = new CatalogContext(dbOptions); dbContext.AddRange(GetFakeCatalog(2)); dbContext.SaveChanges(); //Act var orderController = new CatalogController(dbContext, mapper); var actionResult = await orderController.ItemByIdAsync(2); //Assert Assert.IsType <ActionResult <ProductDTO> >(actionResult); var result = Assert.IsAssignableFrom <ProductDTO>(actionResult.Value); var dbItem = GetFakeCatalog(2).ElementAt(1); Assert.Equal(dbItem.Name, result.Name); Assert.Equal(dbItem.Description, result.Description); Assert.Equal(dbItem.ImgUri, result.ImgUri); Assert.Equal(dbItem.Price, result.Price); }
public async Task Get_catalog_items_custom_page_success() { //Arrange var dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: $"{VersionPrefix}{nameof(Get_catalog_items_custom_page_success)}") .Options; using var dbContext = new CatalogContext(dbOptions); dbContext.AddRange(GetFakeCatalog(20)); dbContext.SaveChanges(); //Act var orderController = new CatalogController(dbContext, mapper); var actionResult = await orderController.ItemsAsync(5, 1); //Assert Assert.IsType <OkObjectResult>(actionResult); var page = Assert.IsAssignableFrom <PaginatedItems <ProductDTO> >((actionResult as OkObjectResult).Value); Assert.Equal(20, page.Count); Assert.Equal(1, page.PageIndex); Assert.Equal(5, page.PageSize); Assert.Equal(5, page.Data.Count()); }
public CatalogControllerTest() { _dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: "in-memory") .Options; using var dbContext = new CatalogContext(_dbOptions); dbContext.AddRange(GetFakeCatalog()); dbContext.SaveChanges(); }
public CatalogRepositoryTests() { var logger = new Mock <ILogger>(); var builder = new WebHostBuilder() .UseEnvironment("UnitTesting") .UseStartup <Startup>(); var server = new TestServer(builder); _context = server.Host.Services.GetService(typeof(CatalogContext)) as CatalogContext; _repository = new CatalogRepository(_context, logger.Object); _catalogBrands = TestCatalog.CreateBrands(); _catalogTypes = TestCatalog.CreateTypes(); _catalogResponse = TestCatalog.CreateItems(); _context.AddRange(_catalogBrands); _context.AddRange(_catalogTypes); _context.AddRange(_catalogResponse.ItemsOnPage); _context.SaveChanges(); }
public async Task Get_catalog_item_notfound() { //Arrange var dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: $"{VersionPrefix}{nameof(Get_catalog_item_notfound)}") .Options; using var dbContext = new CatalogContext(dbOptions); dbContext.AddRange(GetFakeCatalog(1)); dbContext.SaveChanges(); //Act var orderController = new CatalogController(dbContext, mapper); var actionResult = await orderController.ItemByIdAsync(2); //Assert Assert.IsType <NotFoundResult>(actionResult.Result); }
public async Task Put_catalog_item_description_notfound() { //Arrange var dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: $"{VersionPrefix}{nameof(Put_catalog_item_description_notfound)}") .Options; using var dbContext = new CatalogContext(dbOptions); dbContext.AddRange(GetFakeCatalog(2)); dbContext.SaveChanges(); var newDescription = "Updated description"; //Act var orderController = new CatalogController(dbContext, mapper); var actionResult = await orderController.UpdateProductAsync(3, newDescription); //Assert Assert.IsType <NotFoundObjectResult>(actionResult); }
public async Task Put_catalog_item_description_success() { //Arrange var dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: $"{VersionPrefix}{nameof(Put_catalog_item_description_success)}") .Options; using var dbContext = new CatalogContext(dbOptions); dbContext.AddRange(GetFakeCatalog(2)); dbContext.SaveChanges(); var newDescription = "Updated description"; //Act var orderController = new CatalogController(dbContext, mapper); var actionResult = await orderController.UpdateProductAsync(2, newDescription); //Assert Assert.IsType <NoContentResult>(actionResult); Assert.Equal(newDescription, dbContext.Products.FirstOrDefault(product => product.Id == 2).Description); }
public async Task Get_catalog_items_default_success() { //Arrange var dbOptions = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: $"{VersionPrefix}{nameof(Get_catalog_items_default_success)}") .Options; using var dbContext = new CatalogContext(dbOptions); dbContext.AddRange(GetFakeCatalog(20)); dbContext.SaveChanges(); //Act var orderController = new CatalogController(dbContext, mapper); var actionResult = await orderController.ItemsAsync(); //Assert Assert.IsType <OkObjectResult>(actionResult); var result = Assert.IsAssignableFrom <IEnumerable <ProductDTO> >((actionResult as OkObjectResult).Value); Assert.Equal(20, result.Count()); }
/// <inheritdoc /> public bool SaveAll(IEnumerable <TDomain> domains) { Context.AddRange(domains); return(Context.SaveChanges() > 0); }