Shady nagy/net6 (#614)

* udated to .net6

* used the .net6 version RC2

* added editconfig.

* App core new Scoped Namespaces style.

* BlazorAdmin new Scoped Namespaces style.

* Blazor Shared new Scoped Namespaces style.

* Infra new Scoped Namespaces style.

* public api new Scoped Namespaces style.

* web new Scoped Namespaces style.

* FunctionalTests new Scoped Namespaces style.

* Integrational tests new Scoped Namespaces style.

* unit tests new Scoped Namespaces style.

* update github action.

* update github action.

* change the global.
This commit is contained in:
Shady Nagy
2021-11-06 01:55:48 +02:00
committed by GitHub
parent 64f150dc07
commit 9db2feb930
252 changed files with 6307 additions and 6413 deletions

View File

@@ -1,76 +1,75 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System;
using System;
using System.Linq;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
{
public class BasketAddItem
{
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(_buyerId);
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(_buyerId);
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(_buyerId);
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(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice);
var firstItem = basket.Items.Single();
Assert.Equal(1, firstItem.Quantity);
}
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests;
[Fact]
public void CantAddItemWithNegativeQuantity()
{
var basket = new Basket(_buyerId);
public class BasketAddItem
{
private readonly int _testCatalogItemId = 123;
private readonly decimal _testUnitPrice = 1.23m;
private readonly int _testQuantity = 2;
private readonly string _buyerId = "Test buyerId";
Assert.Throws<ArgumentOutOfRangeException>(() => basket.AddItem(_testCatalogItemId, _testUnitPrice, -1));
}
[Fact]
public void AddsBasketItemIfNotPresent()
{
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity);
[Fact]
public void CantModifyQuantityToNegativeNumber()
{
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice);
var firstItem = basket.Items.Single();
Assert.Equal(_testCatalogItemId, firstItem.CatalogItemId);
Assert.Equal(_testUnitPrice, firstItem.UnitPrice);
Assert.Equal(_testQuantity, firstItem.Quantity);
}
Assert.Throws<ArgumentOutOfRangeException>(() => basket.AddItem(_testCatalogItemId, _testUnitPrice, -2));
}
}
[Fact]
public void IncrementsQuantityOfItemIfPresent()
{
var basket = new Basket(_buyerId);
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(_buyerId);
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(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice);
var firstItem = basket.Items.Single();
Assert.Equal(1, firstItem.Quantity);
}
[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));
}
}

View File

@@ -1,22 +1,21 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests;
public class BasketRemoveEmptyItems
{
public class BasketRemoveEmptyItems
private readonly int _testCatalogItemId = 123;
private readonly decimal _testUnitPrice = 1.23m;
private readonly string _buyerId = "Test buyerId";
[Fact]
public void RemovesEmptyBasketItems()
{
private readonly int _testCatalogItemId = 123;
private readonly decimal _testUnitPrice = 1.23m;
private readonly string _buyerId = "Test buyerId";
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, 0);
basket.RemoveEmptyItems();
[Fact]
public void RemovesEmptyBasketItems()
{
var basket = new Basket(_buyerId);
basket.AddItem(_testCatalogItemId, _testUnitPrice, 0);
basket.RemoveEmptyItems();
Assert.Equal(0, basket.Items.Count);
}
Assert.Equal(0, basket.Items.Count);
}
}

View File

