public void TestGetCustomer() { //Arrange var options = new DbContextOptionsBuilder <BitsAndBobsContext>() .UseInMemoryDatabase(databaseName: "Test2DB") .Options; //Act Customer testCustomer; using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); testCustomer = new Customer { CustFirstName = "Annie", CustLastName = "Admin", CustUsername = "******" }; _unitOfWork.Customers.Add(testCustomer); _unitOfWork.Complete(); } //Assert using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); Assert.Equal(testCustomer.CustUsername, _unitOfWork.Customers.Get(1).CustUsername); } }
public void TestUsernameAvailableFalse() { //Arrange var options = new DbContextOptionsBuilder <BitsAndBobsContext>() .UseInMemoryDatabase(databaseName: "Test5DB") .Options; //Act using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); var testCustomer = new Customer { CustFirstName = "Annie", CustLastName = "Admin", CustUsername = "******" }; _unitOfWork.Customers.Add(testCustomer); _unitOfWork.Complete(); } //Assert using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); Assert.False(_unitOfWork.Customers.IsAvailable("AAdmin")); } }
public void TestSaveMultipleChanges() { //Arrange var options = new DbContextOptionsBuilder <BitsAndBobsContext>() .UseInMemoryDatabase(databaseName: "Test18DB") .Options; //Act using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); var testCustomer = new Customer { CustFirstName = "Annie", CustLastName = "Admin", CustUsername = "******" }; var testCustomer2 = new Customer { CustFirstName = "Bonnie", CustLastName = "Boss", CustUsername = "******" }; var testCustomer3 = new Customer { CustFirstName = "Charlie", CustLastName = "Champion", CustUsername = "******" }; _unitOfWork.Customers.Add(testCustomer); _unitOfWork.Customers.Add(testCustomer2); _unitOfWork.Customers.Add(testCustomer3); _unitOfWork.Complete(); } //Assert using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); Assert.Equal(3, _unitOfWork.Customers.GetAll().Count()); } }
public OrderLineItemRepository(BitsAndBobsContext context) : base(context) { }
public CustomerRepository(BitsAndBobsContext context) : base(context) { }
public InventoryRepository(BitsAndBobsContext context) : base(context) { }
public void TestGetAllLocations() { //Arrange var options = new DbContextOptionsBuilder <BitsAndBobsContext>() .UseInMemoryDatabase(databaseName: "Test16DB") .Options; //Act using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); var testCustomer = new Customer { CustFirstName = "Annie", CustLastName = "Admin", CustUsername = "******" }; var testProduct1 = new Product { ProductName = "Apple", ProductPrice = 1 }; var testProduct2 = new Product { ProductName = "Banana", ProductPrice = 1 }; var testLocation = new Location { LocationCity = "Springfield" }; var testLocation2 = new Location { LocationCity = "Peoria" }; var testInventory1 = new Inventory { InventoryLocation = testLocation, InventoryProduct = testProduct1, QuantityAvailable = 5 }; var testInventory2 = new Inventory { InventoryLocation = testLocation, InventoryProduct = testProduct2, QuantityAvailable = 5 }; var testOrderLineItem = new OrderLineItem { LineItemProduct = testProduct1, LinePrice = 2, Quantity = 2 }; var testOrder = new Order { OrderCustomer = testCustomer, OrderDate = DateTime.Now, OrderLineItems = new List <OrderLineItem> { testOrderLineItem }, OrderLocation = testLocation }; context.Add(testCustomer); context.Add(testProduct1); context.Add(testProduct2); context.Add(testLocation); context.Add(testLocation2); context.Add(testInventory1); context.Add(testInventory2); context.SaveChanges(); _unitOfWork.Orders.Add(testOrder); _unitOfWork.Complete(); } //Assert using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); Assert.Equal(2, _unitOfWork.Locations.GetAll().Count()); } }
public void TestReduceMultipleStock() { //Arrange var options = new DbContextOptionsBuilder <BitsAndBobsContext>() .UseInMemoryDatabase(databaseName: "Test10DB") .Options; //Act using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); var testProduct1 = new Product { ProductName = "Apple", ProductPrice = 1 }; var testProduct2 = new Product { ProductName = "Banana", ProductPrice = 1 }; var testLocation = new Location { LocationCity = "Springfield" }; var testInventory1 = new Inventory { InventoryLocation = testLocation, InventoryProduct = testProduct1, QuantityAvailable = 5 }; var testInventory2 = new Inventory { InventoryLocation = testLocation, InventoryProduct = testProduct2, QuantityAvailable = 5 }; context.Add(testProduct1); context.Add(testProduct2); context.Add(testLocation); context.Add(testInventory1); context.Add(testInventory2); context.SaveChanges(); } //Assert using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); _unitOfWork.Inventories.ReduceStock(1, 1); _unitOfWork.Inventories.ReduceStock(2, 3); Assert.Equal(4, _unitOfWork.Inventories.GetLocationInventory(1).Where(id => id.InventoryID == 1).FirstOrDefault().QuantityAvailable); Assert.Equal(2, _unitOfWork.Inventories.GetLocationInventory(1).Where(id => id.InventoryID == 2).FirstOrDefault().QuantityAvailable); } }
public void TestGetLocationInventory() { //Arrange var options = new DbContextOptionsBuilder <BitsAndBobsContext>() .UseInMemoryDatabase(databaseName: "Test8DB") .Options; //Act using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); var testProduct1 = new Product { ProductName = "Apple", ProductPrice = 1 }; var testProduct2 = new Product { ProductName = "Banana", ProductPrice = 1 }; var testLocation = new Location { LocationCity = "Springfield" }; var testInventory1 = new Inventory { InventoryLocation = testLocation, InventoryProduct = testProduct1, QuantityAvailable = 5 }; var testInventory2 = new Inventory { InventoryLocation = testLocation, InventoryProduct = testProduct2, QuantityAvailable = 5 }; context.Add(testProduct1); context.Add(testProduct2); context.Add(testLocation); context.Add(testInventory1); context.Add(testInventory2); context.SaveChanges(); } //Assert using (var context = new BitsAndBobsContext(options)) { var _unitOfWork = new UnitOfWork(context); Assert.Equal(2, _unitOfWork.Inventories.GetLocationInventory(1).Count()); } }