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.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;
}
}