@@ -1,56 +1,55 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System;
using System;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.CatalogItemTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.CatalogItemTests;
public class UpdateDetails
{
public class UpdateDetails
private CatalogItem _testItem;
private int _validTypeId = 1;
private int _validBrandId = 2;
private string _validDescription = "test description";
private string _validName = "test name";
private decimal _validPrice = 1.23m;
private string _validUri = "/123";
public UpdateDetails()
{
private CatalogItem _testItem;
private int _validTypeId = 1;
private int _validBrandId = 2;
private string _validDescription = "test description";
private string _validName = "test name";
private decimal _validPrice = 1.23m;
private string _validUri = "/123";
_testItem = new CatalogItem(_validTypeId, _validBrandId, _validDescription, _validName, _validPrice, _validUri);
}
public UpdateDetails()
{
_testItem = new CatalogItem(_validTypeId, _validBrandId, _validDescription, _validName, _validPrice, _validUri);
}
[Fact]
public void ThrowsArgumentExceptionGivenEmptyName()
{
string newValue = "";
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(newValue, _validDescription, _validPrice));
}
[Fact]
public void ThrowsArgumentExceptionGivenEmptyName()
{
string newValue = "";
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(newValue, _validDescription, _validPrice));
}
[Fact]
public void ThrowsArgumentExceptionGivenEmptyDescription()
{
string newValue = "";
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(_validName, newValue, _validPrice));
}
[Fact]
public void ThrowsArgumentExceptionGivenEmptyDescription()
{
string newValue = "";
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(_validName, newValue, _validPrice));
}
[Fact]
public void ThrowsArgumentNullExceptionGivenNullName()
{
Assert.Throws<ArgumentNullException>(() => _testItem.UpdateDetails(null, _validDescription, _validPrice));
}
[Fact]
public void ThrowsArgumentNullExceptionGivenNullName()
{
Assert.Throws<ArgumentNullException>(() => _testItem.UpdateDetails(null, _validDescription, _validPrice));
}
[Fact]
public void ThrowsArgumentNullExceptionGivenNullDescription()
{
Assert.Throws<ArgumentNullException>(() => _testItem.UpdateDetails(_validName, null, _validPrice));
}
[Fact]
public void ThrowsArgumentNullExceptionGivenNullDescription()
{
Assert.Throws<ArgumentNullException>(() => _testItem.UpdateDetails(_validName, null, _validPrice));
}
[Theory]
[InlineData(0)]
[InlineData(-1.23)]
public void ThrowsArgumentExceptionGivenNonPositivePrice(decimal newPrice)
{
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(_validName, _validDescription, newPrice));
}
[Theory]
[InlineData(0)]
[InlineData(-1.23)]
public void ThrowsArgumentExceptionGivenNonPositivePrice(decimal newPrice)
{
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(_validName, _validDescription, newPrice));
}
}

View File

@@ -1,41 +1,40 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
using System.Collections.Generic;
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
using Microsoft.eShopWeb.UnitTests.Builders;
using System.Collections.Generic;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.OrderTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.OrderTests;
public class OrderTotal
{
public class OrderTotal
private decimal _testUnitPrice = 42m;
[Fact]
public void IsZeroForNewOrder()
{
private decimal _testUnitPrice = 42m;
var order = new OrderBuilder().WithNoItems();
[Fact]
public void IsZeroForNewOrder()
{
var order = new OrderBuilder().WithNoItems();
Assert.Equal(0, order.Total());
}
Assert.Equal(0, order.Total());
}
[Fact]
public void IsCorrectGiven1Item()
{
var builder = new OrderBuilder();
var items = new List<OrderItem>
[Fact]
public void IsCorrectGiven1Item()
{
var builder = new OrderBuilder();
var items = new List<OrderItem>
{
new OrderItem(builder.TestCatalogItemOrdered, _testUnitPrice, 1)
};
var order = new OrderBuilder().WithItems(items);
Assert.Equal(_testUnitPrice, order.Total());
}
var order = new OrderBuilder().WithItems(items);
Assert.Equal(_testUnitPrice, order.Total());
}
[Fact]
public void IsCorrectGiven3Items()
{
var builder = new OrderBuilder();
var order = builder.WithDefaultValues();
[Fact]
public void IsCorrectGiven3Items()
{
var builder = new OrderBuilder();
var order = builder.WithDefaultValues();
Assert.Equal(builder.TestUnitPrice * builder.TestUnits, order.Total());
}
Assert.Equal(builder.TestUnitPrice * builder.TestUnits, order.Total());
}
}

View File

@@ -1,36 +1,35 @@
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions;
public class JsonExtensions
{
public class JsonExtensions
[Fact]
public void CorrectlySerializesAndDeserializesObject()
{
[Fact]
public void CorrectlySerializesAndDeserializesObject()
var testParent = new TestParent
{
var testParent = new TestParent
Id = 7,
Name = "Test name",
Children = new[]
{
Id = 7,
Name = "Test name",
Children = new[]
{
new TestChild(),
new TestChild(),
new TestChild()
}
};
var json = testParent.ToJson();
var result = json.FromJson<TestParent>();
Assert.Equal(testParent, result);
}
[
Theory,
InlineData("{ \"id\": 9, \"name\": \"Another test\" }", 9, "Another test"),
InlineData("{ \"id\": 3124, \"name\": \"Test Value 1\" }", 3124, "Test Value 1"),
]
public void CorrectlyDeserializesJson(string json, int expectedId, string expectedName) =>
Assert.Equal(new TestParent { Id = expectedId, Name = expectedName }, json.FromJson<TestParent>());
};
var json = testParent.ToJson();
var result = json.FromJson<TestParent>();
Assert.Equal(testParent, result);
}
}
[
Theory,
InlineData("{ \"id\": 9, \"name\": \"Another test\" }", 9, "Another test"),
InlineData("{ \"id\": 3124, \"name\": \"Test Value 1\" }", 3124, "Test Value 1"),
]
public void CorrectlyDeserializesJson(string json, int expectedId, string expectedName) =>
Assert.Equal(new TestParent { Id = expectedId, Name = expectedName }, json.FromJson<TestParent>());
}

