Feature/respect encapsulation (#349)

* resolve osbsolete method

* put all properties as private, align unit test

* fix version of version in MD, add instruction to install ef tool

* fix url stored
This commit is contained in:
Cédric Michel
2020-02-03 20:47:59 +01:00
committed by GitHub
parent 288d827821
commit 3e228035c0
22 changed files with 162 additions and 99 deletions

View File

@@ -6,14 +6,15 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
{
public class BasketAddItem
{
private int _testCatalogItemId = 123;
private decimal _testUnitPrice = 1.23m;
private int _testQuantity = 2;
private readonly int _testCatalogItemId = 123;
private readonly decimal _testUnitPrice = 1.23m;
private readonly int _testQuantity = 2;
private readonly string _buyerId = "Test buyerId";
[Fact]
public void AddsBasketItemIfNotPresent()
{
var basket = new Basket();
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
var firstItem = basket.Items.Single();
@@ -25,7 +26,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
[Fact]
public void IncrementsQuantityOfItemIfPresent()
{
var basket = new Basket();
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
@@ -36,7 +37,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
[Fact]
public void KeepsOriginalUnitPriceIfMoreItemsAdded()
{
var basket = new Basket();
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
basket.AddItem(_testCatalogItemId, _testUnitPrice * 2, _testQuantity);
@@ -47,7 +48,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
[Fact]
public void DefaultsToQuantityOfOne()
{
var basket = new Basket();
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice);
var firstItem = basket.Items.Single();
@@ -57,7 +58,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
[Fact]
public void RemoveEmptyItems()
{
var basket = new Basket();
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, 0);
basket.RemoveEmptyItems();

View File

@@ -9,7 +9,8 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTes
{
public class DeleteBasket
{
private Mock<IAsyncRepository<Basket>> _mockBasketRepo;
private readonly string _buyerId = "Test buyerId";
private readonly Mock<IAsyncRepository<Basket>> _mockBasketRepo;
public DeleteBasket()
{
@@ -19,7 +20,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTes
[Fact]
public async Task Should_InvokeBasketRepositoryDeleteAsync_Once()
{
var basket = new Basket();
var basket = new Basket(_buyerId);
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>());
basket.AddItem(2, It.IsAny<decimal>(), It.IsAny<int>());
_mockBasketRepo.Setup(x => x.GetByIdAsync(It.IsAny<int>()))

View File

@@ -3,12 +3,14 @@ using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Moq;
namespace Microsoft.eShopWeb.UnitTests
{
public class BasketWithItems
{
private int _testBasketId = 123;
private readonly int _testBasketId = 123;
private readonly string _buyerId = "Test buyerId";
[Fact]
public void MatchesBasketWithGivenId()
@@ -37,11 +39,18 @@ namespace Microsoft.eShopWeb.UnitTests
public List<Basket> GetTestBasketCollection()
{
var basket1Mock = new Mock<Basket>(_buyerId);
basket1Mock.SetupGet(s => s.Id).Returns(1);
var basket2Mock = new Mock<Basket>(_buyerId);
basket2Mock.SetupGet(s => s.Id).Returns(2);
var basket3Mock = new Mock<Basket>(_buyerId);
basket3Mock.SetupGet(s => s.Id).Returns(_testBasketId);
return new List<Basket>()
{
new Basket() { Id = 1 },
new Basket() { Id = 2 },
new Basket() { Id = _testBasketId }
basket1Mock.Object,
basket2Mock.Object,
basket3Mock.Object
};
}
}

View File

@@ -3,6 +3,7 @@ using Microsoft.eShopWeb.ApplicationCore.Entities;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Moq;
namespace Microsoft.eShopWeb.UnitTests
{
@@ -31,11 +32,11 @@ namespace Microsoft.eShopWeb.UnitTests
{
return new List<CatalogItem>()
{
new CatalogItem() { Id = 1, CatalogBrandId = 1, CatalogTypeId= 1 },
new CatalogItem() { Id = 2, CatalogBrandId = 1, CatalogTypeId= 2 },
new CatalogItem() { Id = 3, CatalogBrandId = 1, CatalogTypeId= 3 },
new CatalogItem() { Id = 4, CatalogBrandId = 2, CatalogTypeId= 1 },
new CatalogItem() { Id = 5, CatalogBrandId = 2, CatalogTypeId= 2 },
new CatalogItem(1, 1, "Description", "Name", 0, "FakePath"),
new CatalogItem(2, 1, "Description", "Name", 0, "FakePath"),
new CatalogItem(3, 1, "Description", "Name", 0, "FakePath"),
new CatalogItem(1, 2, "Description", "Name", 0, "FakePath"),
new CatalogItem(2, 2, "Description", "Name", 0, "FakePath"),
};
}
}

View File

@@ -1,11 +1,13 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Moq;
namespace Microsoft.eShopWeb.UnitTests.Builders
{
public class BasketBuilder
{
private Basket _basket;
private Basket _basket;
public string BasketBuyerId => "testbuyerId@test.com";
public int BasketId => 1;
public BasketBuilder()
@@ -20,13 +22,17 @@ namespace Microsoft.eShopWeb.UnitTests.Builders
public Basket WithNoItems()
{
_basket = new Basket { BuyerId = BasketBuyerId, Id = BasketId };
var basketMock = new Mock<Basket>(BasketBuyerId);
basketMock.SetupGet(s => s.Id).Returns(BasketId);
_basket = basketMock.Object;
return _basket;
}
public Basket WithOneBasketItem()
{
_basket = new Basket { BuyerId = BasketBuyerId, Id = BasketId };
var basketMock = new Mock<Basket>(BasketBuyerId);
_basket = basketMock.Object;
_basket.AddItem(2, 3.40m, 4);
return _basket;
}