public void TestProductNotFoundById() { var option = new DbContextOptionsBuilder <ApidbContext>() .UseInMemoryDatabase(databaseName: "webAPIdb") .Options; // Run the test against one instance of the context var context = new ApidbContext(option); var service = new WebApiProductController(context); service.Seed(context); var Testresult = context.ProductItems.FindAsync(100); Assert.IsNull(Testresult.Result); }
public void TestDeleteProductById() { var option = new DbContextOptionsBuilder <ApidbContext>() .UseInMemoryDatabase(databaseName: "webAPIdb") .Options; // Run the test against one instance of the context var context = new ApidbContext(option); var service = new WebApiProductController(context); service.Seed(context); var isDeleted = service.DeleteProductById(5); Product getData = service.GetProductbyId(5); Assert.IsNull(getData); }
public void TestGetProductbyId() { var option = new DbContextOptionsBuilder <ApidbContext>() .UseInMemoryDatabase(databaseName: "webAPIdb") .Options; // Run the test against one instance of the context var context = new ApidbContext(option); var service = new WebApiProductController(context); service.Seed(context); var Testresult = context.ProductItems.FindAsync(6); var getData = service.GetProductbyId(6); Assert.AreEqual(Testresult.Result.Name, getData.Name); }
public void TestPageNotFoundOnPage() { var option = new DbContextOptionsBuilder <ApidbContext>() .UseInMemoryDatabase(databaseName: "webAPIdb") .Options; // Run the test against one instance of the context var context = new ApidbContext(option); var service = new WebApiProductController(context); service.Seed(context); var pageData = service.GetPageList(10, 5); var model = JsonConvert.DeserializeObject <ProductPage>(pageData); var productItems = model.Product_Items; Assert.AreEqual(productItems.Count, 0); }
public void TestUpdateProductById() { var option = new DbContextOptionsBuilder <ApidbContext>() .UseInMemoryDatabase(databaseName: "webAPIdb") .Options; // Run the test against one instance of the context var context = new ApidbContext(option); var service = new WebApiProductController(context); service.Seed(context); Product prod = new Product(); prod.Id = 2; prod.Name = "UpdatedProduct"; prod.Description = "Description"; service.UpdateProduct(2, prod); var getUpdatedProduct = service.GetProductbyId(2); Assert.AreEqual(getUpdatedProduct.Name, "UpdatedProduct"); }
public ApiController(ApidbContext context) { _context = context; if (_context.CustomerList.Count() == 0) { _context.CustomerList.Add(new CustomerModel { Name = "Customer 1", saleIdList = "" }); _context.CustomerList.Add(new CustomerModel { Name = "Customer 2", saleIdList = "" }); _context.CustomerList.Add(new CustomerModel { Name = "Customer 3", saleIdList = "" }); _context.CustomerList.Add(new CustomerModel { Name = "Customer 4", saleIdList = "" }); _context.CustomerList.Add(new CustomerModel { Name = "Customer 5", saleIdList = "" }); _context.SaveChanges(); } if (_context.SalesList.Count() == 0) { // Create a new SalesList if collection is empty _context.SalesList.Add(new SalesRepModel { FirstName = "Sale Rep1", LastName = "Sales1", custIdList = "" }); _context.SalesList.Add(new SalesRepModel { FirstName = "Sale Rep2", LastName = "Sales2", custIdList = "" }); _context.SalesList.Add(new SalesRepModel { FirstName = "Sale Rep3", LastName = "Sales3", custIdList = "" }); _context.SalesList.Add(new SalesRepModel { FirstName = "Sale Rep4", LastName = "Sale4", custIdList = "" }); _context.SaveChanges(); } }
public void Seed(ApidbContext _context) { if (_context.ProductItems.Count() == 0) { _context.ProductItems.Add(new Model.Product { Id = 1, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 2, Name = "Orange Juice", Description = "Juice made of fresh Oranges" }); _context.ProductItems.Add(new Model.Product { Id = 3, Name = "Grape Juice", Description = "Juice made of fresh Grape" }); _context.ProductItems.Add(new Model.Product { Id = 4, Name = "Banana Juice", Description = "Juice made of fresh Banana" }); _context.ProductItems.Add(new Model.Product { Id = 5, Name = "Lemom Juice", Description = "Juice made of fresh Lemom" }); _context.ProductItems.Add(new Model.Product { Id = 6, Name = "Pineapple Juice", Description = "Juice made of fresh Pineapple" }); _context.ProductItems.Add(new Model.Product { Id = 7, Name = "Tea", Description = "Hot Masala Tea" }); _context.ProductItems.Add(new Model.Product { Id = 8, Name = "Coffee", Description = "Hot coffee with original coffee beans" }); _context.ProductItems.Add(new Model.Product { Id = 9, Name = "Cold Coffee", Description = "Icy cold coffee" }); _context.ProductItems.Add(new Model.Product { Id = 10, Name = "Coffee latte", Description = "Hot coffee Latte" }); _context.ProductItems.Add(new Model.Product { Id = 11, Name = "Ice cream", Description = "Chocolate Ice cream" }); _context.ProductItems.Add(new Model.Product { Id = 12, Name = "Chips", Description = "Cream and Onion Chips" }); _context.ProductItems.Add(new Model.Product { Id = 13, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 14, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 15, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 16, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 17, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 18, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.ProductItems.Add(new Model.Product { Id = 19, Name = "Apple Juice", Description = "Juice made of fresh apple" }); _context.SaveChanges(); } }
public WebApiProductController(ApidbContext context) { _context = context; Seed(_context); }