View File

@@ -2,16 +2,15 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions;
[DebuggerDisplay("Id={Id}, Date={Date}")]
public class TestChild : IEquatable<TestChild>
{
[DebuggerDisplay("Id={Id}, Date={Date}")]
public class TestChild : IEquatable<TestChild>
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid Id { get; set; } = Guid.NewGuid();
public DateTime Date { get; set; } = DateTime.UtcNow;
public DateTime Date { get; set; } = DateTime.UtcNow;
public bool Equals([AllowNull] TestChild other) =>
other?.Date == Date && other?.Id == Id;
}
public bool Equals([AllowNull] TestChild other) =>
other?.Date == Date && other?.Id == Id;
}

View File

@@ -3,19 +3,18 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions;
public class TestParent : IEquatable<TestParent>
{
public class TestParent : IEquatable<TestParent>
{
public int Id { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Name { get; set; }
public IEnumerable<TestChild> Children { get; set; }
public IEnumerable<TestChild> Children { get; set; }
public bool Equals([AllowNull] TestParent other) =>
other?.Id == Id && other?.Name == Name &&
(other?.Children is null && Children is null ||
(other?.Children?.Zip(Children)?.All(t => t.First?.Equals(t.Second) ?? false) ?? false));
}
}
public bool Equals([AllowNull] TestParent other) =>
other?.Id == Id && other?.Name == Name &&
(other?.Children is null && Children is null ||
(other?.Children?.Zip(Children)?.All(t => t.First?.Equals(t.Second) ?? false) ?? false));
}

View File

@@ -1,44 +1,43 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System.Threading.Tasks;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.eShopWeb.ApplicationCore.Services;
using Microsoft.eShopWeb.ApplicationCore.Specifications;
using Moq;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests;
public class AddItemToBasket
{
public class AddItemToBasket
private readonly string _buyerId = "Test buyerId";
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
[Fact]
public async Task InvokesBasketRepositoryGetBySpecAsyncOnce()
{
private readonly string _buyerId = "Test buyerId";
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
var basket = new Basket(_buyerId);
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>());
_mockBasketRepo.Setup(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default)).ReturnsAsync(basket);
[Fact]
public async Task InvokesBasketRepositoryGetBySpecAsyncOnce()
{
var basket = new Basket(_buyerId);
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>());
_mockBasketRepo.Setup(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default)).ReturnsAsync(basket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.AddItemToBasket(basket.BuyerId, 1, 1.50m);
await basketService.AddItemToBasket(basket.BuyerId, 1, 1.50m);
_mockBasketRepo.Verify(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default), Times.Once);
}
_mockBasketRepo.Verify(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default), Times.Once);
}
[Fact]
public async Task InvokesBasketRepositoryUpdateAsyncOnce()
{
var basket = new Basket(_buyerId);
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>());
_mockBasketRepo.Setup(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default)).ReturnsAsync(basket);
[Fact]
public async Task InvokesBasketRepositoryUpdateAsyncOnce()
{
var basket = new Basket(_buyerId);
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>());
_mockBasketRepo.Setup(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default)).ReturnsAsync(basket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.AddItemToBasket(basket.BuyerId, 1, 1.50m);
await basketService.AddItemToBasket(basket.BuyerId, 1, 1.50m);
_mockBasketRepo.Verify(x => x.UpdateAsync(basket, default), Times.Once);
}
_mockBasketRepo.Verify(x => x.UpdateAsync(basket, default), Times.Once);
}
}

View File

