Refactoring and Adding Tests (#58)

* Moving Identity seeding to its own class and method.

* Adding tests for AddItem

* Added catalog api controller and functional tests
Added and cleaned up some comments

* Adding integration tests for OrderRepository

* Getting integration test for order working with inmemory db
This commit is contained in:
Steve Smith
2017-10-20 12:52:42 -04:00
committed by GitHub
parent 32950aa175
commit 0eb4d72b89
17 changed files with 306 additions and 94 deletions

View File

@@ -0,0 +1,57 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System.Linq;
using Xunit;
namespace UnitTests.ApplicationCore.Entities.BasketTests
{
public class AddItem
{
private int _testCatalogItemId = 123;
private decimal _testUnitPrice = 1.23m;
private int _testQuantity = 2;
[Fact]
public void AddsBasketItemIfNotPresent()
{
var basket = new Basket();
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
var firstItem = basket.Items.Single();
Assert.Equal(_testCatalogItemId, firstItem.CatalogItemId);
Assert.Equal(_testUnitPrice, firstItem.UnitPrice);
Assert.Equal(_testQuantity, firstItem.Quantity);
}
[Fact]
public void IncrementsQuantityOfItemIfPresent()
{
var basket = new Basket();
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
var firstItem = basket.Items.Single();
Assert.Equal(_testQuantity * 2, firstItem.Quantity);
}
[Fact]
public void KeepsOriginalUnitPriceIfMoreItemsAdded()
{
var basket = new Basket();
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
basket.AddItem(_testCatalogItemId, _testUnitPrice * 2, _testQuantity);
var firstItem = basket.Items.Single();
Assert.Equal(_testUnitPrice, firstItem.UnitPrice);
}
[Fact]
public void DefaultsToQuantityOfOne()
{
var basket = new Basket();
basket.AddItem(_testCatalogItemId, _testUnitPrice);
var firstItem = basket.Items.Single();
Assert.Equal(1, firstItem.Quantity);
}
}
}