public int NumberOfCustomers() { using (var context = new WheyMenContext()) { return(context.Customer.ToList().Count); } }
public void TestValidQty(int qty) { OrderDAL Repo; LocationDAL LocDal; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { TestSetup(context); Repo = new OrderDAL(context); LocDal = new LocationDAL(context); var orderItem = new OrderItem { Oid = 1, Qty = qty, Pid = 5, }; Assert.IsTrue(orderItem.ValidateQuantity(LocDal.GetQty(5))); } } finally { conn.Close(); } }
public async Task TestCustAdd() { CustomerDAL Repo; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { Repo = new CustomerDAL(context); var custs = await Repo.GetCusts(); int initial_count = custs.ToList().Count; Customer cust1 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; Customer cust2 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; Customer cust3 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; int x = Repo.Add(cust1); int y = Repo.Add(cust2); int z = Repo.Add(cust3); custs = await Repo.GetCusts(); int final_count = custs.ToList().Count; Assert.IsTrue(final_count == (initial_count + 3)); Repo.Remove(x); Repo.Remove(y); Repo.Remove(z); } } finally { conn.Close(); } }
public List <Customer> GetList() { using (var context = new WheyMenContext()) { var listCustomerModel = context.Customer.ToList(); return(listCustomerModel); } }
public void UpdateInventory(int id, int qty) { using (var context = new WheyMenContext()) { var to_update = context.Inventory.Find(id); to_update.Qty -= qty; context.SaveChanges(); } }
//Searches orders by given param, param is checked against Order columns according to mode //Mode Codes: // 1: Get orders by location // 2: By customer // 3: Get details of 1 specific order public List <Order> GetOrders(string search_param, int mode = 0) { var ordersList = new List <Order>(); int id = int.Parse(search_param); using (var context = new WheyMenContext()) { switch (mode) { case 1: ordersList = context.Order .Where(o => o.LocId == id) .Include("OrderItem") .Include("OrderItem.P") .Include("OrderItem.P.P") .Include("Loc") .Include("Cust") .ToList(); break; case 2: ordersList = context.Order .Where(o => o.CustId == id) .Include("OrderItem") .Include("OrderItem.P") .Include("OrderItem.P.P") .Include("Loc") .Include("Cust") .ToList(); break; case 3: ordersList = context.Order .Where(o => o.Id == id) .Include("OrderItem") .Include("OrderItem.P") .Include("OrderItem.P.P") .Include("Loc") .Include("Cust") .ToList(); break; default: ordersList = context.Order.Include("OrderItem") .Include("OrderItem.P") .Include("OrderItem.P.P") .Include("Loc") .Include("Cust") .ToList(); break; } } return(ordersList); }
public List <Loc> GetList() { var listLocationModel = new List <Loc>(); using (var context = new WheyMenContext()) { listLocationModel = context.Loc.ToList(); } return(listLocationModel); }
public async Task TestOrdDeleteEmpty() { OrderDAL Repo; LocationDAL LocDal; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { TestSetup(context); Repo = new OrderDAL(context); LocDal = new LocationDAL(context); var newCust = new Order { CustId = 1, Total = 0, LocId = 1, Timestamp = DateTime.Now }; Repo.Add(newCust); var custs = await Repo.GetOrds(); int initialCount = custs.ToList().Count; var newCust1 = new Order { CustId = 1, Total = 0, LocId = 1, Timestamp = DateTime.Now }; int rem = Repo.Add(newCust1); custs = await Repo.GetOrds(); int current = custs.ToList().Count; Assert.AreEqual(initialCount, initialCount); Repo.Remove(rem); } } finally { conn.Close(); } }
public List <Inventory> GetInventory(int id) { var listInventoryModel = new List <Inventory>(); using (var context = new WheyMenContext()) { listInventoryModel = context.Inventory .Include("P") .Where(i => i.StoreId == id) .ToList(); } return(listInventoryModel); }
public int CreateOrder(int cid, int lid) { using (var context = new WheyMenContext()) { var new_order = new Order { CustId = cid, LocId = lid, Timestamp = DateTime.Now, }; context.Order.Add(new_order); context.SaveChanges(); return(new_order.Id); } }
public void TestOrdTotalUpdate() { OrderDAL Repo; LocationDAL LocDal; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { TestSetup(context); Repo = new OrderDAL(context); LocDal = new LocationDAL(context); var newCust = new Order { CustId = 1, Total = 0, LocId = 1, Timestamp = DateTime.Now }; int addedID = Repo.Add(newCust); var orderItem = new OrderItem { Oid = addedID, Qty = 2, Pid = 5, }; Repo.AddOrderItem(orderItem); var order = Repo.FindByID(addedID); Assert.AreEqual(0, order.Total); Repo.RemoveOrderItem(orderItem); Repo.Remove(addedID); } } finally { conn.Close(); } }
public async Task TestOrdtAdd() { OrderDAL Repo; LocationDAL LocDal; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { TestSetup(context); Debug.WriteLine(context.Customer.ToList().Count); Repo = new OrderDAL(context); LocDal = new LocationDAL(context); var custs = await Repo.GetOrds(); int initial_count = custs.ToList().Count; Order cust1 = new Order { CustId = 1, LocId = 1, Total = 0, Timestamp = DateTime.Now }; int x = Repo.Add(cust1); custs = await Repo.GetOrds(); int final_count = custs.ToList().Count; Assert.AreEqual(final_count, initial_count + 1); Repo.Remove(x); } } finally { conn.Close(); } }
public async Task TestCustDelete() { CustomerDAL Repo; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { Repo = new CustomerDAL(context); var custs = await Repo.GetCusts(); int initialCount = custs.ToList().Count; var newCust = new Customer { Email = "*****@*****.**", Name = "asd", LastName = "dasd", Pwd = "asda", Username = "******" }; int addedID = Repo.Add(newCust); Repo.Remove(addedID); custs = await Repo.GetCusts(); int finalCount = custs.ToList().Count; Assert.AreEqual(initialCount, finalCount); } } finally { conn.Close(); } }
public int AddCust(string fn, string ln, string username, string email, string pwd) { var new_cust = new Customer { Name = fn, Email = email, Username = username, Pwd = pwd, LastName = ln }; using (var context = new WheyMenContext()) { context.Customer.Add(new_cust); context.SaveChanges(); } return(new_cust.Id); }
public void TestSetup(WheyMenContext context) { OrderDAL Repo; LocationDAL LocDal; CustomerDAL CustDal; Repo = new OrderDAL(context); LocDal = new LocationDAL(context); CustDal = new CustomerDAL(context); var cust = new Customer { Id = 1, Name = "jon", LastName = "asd", Email = "*****@*****.**", Username = "******", Pwd = "asd" }; var loc = new Loc { Id = 1, Name = "gnc", }; var prod = new Products { Id = 1, Price = 12, Name = "wpi", }; var inventory = new Inventory { Id = 5, Qty = 10000, Pid = 1, StoreId = 1 }; CustDal.Add(cust); LocDal.Add(loc); context.Products.Add(prod); context.Inventory.Add(inventory); context.SaveChanges(); }
public void TestOrdEdit() { OrderDAL Repo; LocationDAL LocDal; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { TestSetup(context); Repo = new OrderDAL(context); LocDal = new LocationDAL(context); var ord = new Order { CustId = 1, Total = 0, Timestamp = DateTime.Now, LocId = 1 }; int target = Repo.Add(ord); var toEdit = Repo.FindByID(target); toEdit.Total = 0; Repo.Edit(toEdit); var editedCust = Repo.FindByID(target); Assert.AreEqual(0, editedCust.Total); Repo.Remove(target); } } finally { conn.Close(); } }
public void TestCustEdit() { CustomerDAL Repo; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { Repo = new CustomerDAL(context); Customer cust1 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; int target = Repo.Add(cust1); var toEdit = Repo.FindByID(target); toEdit.Name = "Bren"; Repo.Edit(toEdit); var editedCust = Repo.FindByID(target); Assert.AreEqual("Bren", editedCust.Name); editedCust.Name = "Jon"; Repo.Edit(editedCust); } } finally { conn.Close(); } }
//Returns price of added item public Decimal AddOrderItem(int oid, int pid, int qty) { using (var context = new WheyMenContext()) { var order_item = new OrderItem { Oid = oid, Pid = pid, Qty = qty }; context.OrderItem.Add(order_item); context.SaveChanges(); var order = context.OrderItem .Include("P") .Include("P.P") .Where(o => o.Pid == pid && o.Id == order_item.Id) .FirstOrDefault(x => x.Pid == pid); return(order.P.P.Price); } }
public bool CheckUnique(int mode, string check) { using (var context = new WheyMenContext()) { if (mode == 1) { if (context.Customer.Where(c => c.Username == check).ToList().Count == 0) { return(true); } } else if (mode == 2) { if (context.Customer.Where(c => c.Email == check).ToList().Count == 0) { return(true); } } } return(false); }
public void TestSetup() { var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { } } finally { conn.Close(); } }
public BusinessTest(ITestOutputHelper output) { this.output = output; _context = new WheyMenContext(); }