@@ -1,30 +1,29 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System.Threading.Tasks;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.eShopWeb.ApplicationCore.Services;
using Moq;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests;
public class DeleteBasket
{
public class DeleteBasket
private readonly string _buyerId = "Test buyerId";
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
[Fact]
public async Task ShouldInvokeBasketRepositoryDeleteAsyncOnce()
{
private readonly string _buyerId = "Test buyerId";
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
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>(), default))
.ReturnsAsync(basket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
[Fact]
public async Task ShouldInvokeBasketRepositoryDeleteAsyncOnce()
{
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>(),default))
.ReturnsAsync(basket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.DeleteBasketAsync(It.IsAny<int>());
await basketService.DeleteBasketAsync(It.IsAny<int>());
_mockBasketRepo.Verify(x => x.DeleteAsync(It.IsAny<Basket>(),default), Times.Once);
}
_mockBasketRepo.Verify(x => x.DeleteAsync(It.IsAny<Basket>(), default), Times.Once);
}
}

View File

@@ -1,35 +1,34 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System;
using System.Threading.Tasks;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Exceptions;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.eShopWeb.ApplicationCore.Services;
using Moq;
using System;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests;
public class SetQuantities
{
public class SetQuantities
private readonly int _invalidId = -1;
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
[Fact]
public async Task ThrowsGivenInvalidBasketId()
{
private readonly int _invalidId = -1;
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
var basketService = new BasketService(_mockBasketRepo.Object, null);
[Fact]
public async Task ThrowsGivenInvalidBasketId()
{
var basketService = new BasketService(_mockBasketRepo.Object, null);
await Assert.ThrowsAsync<BasketNotFoundException>(async () =>
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>()));
}
await Assert.ThrowsAsync<BasketNotFoundException>(async () =>
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>()));
}
[Fact]
public async Task ThrowsGivenNullQuantities()
{
var basketService = new BasketService(null, null);
[Fact]
public async Task ThrowsGivenNullQuantities()
{
var basketService = new BasketService(null, null);
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
await basketService.SetQuantities(123, null));
}
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
await basketService.SetQuantities(123, null));
}
}

View File

