Prevent negative item orders (#392)

* Pulling changes over from previous branch

* Adding exception and guard clause
This commit is contained in:
Eric Fleming
2020-06-12 21:06:23 -04:00
committed by GitHub
parent 0af21d22f5
commit 248b8ed632
10 changed files with 133 additions and 46 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System;
using System.Linq;
using Xunit;
@@ -53,8 +54,8 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
var firstItem = basket.Items.Single();
Assert.Equal(1, firstItem.Quantity);
}
}
[Fact]
public void RemoveEmptyItems()
{
@@ -63,6 +64,23 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
basket.RemoveEmptyItems();
Assert.Equal(0, basket.Items.Count);
}
[Fact]
public void CantAddItemWithNegativeQuantity()
{
var basket = new Basket(_buyerId);
Assert.Throws<ArgumentOutOfRangeException>(() => basket.AddItem(_testCatalogItemId, _testUnitPrice, -1));
}
[Fact]
public void CantModifyQuantityToNegativeNumber()
{
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice);
Assert.Throws<ArgumentOutOfRangeException>(() => basket.AddItem(_testCatalogItemId, _testUnitPrice, -2));
}
}
}