Refactoring and Adding Tests (#28)
* Introducing repository and refactoring services. Changing entities to use int keys everywhere. * Refactoring application services to live in web project and only reference repositories, not EF contexts. * Cleaning up implementations * Moving logic out of CatalogController Moving entity knowledge out of viewmodels. * Implementing specification includes better for catalogservice * Cleaning up and adding specification unit tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using ApplicationCore.Specifications;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
public class BasketWithItems
|
||||
{
|
||||
private int _testBasketId = 123;
|
||||
|
||||
[Fact]
|
||||
public void MatchesBasketWithGivenId()
|
||||
{
|
||||
var spec = new BasketWithItemsSpecification(_testBasketId);
|
||||
|
||||
var result = GetTestBasketCollection()
|
||||
.AsQueryable()
|
||||
.FirstOrDefault(spec.Criteria);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(_testBasketId, result.Id);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchesNoBasketsIfIdNotPresent()
|
||||
{
|
||||
int badId = -1;
|
||||
var spec = new BasketWithItemsSpecification(badId);
|
||||
|
||||
Assert.False(GetTestBasketCollection()
|
||||
.AsQueryable()
|
||||
.Any(spec.Criteria));
|
||||
}
|
||||
|
||||
public List<Basket> GetTestBasketCollection()
|
||||
{
|
||||
return new List<Basket>()
|
||||
{
|
||||
new Basket() { Id = 1 },
|
||||
new Basket() { Id = 2 },
|
||||
new Basket() { Id = _testBasketId }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user