@@ -1,97 +1,96 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System;
using System.Threading.Tasks;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.eShopWeb.ApplicationCore.Services;
using Microsoft.eShopWeb.ApplicationCore.Specifications;
using Moq;
using System;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests;
public class TransferBasket
{
public class TransferBasket
private readonly string _nonexistentAnonymousBasketBuyerId = "nonexistent-anonymous-basket-buyer-id";
private readonly string _existentAnonymousBasketBuyerId = "existent-anonymous-basket-buyer-id";
private readonly string _nonexistentUserBasketBuyerId = "newuser@microsoft.com";
private readonly string _existentUserBasketBuyerId = "testuser@microsoft.com";
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
[Fact]
public async Task ThrowsGivenNullAnonymousId()
{
private readonly string _nonexistentAnonymousBasketBuyerId = "nonexistent-anonymous-basket-buyer-id";
private readonly string _existentAnonymousBasketBuyerId = "existent-anonymous-basket-buyer-id";
private readonly string _nonexistentUserBasketBuyerId = "newuser@microsoft.com";
private readonly string _existentUserBasketBuyerId = "testuser@microsoft.com";
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new();
var basketService = new BasketService(null, null);
[Fact]
public async Task ThrowsGivenNullAnonymousId()
{
var basketService = new BasketService(null, null);
await Assert.ThrowsAsync<ArgumentNullException>(async () => await basketService.TransferBasketAsync(null, "steve"));
}
await Assert.ThrowsAsync<ArgumentNullException>(async () => await basketService.TransferBasketAsync(null, "steve"));
}
[Fact]
public async Task ThrowsGivenNullUserId()
{
var basketService = new BasketService(null, null);
[Fact]
public async Task ThrowsGivenNullUserId()
{
var basketService = new BasketService(null, null);
await Assert.ThrowsAsync<ArgumentNullException>(async () => await basketService.TransferBasketAsync("abcdefg", null));
}
await Assert.ThrowsAsync<ArgumentNullException>(async () => await basketService.TransferBasketAsync("abcdefg", null));
}
[Fact]
public async Task InvokesBasketRepositoryFirstOrDefaultAsyncOnceIfAnonymousBasketNotExists()
{
var anonymousBasket = null as Basket;
var userBasket = new Basket(_existentUserBasketBuyerId);
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default), Times.Once);
}
[Fact]
public async Task InvokesBasketRepositoryFirstOrDefaultAsyncOnceIfAnonymousBasketNotExists()
{
var anonymousBasket = null as Basket;
var userBasket = new Basket(_existentUserBasketBuyerId);
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default), Times.Once);
}
[Fact]
public async Task TransferAnonymousBasketItemsWhilePreservingExistingUserBasketItems()
{
var anonymousBasket = new Basket(_existentAnonymousBasketBuyerId);
anonymousBasket.AddItem(1, 10, 1);
anonymousBasket.AddItem(3, 55, 7);
var userBasket = new Basket(_existentUserBasketBuyerId);
userBasket.AddItem(1, 10, 4);
userBasket.AddItem(2, 99, 3);
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.UpdateAsync(userBasket, default), Times.Once);
Assert.Equal(3, userBasket.Items.Count);
Assert.Contains(userBasket.Items, x => x.CatalogItemId == 1 && x.UnitPrice == 10 && x.Quantity == 5);
Assert.Contains(userBasket.Items, x => x.CatalogItemId == 2 && x.UnitPrice == 99 && x.Quantity == 3);
Assert.Contains(userBasket.Items, x => x.CatalogItemId == 3 && x.UnitPrice == 55 && x.Quantity == 7);
}
[Fact]
public async Task TransferAnonymousBasketItemsWhilePreservingExistingUserBasketItems()
{
var anonymousBasket = new Basket(_existentAnonymousBasketBuyerId);
anonymousBasket.AddItem(1, 10, 1);
anonymousBasket.AddItem(3, 55, 7);
var userBasket = new Basket(_existentUserBasketBuyerId);
userBasket.AddItem(1, 10, 4);
userBasket.AddItem(2, 99, 3);
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.UpdateAsync(userBasket, default), Times.Once);
Assert.Equal(3, userBasket.Items.Count);
Assert.Contains(userBasket.Items, x => x.CatalogItemId == 1 && x.UnitPrice == 10 && x.Quantity == 5);
Assert.Contains(userBasket.Items, x => x.CatalogItemId == 2 && x.UnitPrice == 99 && x.Quantity == 3);
Assert.Contains(userBasket.Items, x => x.CatalogItemId == 3 && x.UnitPrice == 55 && x.Quantity == 7);
}
[Fact]
public async Task RemovesAnonymousBasketAfterUpdatingUserBasket()
{
var anonymousBasket = new Basket(_existentAnonymousBasketBuyerId);
var userBasket = new Basket(_existentUserBasketBuyerId);
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.UpdateAsync(userBasket, default), Times.Once);
_mockBasketRepo.Verify(x => x.DeleteAsync(anonymousBasket, default), Times.Once);
}
[Fact]
public async Task RemovesAnonymousBasketAfterUpdatingUserBasket()
{
var anonymousBasket = new Basket(_existentAnonymousBasketBuyerId);
var userBasket = new Basket(_existentUserBasketBuyerId);
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.UpdateAsync(userBasket, default), Times.Once);
_mockBasketRepo.Verify(x => x.DeleteAsync(anonymousBasket, default), Times.Once);
}
[Fact]
public async Task CreatesNewUserBasketIfNotExists()
{
var anonymousBasket = new Basket(_existentAnonymousBasketBuyerId);
var userBasket = null as Basket;
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_existentAnonymousBasketBuyerId, _nonexistentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.AddAsync(It.Is<Basket>(x => x.BuyerId == _nonexistentUserBasketBuyerId), default), Times.Once);
}
[Fact]
public async Task CreatesNewUserBasketIfNotExists()
{
var anonymousBasket = new Basket(_existentAnonymousBasketBuyerId);
var userBasket = null as Basket;
_mockBasketRepo.SetupSequence(x => x.GetBySpecAsync(It.IsAny<BasketWithItemsSpecification>(), default))
.ReturnsAsync(anonymousBasket)
.ReturnsAsync(userBasket);
var basketService = new BasketService(_mockBasketRepo.Object, null);
await basketService.TransferBasketAsync(_existentAnonymousBasketBuyerId, _nonexistentUserBasketBuyerId);
_mockBasketRepo.Verify(x => x.AddAsync(It.Is<Basket>(x => x.BuyerId == _nonexistentUserBasketBuyerId), default), Times.Once);
}
}

View File

