public void Repo_Init_Works() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); DefaultAddItemsToContext(context); locationLine_A.Item = product_A; locationLine_B.Item = product_B; location_A.Items.Add(locationLine_A); location_A.Items.Add(locationLine_B); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); repo.Init(); Assert.AreEqual(2, context.Locations.First().Items.Count); } }
public void Multiple_Orders_Saved_In_Customer() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); DefaultAddItemsToContext(context); DefaultInitContext(context); repo.Init(); repo.SubmitOrder(location_A, customer_A); repo.SubmitOrder(location_A, customer_A); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); OrderLogic logic = new OrderLogic(repo, new HttpContextAccessor()); Assert.AreEqual(2, logic.FetchCustomerOrders(1, customer_A).Count()); } }
private static void DefaultInitContext(P1_DbContext context) { locationLine_A.Item = product_A; locationLine_B.Item = product_B; location_A.Items.Add(locationLine_A); location_A.Items.Add(locationLine_B); customer_A.AddToCart(product_A.Id, 3); context.SaveChanges(); }
public void Purchase_Throws_Error_If_No_Product() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); DefaultAddItemsToContext(context); locationLine_A.Item = product_A; customer_A.AddToCart(product_B.Id, 3); context.SaveChanges(); Assert.ThrowsException <Exception>(() => repo.SubmitOrder(location_A, customer_A)); } }
public void Invalid_Login_Returns_Null() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); repo.Register("AAA", "BBB", "CCC", "098890098890"); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); Assert.IsNull(repo.Login("09889009889")); } }
public void Select_Store_Works() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); context.Locations.Add(location_A); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); Assert.AreEqual("Queens", repo.SelectStore(location_A.Id).Address); } }
public void Fetch_Customers_Works() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); repo.Register("AAA", "BBB", "CCC", "098890098890"); repo.Register("AAA", "BBB", "CCC", "098778900987"); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); CustomerLogic logic = new CustomerLogic(repo, new HttpContextAccessor()); Assert.AreEqual(2, logic.FetchCustomers().Count()); } }
public void Select_Product_Works() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); context.Products.Add(product_A); context.Products.Add(product_B); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); Assert.AreEqual("Wrench", repo.SelectProduct(product_A.Id).Name); Assert.AreEqual("Hammer", repo.SelectProduct(product_B.Id).Name); } }
public void Fetch_Locations_Works() { DbContextOptions <P1_DbContext> options = new DbContextOptionsBuilder <P1_DbContext>() .UseInMemoryDatabase(databaseName: "Add_Writes_To_Db").Options; using (P1_DbContext context = new P1_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); P1_Repo repo = new P1_Repo(context); Location a = new Location("Queens"); Location b = new Location("Brooklyn"); context.Locations.Add(a); context.Locations.Add(b); context.SaveChanges(); } using (P1_DbContext context = new P1_DbContext(options)) { P1_Repo repo = new P1_Repo(context); LocationLogic logic = new LocationLogic(repo, new HttpContextAccessor()); Assert.AreEqual(2, logic.FetchLocations().Count()); } }