예제 #1
0
        public void UpdateInventoryLineItemShouldUpdateLineItem()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <IceShopContext>().UseInMemoryDatabase("UpdateInventoryLineItemShouldUpdateLineItem").Options;

            using var testContext = new IceShopContext(options);
            // add sample data to testContext
            testContext.InventoryLineItems.AddRange(SampleData.GetSampleInventoryLineItems());
            // This data needs to be added so that navigation properties of the Inventory Line Items aren't null.
            testContext.Locations.AddRange(SampleData.GetSampleLocations());
            testContext.Products.AddRange(SampleData.GetSampleProducts());
            testContext.SaveChanges();

            repo = new DBRepo(testContext);

            //Act
            // get a location that has an InventoryLineItem
            int sampleLocationId             = repo.GetAllLocations().First().Id;
            InventoryLineItem sampleLineItem = repo.GetAllInventoryLineItemsAtLocation(sampleLocationId).FindLast(ili => ili.LocationId == sampleLocationId);
            int startingQuantity             = sampleLineItem.ProductQuantity;

            sampleLineItem.ProductQuantity += 1;


            repo.UpdateInventoryLineItem(sampleLineItem);
            repo.SaveChanges();

            //Assert
            //using var assertContext = new IceShopContext(options);
            Assert.NotEqual(startingQuantity, sampleLineItem.ProductQuantity);
        }
예제 #2
0
 public void SaveChanges()
 {
     context.SaveChanges();
 }