@@ -1,76 +1,75 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System.Collections.Generic;
using System.Linq;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Specifications;
using Moq;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications;
public class BasketWithItems
{
public class BasketWithItems
private readonly int _testBasketId = 123;
private readonly string _buyerId = "Test buyerId";
[Fact]
public void MatchesBasketWithGivenBasketId()
{
private readonly int _testBasketId = 123;
private readonly string _buyerId = "Test buyerId";
var spec = new BasketWithItemsSpecification(_testBasketId);
[Fact]
public void MatchesBasketWithGivenBasketId()
{
var spec = new BasketWithItemsSpecification(_testBasketId);
var result = spec.Evaluate(GetTestBasketCollection()).FirstOrDefault();
var result = spec.Evaluate(GetTestBasketCollection()).FirstOrDefault();
Assert.NotNull(result);
Assert.Equal(_testBasketId, result.Id);
}
Assert.NotNull(result);
Assert.Equal(_testBasketId, result.Id);
}
[Fact]
public void MatchesNoBasketsIfBasketIdNotPresent()
{
int badBasketId = -1;
var spec = new BasketWithItemsSpecification(badBasketId);
[Fact]
public void MatchesNoBasketsIfBasketIdNotPresent()
{
int badBasketId = -1;
var spec = new BasketWithItemsSpecification(badBasketId);
var result = spec.Evaluate(GetTestBasketCollection()).Any();
var result = spec.Evaluate(GetTestBasketCollection()).Any();
Assert.False(result);
}
Assert.False(result);
}
[Fact]
public void MatchesBasketWithGivenBuyerId()
{
var spec = new BasketWithItemsSpecification(_buyerId);
[Fact]
public void MatchesBasketWithGivenBuyerId()
{
var spec = new BasketWithItemsSpecification(_buyerId);
var result = spec.Evaluate(GetTestBasketCollection()).FirstOrDefault();
var result = spec.Evaluate(GetTestBasketCollection()).FirstOrDefault();
Assert.NotNull(result);
Assert.Equal(_buyerId, result.BuyerId);
}
Assert.NotNull(result);
Assert.Equal(_buyerId, result.BuyerId);
}
[Fact]
public void MatchesNoBasketsIfBuyerIdNotPresent()
{
string badBuyerId = "badBuyerId";
var spec = new BasketWithItemsSpecification(badBuyerId);
[Fact]
public void MatchesNoBasketsIfBuyerIdNotPresent()
{
string badBuyerId = "badBuyerId";
var spec = new BasketWithItemsSpecification(badBuyerId);
var result = spec.Evaluate(GetTestBasketCollection()).Any();
var result = spec.Evaluate(GetTestBasketCollection()).Any();
Assert.False(result);
}
Assert.False(result);
}
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);
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>()
return new List<Basket>()
{
basket1Mock.Object,
basket2Mock.Object,
basket3Mock.Object
};
}
}
}

View File

@@ -1,48 +1,47 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications;
public class CatalogFilterPaginatedSpecification
{
public class CatalogFilterPaginatedSpecification
[Fact]
public void ReturnsAllCatalogItems()
{
[Fact]
public void ReturnsAllCatalogItems()
{
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogFilterPaginatedSpecification(0, 10, null, null);
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogFilterPaginatedSpecification(0, 10, null, null);
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
Assert.NotNull(result);
Assert.Equal(4, result.ToList().Count);
}
Assert.NotNull(result);
Assert.Equal(4, result.ToList().Count);
}
[Fact]
public void Returns2CatalogItemsWithSameBrandAndTypeId()
{
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogFilterPaginatedSpecification(0, 10, 1, 1);
[Fact]
public void Returns2CatalogItemsWithSameBrandAndTypeId()
{
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogFilterPaginatedSpecification(0, 10, 1, 1);
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
Assert.NotNull(result);
Assert.Equal(2, result.ToList().Count);
}
Assert.NotNull(result);
Assert.Equal(2, result.ToList().Count);
}
private List<CatalogItem> GetTestCollection()
{
var catalogItemList = new List<CatalogItem>();
private List<CatalogItem> GetTestCollection()
{
var catalogItemList = new List<CatalogItem>();
catalogItemList.Add(new CatalogItem(1, 1, "Item 1", "Item 1", 1.00m, "TestUri1"));
catalogItemList.Add(new CatalogItem(1, 1, "Item 1.5", "Item 1.5", 1.50m, "TestUri1"));
catalogItemList.Add(new CatalogItem(2, 2, "Item 2", "Item 2", 2.00m, "TestUri2"));
catalogItemList.Add(new CatalogItem(3, 3, "Item 3", "Item 3", 3.00m, "TestUri3"));
catalogItemList.Add(new CatalogItem(1, 1, "Item 1", "Item 1", 1.00m, "TestUri1"));
catalogItemList.Add(new CatalogItem(1, 1, "Item 1.5", "Item 1.5", 1.50m, "TestUri1"));
catalogItemList.Add(new CatalogItem(2, 2, "Item 2", "Item 2", 2.00m, "TestUri2"));
catalogItemList.Add(new CatalogItem(3, 3, "Item 3", "Item 3", 3.00m, "TestUri3"));
return catalogItemList;
}
return catalogItemList;
}
}

