From 70a919e145864032ceef2ceb6aa82210a0527773 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Mon, 8 Jun 2020 13:31:22 -0400 Subject: [PATCH] Switching to NuGet Ardalis.Specifications (#389) - updating to use Ardalis.Specifications package as it is maintained and has a more robust implementation - Removing all custom specification implementation - Updating unit tests --- src/ApplicationCore/ApplicationCore.csproj | 1 + .../Helpers/Query/IncludeAggregator.cs | 26 -------- .../Helpers/Query/IncludeQuery.cs | 19 ------ .../Helpers/Query/IncludeQueryExtensions.cs | 66 ------------------- .../Helpers/Query/IncludeVisitor.cs | 16 ----- .../Interfaces/IAsyncRepository.cs | 3 +- .../Interfaces/IIncludeQuery.cs | 16 ----- .../Interfaces/ISpecification.cs | 20 ------ .../Specifications/BaseSpecification.cs | 63 ------------------ .../BasketWithItemsSpecification.cs | 9 ++- .../CatalogFilterPaginatedSpecification.cs | 3 +- .../CatalogFilterSpecification.cs | 3 +- .../CatalogItemsSpecification.cs | 3 +- .../CustomerOrdersWithItemsSpecification.cs | 8 ++- src/Infrastructure/Data/EfRepository.cs | 19 ++++-- src/Infrastructure/Data/OrderRepository.cs | 1 + .../Data/SpecificationEvaluator.cs | 52 --------------- src/Infrastructure/Infrastructure.csproj | 1 + src/Web/Web.csproj | 1 + .../Query/IncludeAggregatorTests/Include.cs | 2 +- .../Query/IncludeQueryTests/Include.cs | 2 +- .../Query/IncludeQueryTests/ThenInclude.cs | 2 +- .../Query/IncludeVisitorTests/Visit.cs | 2 +- .../BasketWithItemsSpecification.cs | 4 +- .../CatalogFilterSpecificationFilter.cs | 3 +- .../UnitTests/Builders/IncludeQueryBuilder.cs | 4 +- .../OrdersTests/GetMyOrders_Should.cs | 3 +- .../OrdersTests/GetOrderDetails_Should.cs | 3 +- 28 files changed, 45 insertions(+), 310 deletions(-) delete mode 100644 src/ApplicationCore/Helpers/Query/IncludeAggregator.cs delete mode 100644 src/ApplicationCore/Helpers/Query/IncludeQuery.cs delete mode 100644 src/ApplicationCore/Helpers/Query/IncludeQueryExtensions.cs delete mode 100644 src/ApplicationCore/Helpers/Query/IncludeVisitor.cs delete mode 100644 src/ApplicationCore/Interfaces/IIncludeQuery.cs delete mode 100644 src/ApplicationCore/Interfaces/ISpecification.cs delete mode 100644 src/ApplicationCore/Specifications/BaseSpecification.cs delete mode 100644 src/Infrastructure/Data/SpecificationEvaluator.cs diff --git a/src/ApplicationCore/ApplicationCore.csproj b/src/ApplicationCore/ApplicationCore.csproj index 28e1b47..a35c71f 100644 --- a/src/ApplicationCore/ApplicationCore.csproj +++ b/src/ApplicationCore/ApplicationCore.csproj @@ -7,6 +7,7 @@ + diff --git a/src/ApplicationCore/Helpers/Query/IncludeAggregator.cs b/src/ApplicationCore/Helpers/Query/IncludeAggregator.cs deleted file mode 100644 index fe3c26b..0000000 --- a/src/ApplicationCore/Helpers/Query/IncludeAggregator.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace Microsoft.eShopWeb.ApplicationCore.Helpers.Query -{ - public class IncludeAggregator - { - public IncludeQuery Include(Expression> selector) - { - var visitor = new IncludeVisitor(); - visitor.Visit(selector); - - var pathMap = new Dictionary(); - var query = new IncludeQuery(pathMap); - - if (!string.IsNullOrEmpty(visitor.Path)) - { - pathMap[query] = visitor.Path; - } - - return query; - } - } -} diff --git a/src/ApplicationCore/Helpers/Query/IncludeQuery.cs b/src/ApplicationCore/Helpers/Query/IncludeQuery.cs deleted file mode 100644 index e8c9c9d..0000000 --- a/src/ApplicationCore/Helpers/Query/IncludeQuery.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.eShopWeb.ApplicationCore.Helpers.Query -{ - public class IncludeQuery : IIncludeQuery - { - public Dictionary PathMap { get; } = new Dictionary(); - public IncludeVisitor Visitor { get; } = new IncludeVisitor(); - - public IncludeQuery(Dictionary pathMap) - { - PathMap = pathMap; - } - - public HashSet Paths => PathMap.Select(x => x.Value).ToHashSet(); - } -} diff --git a/src/ApplicationCore/Helpers/Query/IncludeQueryExtensions.cs b/src/ApplicationCore/Helpers/Query/IncludeQueryExtensions.cs deleted file mode 100644 index 60c154a..0000000 --- a/src/ApplicationCore/Helpers/Query/IncludeQueryExtensions.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace Microsoft.eShopWeb.ApplicationCore.Helpers.Query -{ - public static class IncludeQueryExtensions - { - public static IIncludeQuery Include( - this IIncludeQuery query, - Expression> selector) - { - query.Visitor.Visit(selector); - - var includeQuery = new IncludeQuery(query.PathMap); - query.PathMap[includeQuery] = query.Visitor.Path; - - return includeQuery; - } - - public static IIncludeQuery ThenInclude( - this IIncludeQuery query, - Expression> selector) - { - query.Visitor.Visit(selector); - - // If the visitor did not generated a path, return a new IncludeQuery with an unmodified PathMap. - if (string.IsNullOrEmpty(query.Visitor.Path)) - { - return new IncludeQuery(query.PathMap); - } - - var pathMap = query.PathMap; - var existingPath = pathMap[query]; - pathMap.Remove(query); - - var includeQuery = new IncludeQuery(query.PathMap); - pathMap[includeQuery] = $"{existingPath}.{query.Visitor.Path}"; - - return includeQuery; - } - - public static IIncludeQuery ThenInclude( - this IIncludeQuery> query, - Expression> selector) - { - query.Visitor.Visit(selector); - - // If the visitor did not generated a path, return a new IncludeQuery with an unmodified PathMap. - if (string.IsNullOrEmpty(query.Visitor.Path)) - { - return new IncludeQuery(query.PathMap); - } - - var pathMap = query.PathMap; - var existingPath = pathMap[query]; - pathMap.Remove(query); - - var includeQuery = new IncludeQuery(query.PathMap); - pathMap[includeQuery] = $"{existingPath}.{query.Visitor.Path}"; - - return includeQuery; - } - } -} diff --git a/src/ApplicationCore/Helpers/Query/IncludeVisitor.cs b/src/ApplicationCore/Helpers/Query/IncludeVisitor.cs deleted file mode 100644 index f6be55f..0000000 --- a/src/ApplicationCore/Helpers/Query/IncludeVisitor.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Linq.Expressions; - -namespace Microsoft.eShopWeb.ApplicationCore.Helpers.Query -{ - public class IncludeVisitor : ExpressionVisitor - { - public string Path { get; private set; } = string.Empty; - - protected override Expression VisitMember(MemberExpression node) - { - Path = string.IsNullOrEmpty(Path) ? node.Member.Name : $"{node.Member.Name}.{Path}"; - - return base.VisitMember(node); - } - } -} diff --git a/src/ApplicationCore/Interfaces/IAsyncRepository.cs b/src/ApplicationCore/Interfaces/IAsyncRepository.cs index e8033c2..baad6e1 100644 --- a/src/ApplicationCore/Interfaces/IAsyncRepository.cs +++ b/src/ApplicationCore/Interfaces/IAsyncRepository.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities; using System.Collections.Generic; using System.Threading.Tasks; diff --git a/src/ApplicationCore/Interfaces/IIncludeQuery.cs b/src/ApplicationCore/Interfaces/IIncludeQuery.cs deleted file mode 100644 index 9046cd6..0000000 --- a/src/ApplicationCore/Interfaces/IIncludeQuery.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; -using System.Collections.Generic; - -namespace Microsoft.eShopWeb.ApplicationCore.Interfaces -{ - public interface IIncludeQuery - { - Dictionary PathMap { get; } - IncludeVisitor Visitor { get; } - HashSet Paths { get; } - } - - public interface IIncludeQuery : IIncludeQuery - { - } -} diff --git a/src/ApplicationCore/Interfaces/ISpecification.cs b/src/ApplicationCore/Interfaces/ISpecification.cs deleted file mode 100644 index 2097163..0000000 --- a/src/ApplicationCore/Interfaces/ISpecification.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace Microsoft.eShopWeb.ApplicationCore.Interfaces -{ - public interface ISpecification - { - Expression> Criteria { get; } - List>> Includes { get; } - List IncludeStrings { get; } - Expression> OrderBy { get; } - Expression> OrderByDescending { get; } - Expression> GroupBy { get; } - - int Take { get; } - int Skip { get; } - bool IsPagingEnabled { get;} - } -} diff --git a/src/ApplicationCore/Specifications/BaseSpecification.cs b/src/ApplicationCore/Specifications/BaseSpecification.cs deleted file mode 100644 index 16d65e5..0000000 --- a/src/ApplicationCore/Specifications/BaseSpecification.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using System; -using System.Linq.Expressions; -using System.Collections.Generic; -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; - -namespace Microsoft.eShopWeb.ApplicationCore.Specifications -{ - public abstract class BaseSpecification : ISpecification - { - protected BaseSpecification(Expression> criteria) - { - Criteria = criteria; - } - public Expression> Criteria { get; } - public List>> Includes { get; } = new List>>(); - public List IncludeStrings { get; } = new List(); - public Expression> OrderBy { get; private set; } - public Expression> OrderByDescending { get; private set; } - public Expression> GroupBy { get; private set; } - - public int Take { get; private set; } - public int Skip { get; private set; } - public bool IsPagingEnabled { get; private set; } = false; - - protected virtual void AddInclude(Expression> includeExpression) - { - Includes.Add(includeExpression); - } - - protected virtual void AddIncludes(Func, IIncludeQuery> includeGenerator) - { - var includeQuery = includeGenerator(new IncludeAggregator()); - IncludeStrings.AddRange(includeQuery.Paths); - } - - protected virtual void AddInclude(string includeString) - { - IncludeStrings.Add(includeString); - } - protected virtual void ApplyPaging(int skip, int take) - { - Skip = skip; - Take = take; - IsPagingEnabled = true; - } - protected virtual void ApplyOrderBy(Expression> orderByExpression) - { - OrderBy = orderByExpression; - } - protected virtual void ApplyOrderByDescending(Expression> orderByDescendingExpression) - { - OrderByDescending = orderByDescendingExpression; - } - - //Not used anywhere at the moment, but someone requested an example of setting this up. - protected virtual void ApplyGroupBy(Expression> groupByExpression) - { - GroupBy = groupByExpression; - } - - } -} diff --git a/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs b/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs index bc96e34..f7bc0d4 100644 --- a/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs +++ b/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs @@ -1,16 +1,15 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace Microsoft.eShopWeb.ApplicationCore.Specifications { public sealed class BasketWithItemsSpecification : BaseSpecification { - public BasketWithItemsSpecification(int basketId) - :base(b => b.Id == basketId) + public BasketWithItemsSpecification(int basketId) : base(b => b.Id == basketId) { AddInclude(b => b.Items); } - public BasketWithItemsSpecification(string buyerId) - :base(b => b.BuyerId == buyerId) + public BasketWithItemsSpecification(string buyerId) : base(b => b.BuyerId == buyerId) { AddInclude(b => b.Items); } diff --git a/src/ApplicationCore/Specifications/CatalogFilterPaginatedSpecification.cs b/src/ApplicationCore/Specifications/CatalogFilterPaginatedSpecification.cs index f24b8c6..8bbdf04 100644 --- a/src/ApplicationCore/Specifications/CatalogFilterPaginatedSpecification.cs +++ b/src/ApplicationCore/Specifications/CatalogFilterPaginatedSpecification.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities; namespace Microsoft.eShopWeb.ApplicationCore.Specifications { diff --git a/src/ApplicationCore/Specifications/CatalogFilterSpecification.cs b/src/ApplicationCore/Specifications/CatalogFilterSpecification.cs index 2d67be1..fc68b8a 100644 --- a/src/ApplicationCore/Specifications/CatalogFilterSpecification.cs +++ b/src/ApplicationCore/Specifications/CatalogFilterSpecification.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities; namespace Microsoft.eShopWeb.ApplicationCore.Specifications { diff --git a/src/ApplicationCore/Specifications/CatalogItemsSpecification.cs b/src/ApplicationCore/Specifications/CatalogItemsSpecification.cs index 296d93d..d514e58 100644 --- a/src/ApplicationCore/Specifications/CatalogItemsSpecification.cs +++ b/src/ApplicationCore/Specifications/CatalogItemsSpecification.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities; using System; using System.Linq; diff --git a/src/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs b/src/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs index 662ec4e..2d673f7 100644 --- a/src/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs +++ b/src/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs @@ -1,5 +1,6 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; +using Ardalis.Specification; +using Ardalis.Specification.QueryExtensions.Include; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; namespace Microsoft.eShopWeb.ApplicationCore.Specifications { @@ -8,7 +9,8 @@ namespace Microsoft.eShopWeb.ApplicationCore.Specifications public CustomerOrdersWithItemsSpecification(string buyerId) : base(o => o.BuyerId == buyerId) { - AddIncludes(query => query.Include(o => o.OrderItems).ThenInclude(i => i.ItemOrdered)); + AddIncludes(query => query.Include(o => o.OrderItems) + .ThenInclude(i => i.ItemOrdered)); } } } diff --git a/src/Infrastructure/Data/EfRepository.cs b/src/Infrastructure/Data/EfRepository.cs index 303019c..0d2d222 100644 --- a/src/Infrastructure/Data/EfRepository.cs +++ b/src/Infrastructure/Data/EfRepository.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Ardalis.Specification; +using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using System.Collections.Generic; @@ -33,12 +34,14 @@ namespace Microsoft.eShopWeb.Infrastructure.Data public async Task> ListAsync(ISpecification spec) { - return await ApplySpecification(spec).ToListAsync(); + var specificationResult = await ApplySpecification(spec); + return await specificationResult.ToListAsync(); } public async Task CountAsync(ISpecification spec) { - return await ApplySpecification(spec).CountAsync(); + var specificationResult = await ApplySpecification(spec); + return await specificationResult.CountAsync(); } public async Task AddAsync(T entity) @@ -63,17 +66,19 @@ namespace Microsoft.eShopWeb.Infrastructure.Data public async Task FirstAsync(ISpecification spec) { - return await ApplySpecification(spec).FirstAsync(); + var specificationResult = await ApplySpecification(spec); + return await specificationResult.FirstAsync(); } public async Task FirstOrDefaultAsync(ISpecification spec) { - return await ApplySpecification(spec).FirstOrDefaultAsync(); + var specificationResult = await ApplySpecification(spec); + return await specificationResult.FirstOrDefaultAsync(); } - private IQueryable ApplySpecification(ISpecification spec) + private async Task> ApplySpecification(ISpecification spec) { - return SpecificationEvaluator.GetQuery(_dbContext.Set().AsQueryable(), spec); + return await EfSpecificationEvaluator.GetQuery(_dbContext.Set().AsQueryable(), spec); } } } \ No newline at end of file diff --git a/src/Infrastructure/Data/OrderRepository.cs b/src/Infrastructure/Data/OrderRepository.cs index 8e873bb..7ab0954 100644 --- a/src/Infrastructure/Data/OrderRepository.cs +++ b/src/Infrastructure/Data/OrderRepository.cs @@ -2,6 +2,7 @@ using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; +using Ardalis.Specification; namespace Microsoft.eShopWeb.Infrastructure.Data { diff --git a/src/Infrastructure/Data/SpecificationEvaluator.cs b/src/Infrastructure/Data/SpecificationEvaluator.cs deleted file mode 100644 index a564220..0000000 --- a/src/Infrastructure/Data/SpecificationEvaluator.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopWeb.ApplicationCore.Entities; -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using System.Linq; - -namespace Microsoft.eShopWeb.Infrastructure.Data -{ - public class SpecificationEvaluator where T : BaseEntity - { - public static IQueryable GetQuery(IQueryable inputQuery, ISpecification specification) - { - var query = inputQuery; - - // modify the IQueryable using the specification's criteria expression - if (specification.Criteria != null) - { - query = query.Where(specification.Criteria); - } - - // Includes all expression-based includes - query = specification.Includes.Aggregate(query, - (current, include) => current.Include(include)); - - // Include any string-based include statements - query = specification.IncludeStrings.Aggregate(query, - (current, include) => current.Include(include)); - - // Apply ordering if expressions are set - if (specification.OrderBy != null) - { - query = query.OrderBy(specification.OrderBy); - } - else if (specification.OrderByDescending != null) - { - query = query.OrderByDescending(specification.OrderByDescending); - } - - if (specification.GroupBy != null) - { - query = query.GroupBy(specification.GroupBy).SelectMany(x => x); - } - - // Apply paging if enabled - if (specification.IsPagingEnabled) - { - query = query.Skip(specification.Skip) - .Take(specification.Take); - } - return query; - } - } -} diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index 582bc7b..5af8b11 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 002ccd9..42fe238 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -14,6 +14,7 @@ + diff --git a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeAggregatorTests/Include.cs b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeAggregatorTests/Include.cs index 53abf08..77914bd 100644 --- a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeAggregatorTests/Include.cs +++ b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeAggregatorTests/Include.cs @@ -1,4 +1,4 @@ -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; +using Ardalis.Specification.QueryExtensions.Include; using Xunit; namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query.IncludeAggregatorTests diff --git a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/Include.cs b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/Include.cs index 2f95b1f..aa99722 100644 --- a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/Include.cs +++ b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/Include.cs @@ -1,4 +1,4 @@ -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; +using Ardalis.Specification.QueryExtensions.Include; using Microsoft.eShopWeb.UnitTests.Builders; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/ThenInclude.cs b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/ThenInclude.cs index e6e30d5..cf69f7d 100644 --- a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/ThenInclude.cs +++ b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeQueryTests/ThenInclude.cs @@ -1,4 +1,4 @@ -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; +using Ardalis.Specification.QueryExtensions.Include; using Microsoft.eShopWeb.UnitTests.Builders; using System.Linq; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeVisitorTests/Visit.cs b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeVisitorTests/Visit.cs index 58f0157..74abe0f 100644 --- a/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeVisitorTests/Visit.cs +++ b/tests/UnitTests/ApplicationCore/Helpers/Query/IncludeVisitorTests/Visit.cs @@ -1,4 +1,4 @@ -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; +using Ardalis.Specification.QueryExtensions.Include; using System; using System.Collections.Generic; using System.Linq.Expressions; diff --git a/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs b/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs index a29666b..8657abc 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs @@ -19,7 +19,7 @@ namespace Microsoft.eShopWeb.UnitTests var result = GetTestBasketCollection() .AsQueryable() - .FirstOrDefault(spec.Criteria); + .FirstOrDefault(spec.Criterias.FirstOrDefault()); Assert.NotNull(result); Assert.Equal(_testBasketId, result.Id); @@ -34,7 +34,7 @@ namespace Microsoft.eShopWeb.UnitTests Assert.False(GetTestBasketCollection() .AsQueryable() - .Any(spec.Criteria)); + .Any(spec.Criterias.FirstOrDefault())); } public List GetTestBasketCollection() diff --git a/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecificationFilter.cs b/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecificationFilter.cs index 2d760d8..0ceb480 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecificationFilter.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecificationFilter.cs @@ -3,7 +3,6 @@ using Microsoft.eShopWeb.ApplicationCore.Entities; using System.Collections.Generic; using System.Linq; using Xunit; -using Moq; namespace Microsoft.eShopWeb.UnitTests { @@ -23,7 +22,7 @@ namespace Microsoft.eShopWeb.UnitTests var result = GetTestItemCollection() .AsQueryable() - .Where(spec.Criteria); + .Where(spec.Criterias.FirstOrDefault()); Assert.Equal(expectedCount, result.Count()); } diff --git a/tests/UnitTests/Builders/IncludeQueryBuilder.cs b/tests/UnitTests/Builders/IncludeQueryBuilder.cs index 4657d65..ec99446 100644 --- a/tests/UnitTests/Builders/IncludeQueryBuilder.cs +++ b/tests/UnitTests/Builders/IncludeQueryBuilder.cs @@ -1,7 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; -using Microsoft.eShopWeb.ApplicationCore.Interfaces; +using Ardalis.Specification.QueryExtensions.Include; using Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query; -using System; using System.Collections.Generic; namespace Microsoft.eShopWeb.UnitTests.Builders diff --git a/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders_Should.cs b/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders_Should.cs index e5acc76..d2aef2d 100644 --- a/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders_Should.cs +++ b/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders_Should.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.Web.Features.MyOrders; using Moq; diff --git a/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails_Should.cs b/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails_Should.cs index a151159..a1c334c 100644 --- a/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails_Should.cs +++ b/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails_Should.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Ardalis.Specification; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.Web.Features.OrderDetails; using Moq;