private BatmansInventoryContext GetPopulatedInMemoryDbContext() { var options = new DbContextOptionsBuilder <BatmansInventoryContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new BatmansInventoryContext(options); PhysicalItem fakePhysicalItemSameLocation1 = new PhysicalItem() { PhysicalItemId = 1, InventoryItemId = 1, SerialNumber = "A001", LocationId = 1, Value = 9.99m, Created = DateTime.Now, CreatedBy = "Lucius" }; PhysicalItem fakePhysicalItemSameLocation2 = new PhysicalItem() { PhysicalItemId = 2, InventoryItemId = 1, SerialNumber = "A002", LocationId = 1, Value = 9.99m, Created = DateTime.Now, CreatedBy = "Lucius" }; PhysicalItem fakePhysicalItemDifferentLocation = new PhysicalItem() { PhysicalItemId = 3, InventoryItemId = 2, SerialNumber = "B001", LocationId = 3, Value = 19.99m, Created = DateTime.Now, CreatedBy = "Lucius" }; context.Add(fakePhysicalItemSameLocation1); context.Add(fakePhysicalItemSameLocation2); context.Add(fakePhysicalItemDifferentLocation); context.SaveChanges(); return(context); }
private BatmansInventoryContext GetPopulatedInMemoryDbContext() { // Naming in-memory db by GUID so every test ran is a new db so it's not affected by previous runs var options = new DbContextOptionsBuilder <BatmansInventoryContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new BatmansInventoryContext(options); InventoryItem fakeInventoryItem = new InventoryItem() { InventoryItemId = 1, PartName = "Bat Test", PartNumber = "BTE-747", OrderLeadTime = 6, QuantityOnHand = 4, SafetyStock = 5, Created = DateTime.Now, CreatedBy = "Tester", }; InventoryItem fakeInventoryItemToRetrieve = new InventoryItem() { InventoryItemId = 2, PartName = "BataTest", PartNumber = "BTE-321", OrderLeadTime = 6, QuantityOnHand = 5, SafetyStock = 10, Created = DateTime.Now, CreatedBy = "Alfred" }; InventoryItem fakeInventoryItemUnderSafetyStock1 = new InventoryItem() { InventoryItemId = 3, PartName = "BataTest", PartNumber = "BTE-321", OrderLeadTime = 6, QuantityOnHand = 5, SafetyStock = 10, Created = DateTime.Now, CreatedBy = "Alfred" }; InventoryItem fakeInventoryItemUnderSafetyStock2 = new InventoryItem() { InventoryItemId = 4, PartName = "BataTest1", PartNumber = "BTE-123", OrderLeadTime = 4, QuantityOnHand = 2, SafetyStock = 5, Created = DateTime.Now, CreatedBy = "Alfred" }; InventoryItem fakeInventoryItemNotUnderSafetyStock = new InventoryItem() { InventoryItemId = 5, PartName = "Not Safe", PartNumber = "SAF-321", OrderLeadTime = 6, QuantityOnHand = 12, SafetyStock = 7, Created = DateTime.Now, CreatedBy = "Alfred" }; context.Add(fakeInventoryItem); context.Add(fakeInventoryItemToRetrieve); context.Add(fakeInventoryItemUnderSafetyStock1); context.Add(fakeInventoryItemUnderSafetyStock2); context.Add(fakeInventoryItemNotUnderSafetyStock); context.SaveChanges(); return(context); }