View File

@@ -1,41 +1,40 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications;
public class CatalogFilterSpecification
{
public class CatalogFilterSpecification
[Theory]
[InlineData(null, null, 5)]
[InlineData(1, null, 3)]
[InlineData(2, null, 2)]
[InlineData(null, 1, 2)]
[InlineData(null, 3, 1)]
[InlineData(1, 3, 1)]
[InlineData(2, 3, 0)]
public void MatchesExpectedNumberOfItems(int? brandId, int? typeId, int expectedCount)
{
[Theory]
[InlineData(null, null, 5)]
[InlineData(1, null, 3)]
[InlineData(2, null, 2)]
[InlineData(null, 1, 2)]
[InlineData(null, 3, 1)]
[InlineData(1, 3, 1)]
[InlineData(2, 3, 0)]
public void MatchesExpectedNumberOfItems(int? brandId, int? typeId, int expectedCount)
{
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogFilterSpecification(brandId, typeId);
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogFilterSpecification(brandId, typeId);
var result = GetTestItemCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
var result = GetTestItemCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
Assert.Equal(expectedCount, result.Count());
}
Assert.Equal(expectedCount, result.Count());
}
public List<CatalogItem> GetTestItemCollection()
{
return new List<CatalogItem>()
public List<CatalogItem> GetTestItemCollection()
{
return new List<CatalogItem>()
{
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"),
new CatalogItem(2, 2, "Description", "Name", 0, "FakePath"),
};
}
}
}

View File

@@ -1,55 +1,54 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Moq;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Moq;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications;
public class CatalogItemsSpecification
{
public class CatalogItemsSpecification
[Fact]
public void MatchesSpecificCatalogItem()
{
[Fact]
public void MatchesSpecificCatalogItem()
{
var catalogItemIds = new int[] { 1 };
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogItemsSpecification(catalogItemIds);
var catalogItemIds = new int[] { 1 };
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogItemsSpecification(catalogItemIds);
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
Assert.NotNull(result);
Assert.Single(result.ToList());
}
Assert.NotNull(result);
Assert.Single(result.ToList());
}
[Fact]
public void MatchesAllCatalogItems()
{
var catalogItemIds = new int[] { 1, 3 };
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogItemsSpecification(catalogItemIds);
[Fact]
public void MatchesAllCatalogItems()
{
var catalogItemIds = new int[] { 1, 3 };
var spec = new eShopWeb.ApplicationCore.Specifications.CatalogItemsSpecification(catalogItemIds);
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault());
Assert.NotNull(result);
Assert.Equal(2, result.ToList().Count);
}
Assert.NotNull(result);
Assert.Equal(2, result.ToList().Count);
}
private List<CatalogItem> GetTestCollection()
{
var catalogItems = new List<CatalogItem>();
private List<CatalogItem> GetTestCollection()
{
var catalogItems = new List<CatalogItem>();
var mockCatalogItem1 = new Mock<CatalogItem>(1, 1, "Item 1 description", "Item 1", 1.5m, "Item1Uri");
mockCatalogItem1.SetupGet(x => x.Id).Returns(1);
var mockCatalogItem1 = new Mock<CatalogItem>(1, 1, "Item 1 description", "Item 1", 1.5m, "Item1Uri");
mockCatalogItem1.SetupGet(x => x.Id).Returns(1);
var mockCatalogItem3 = new Mock<CatalogItem>(3, 3, "Item 3 description", "Item 3", 3.5m, "Item3Uri");
mockCatalogItem3.SetupGet(x => x.Id).Returns(3);
var mockCatalogItem3 = new Mock<CatalogItem>(3, 3, "Item 3 description", "Item 3", 3.5m, "Item3Uri");
mockCatalogItem3.SetupGet(x => x.Id).Returns(3);
catalogItems.Add(mockCatalogItem1.Object);
catalogItems.Add(mockCatalogItem3.Object);
catalogItems.Add(mockCatalogItem1.Object);
catalogItems.Add(mockCatalogItem3.Object);
return catalogItems;
}
return catalogItems;
}
}

