public async void candeleteoneshoppingcartitem() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("deleteshoppingcartitem").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { ShoppingCartItem si = new ShoppingCartItem(); si.ID = 1; si.ProdQty = 10; ShoppingCartItem st = new ShoppingCartItem(); st.ID = 2; st.ProdQty = 4; ShoppingCartItemManagementService Service = new ShoppingCartItemManagementService(context); await Service.CreateShoppingCartItem(si); await Service.CreateShoppingCartItem(st); await Service.DeleteShoppingCartItem(2); var expect = await context.ShoppingCartTable.FirstOrDefaultAsync(c => c.ID == 2); Assert.Null(await context.ShoppingCartTable.FirstOrDefaultAsync(c => c.ID == 2)); } }
public PickedProduct(ICart cart, IShoppingCartItem shoppingCartItem, UserManager <ApplicationUser> userManager, CreaturesDbcontext context) { _context = context; _cart = cart; _userManager = userManager; _shoppingCartItem = shoppingCartItem; }
public async void TestGetAllOrdereItems() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("GetAllOrderedItems").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { OrderedItems testOrderedItem6 = new OrderedItems(); testOrderedItem6.ID = 1; testOrderedItem6.OrderID = 1; OrderedItems testOrderedItem7 = new OrderedItems(); testOrderedItem7.ID = 2; testOrderedItem7.OrderID = 1; OrderedItemsManagementService orderedItemsService = new OrderedItemsManagementService(context); await orderedItemsService.CreateOrderedItem(testOrderedItem6); await orderedItemsService.CreateOrderedItem(testOrderedItem7); var orderedItems2Answer = await orderedItemsService.GetAllOrderedItems(1); Assert.Equal(2, orderedItems2Answer.Count); } }
public async void TestCreateOrder() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); var r = await context.Products.FirstOrDefaultAsync(c => c.ID == p.ID); Assert.Equal(p, r); } }
public async void cancreateshoppingcartitem() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateShoppingcartItems").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { ShoppingCartItem si = new ShoppingCartItem(); si.ID = 1; ShoppingCartItemManagementService Service = new ShoppingCartItemManagementService(context); await Service.CreateShoppingCartItem(si); var expect = await context.ShoppingCartTable.FirstOrDefaultAsync(c => c.ID == si.ID); Assert.Equal(expect, si); } }
public async void TestCreateOrdereItems() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateOrderedItems").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { OrderedItems testOrderedItem5 = new OrderedItems(); testOrderedItem5.ID = 1; testOrderedItem5.OrderID = 1; OrderedItemsManagementService orderedItemsService = new OrderedItemsManagementService(context); await orderedItemsService.CreateOrderedItem(testOrderedItem5); var orderedItems1Answer = context.OrderedItemsTable.FirstOrDefault(c => c.ID == testOrderedItem5.ID); Assert.Equal(testOrderedItem5, orderedItems1Answer); } }
public async void TestReadCart() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("ReadCart").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Cart testCart4 = new Cart(); testCart4.ID = 1; testCart4.UserID = "aUserID"; CartManagementService cartService = new CartManagementService(context); await cartService.Create(testCart4); var cart2Answer = await cartService.GetCart("aUserID"); Assert.Equal(testCart4, cart2Answer); } }
public async void TestCreateCart() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateCart").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Cart testCart3 = new Cart(); testCart3.ID = 1; testCart3.UserID = "aUserID"; CartManagementService cartService = new CartManagementService(context); await cartService.Create(testCart3); var cart1Answer = context.Carts.FirstOrDefault(c => c.ID == testCart3.ID); Assert.Equal(testCart3, cart1Answer); } }
public async void TestGetOrder() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("GetOrder").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Order testOrder6 = new Order(); testOrder6.ID = 1; testOrder6.UserID = "aUserID"; testOrder6.Totalprice = 300; OrderManagementService orderService = new OrderManagementService(context); await orderService.CreateOrder(testOrder6); var order2Answer = await orderService.GetOrder("aUserID"); Assert.Equal(testOrder6, order2Answer[0]); } }
public async void TestupdateProduct() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("updateProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; p.Name = "unicorn"; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); p.Name = "test"; await Service.UpdateProduct(p); var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1); Assert.Equal("test", expect.Name); } }
public async void TestCreateOrder() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateOrder").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Order testOrder5 = new Order(); testOrder5.ID = 1; testOrder5.UserID = "aUserID"; testOrder5.Totalprice = 30; OrderManagementService orderService = new OrderManagementService(context); await orderService.CreateOrder(testOrder5); var order1Answer = context.OrderTable.FirstOrDefault(c => c.ID == testOrder5.ID); Assert.Equal(testOrder5, order1Answer); } }
public async void canuodatequantity() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("updatequantity").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { ShoppingCartItem si = new ShoppingCartItem(); si.ID = 1; si.ProdQty = 10; ShoppingCartItemManagementService Service = new ShoppingCartItemManagementService(context); await Service.CreateShoppingCartItem(si); var res = Service.UpdateShoppingCartItem(1, 7); var expect = await context.ShoppingCartTable.FirstOrDefaultAsync(c => c.ID == si.ID); Assert.Equal(7, expect.ProdQty); } }
public async void TestGetallProducts() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("GetProducts").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; Product pp = new Product(); pp.ID = 2; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); await Service.Create(pp); var res = await Service.GetAllProducts(); Assert.Equal(2, res.Count); } }
public async void TestdeleteProduct() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("DeleteProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; Product pp = new Product(); pp.ID = 2; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); await Service.Create(pp); await Service.DeleteProduct(1); var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1); Assert.Null(expect); } }
public async void TestGetOneShoppingCartItems() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("GetOneShoppingcartItem").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { ShoppingCartItem si = new ShoppingCartItem(); si.ID = 1; si.CartID = 1; ShoppingCartItem st = new ShoppingCartItem(); st.ID = 2; st.CartID = 1; ShoppingCartItemManagementService Service = new ShoppingCartItemManagementService(context); await Service.CreateShoppingCartItem(si); await Service.CreateShoppingCartItem(st); var res = await Service.GetShoppingCartItem(1); Assert.Equal(1, res.ID); } }
/// <summary> /// CartManagementService Constructor by taking in the CreaturesDbcontext /// </summary> /// <param name="context">the database</param> public CartManagementService(CreaturesDbcontext context) { _context = context; }
/// <summary> /// OrderedItemsManagementService constructor by bringing in the creatureDbContext /// </summary> /// <param name="context">the database</param> public OrderedItemsManagementService(CreaturesDbcontext context) { _context = context; }
/// <summary> /// ProductManagementService constructor bring in the creaturesDbcontext /// </summary> /// <param name="context">the database</param> public ProductManagementService(CreaturesDbcontext context) { _context = context; }
/// <summary> /// access to other tables /// </summary> /// <param name="userManager">identity table</param> /// <param name="order">order table</param> public OrderController(UserManager <ApplicationUser> userManager, IOrder order, CreaturesDbcontext context) { _userManager = userManager; _order = order; _context = context; }
/// <summary> /// constructor for shoppingcartitemmanagementservice and bring in the creaturesDbcontext /// </summary> /// <param name="context">database</param> public ShoppingCartItemManagementService(CreaturesDbcontext context) { _context = context; }