public void Should_throw_a_NotEnoughStockException_when_the_specified_amount_of_items_to_remove_is_greater_than_QuantityInStock() { // Arrange using var arrangeContext = new ProductContext(_builder.Options); using var actContext = new ProductContext(_builder.Options); using var assertContext = new ProductContext(_builder.Options); arrangeContext.Products.Add(new() { Name = "Product 1", QuantityInStock = 10 }); arrangeContext.SaveChanges(); var sut = new StockService(actContext); // Act & Assert var stockException = Assert.Throws <NotEnoughStockException>( () => sut.RemoveStock(1, 11) ); Assert.Equal(10, stockException.QuantityInStock); Assert.Equal(11, stockException.AmountToRemove); }
public void Should_remove_the_specified_amount_to_QuantityInStock() { // Arrange using var arrangeContext = new ProductContext(_builder.Options); using var actContext = new ProductContext(_builder.Options); using var assertContext = new ProductContext(_builder.Options); arrangeContext.Products.Add(new() { Name = "Product 1", QuantityInStock = 10 }); arrangeContext.SaveChanges(); var sut = new StockService(actContext); // Act var quantityInStock = sut.RemoveStock(1, 5); // Assert Assert.Equal(5, quantityInStock); var actual = assertContext.Products.Find(1); Assert.Equal(5, actual.QuantityInStock); }