View File

@@ -1,66 +1,65 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
using Xunit;
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications;
public class CustomerOrdersWithItemsSpecification
{
public class CustomerOrdersWithItemsSpecification
private readonly string _buyerId = "TestBuyerId";
private Address _shipToAddress = new Address("Street", "City", "OH", "US", "11111");
[Fact]
public void ReturnsOrderWithOrderedItem()
{
private readonly string _buyerId = "TestBuyerId";
private Address _shipToAddress = new Address("Street", "City", "OH", "US", "11111");
var spec = new eShopWeb.ApplicationCore.Specifications.CustomerOrdersWithItemsSpecification(_buyerId);
[Fact]
public void ReturnsOrderWithOrderedItem()
{
var spec = new eShopWeb.ApplicationCore.Specifications.CustomerOrdersWithItemsSpecification(_buyerId);
var result = GetTestCollection()
.AsQueryable()
.FirstOrDefault(spec.WhereExpressions.FirstOrDefault());
var result = GetTestCollection()
.AsQueryable()
.FirstOrDefault(spec.WhereExpressions.FirstOrDefault());
Assert.NotNull(result);
Assert.NotNull(result.OrderItems);
Assert.Equal(1, result.OrderItems.Count);
Assert.NotNull(result.OrderItems.FirstOrDefault().ItemOrdered);
}
Assert.NotNull(result);
Assert.NotNull(result.OrderItems);
Assert.Equal(1, result.OrderItems.Count);
Assert.NotNull(result.OrderItems.FirstOrDefault().ItemOrdered);
}
[Fact]
public void ReturnsAllOrderWithAllOrderedItem()
{
var spec = new eShopWeb.ApplicationCore.Specifications.CustomerOrdersWithItemsSpecification(_buyerId);
[Fact]
public void ReturnsAllOrderWithAllOrderedItem()
{
var spec = new eShopWeb.ApplicationCore.Specifications.CustomerOrdersWithItemsSpecification(_buyerId);
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault())
.ToList();
var result = GetTestCollection()
.AsQueryable()
.Where(spec.WhereExpressions.FirstOrDefault())
.ToList();
Assert.NotNull(result);
Assert.Equal(2, result.Count);
Assert.Equal(1, result[0].OrderItems.Count);
Assert.NotNull(result[0].OrderItems.FirstOrDefault().ItemOrdered);
Assert.Equal(2, result[1].OrderItems.Count);
Assert.NotNull(result[1].OrderItems.ToList()[0].ItemOrdered);
Assert.NotNull(result[1].OrderItems.ToList()[1].ItemOrdered);
}
Assert.NotNull(result);
Assert.Equal(2, result.Count);
Assert.Equal(1, result[0].OrderItems.Count);
Assert.NotNull(result[0].OrderItems.FirstOrDefault().ItemOrdered);
Assert.Equal(2, result[1].OrderItems.Count);
Assert.NotNull(result[1].OrderItems.ToList()[0].ItemOrdered);
Assert.NotNull(result[1].OrderItems.ToList()[1].ItemOrdered);
}
public List<Order> GetTestCollection()
{
var ordersList = new List<Order>();
public List<Order> GetTestCollection()
{
var ordersList = new List<Order>();
ordersList.Add(new Order(_buyerId, _shipToAddress,
new List<OrderItem>
{
ordersList.Add(new Order(_buyerId, _shipToAddress,
new List<OrderItem>
{
new OrderItem(new CatalogItemOrdered(1, "Product1", "testurl"), 10.50m, 1)
}));
ordersList.Add(new Order(_buyerId, _shipToAddress,
new List<OrderItem>
{
}));
ordersList.Add(new Order(_buyerId, _shipToAddress,
new List<OrderItem>
{
new OrderItem(new CatalogItemOrdered(2, "Product2", "testurl"), 15.50m, 2),
new OrderItem(new CatalogItemOrdered(2, "Product3", "testurl"), 20.50m, 1)
}));
}));
return ordersList;
}
return ordersList;
}
}