Skip to content

Commit

Permalink
Upgrade packages and dotnet version (#17)
Browse files Browse the repository at this point in the history
* WIP - Updating packages and .net version to 3.1

* removing groupby functionality

* rename azure pipelines

Co-authored-by: Eric Fleming <[email protected]>
  • Loading branch information
ardalis and efleming18 authored Jun 5, 2020
1 parent f95308c commit 193a6a0
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,4 @@ __pycache__/
*.odx.cs
*.xsd.cs
.vscode/
/out.txt
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /

COPY . ./
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/Ardalis.Specification/Ardalis.Specification.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<Summary>A simple package with a base Specification class, for use in creating queries that work with Repository types.</Summary>
<RepositoryUrl>https://github.com/ardalis/specification</RepositoryUrl>
<PackageTags>spec;specification;repository;ddd</PackageTags>
<Version>2.1.0</Version>
<PackageReleaseNotes>Added support for custom selectors and ThenInclude for additional criteria.</PackageReleaseNotes>
<Version>3.0.0</Version>
<PackageReleaseNotes>Removed TId from SpecificationEvaluator and removed GroupBy which is no longer supported by EF Core 3.0</PackageReleaseNotes>
<AssemblyName>Ardalis.Specification</AssemblyName>
<PackageIconUrl>https://user-images.githubusercontent.com/782127/33497760-facf6550-d69c-11e7-94e4-b3856da259a9.png</PackageIconUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -24,12 +24,12 @@

<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="1.5.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-*" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore">
<Version>2.2.4</Version>
<Version>3.1.4</Version>
</PackageReference>
</ItemGroup>

Expand Down
8 changes: 1 addition & 7 deletions src/Ardalis.Specification/BaseSpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected BaseSpecification(Expression<Func<T, bool>> criteria)
public Expression<Func<T, object>> ThenBy { get; private set; }
public Expression<Func<T, object>> OrderBy { get; private set; }
public Expression<Func<T, object>> OrderByDescending { get; private set; }
public Expression<Func<T, object>> GroupBy { get; private set; }
//public Expression<Func<T, object>> GroupBy { get; private set; }

public int Take { get; private set; }
public int Skip { get; private set; }
Expand Down Expand Up @@ -89,12 +89,6 @@ protected virtual void ApplyOrderByDescending(Expression<Func<T, object>> orderB
OrderByDescending = orderByDescendingExpression;
}

//Not used anywhere at the moment, but someone requested an example of setting this up.
protected virtual void ApplyGroupBy(Expression<Func<T, object>> groupByExpression)
{
GroupBy = groupByExpression;
}

/// <summary>
/// Must be called after specifying criteria
/// </summary>
Expand Down
13 changes: 7 additions & 6 deletions src/Ardalis.Specification/EfSpecificationEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Ardalis.Specification
{
public class EfSpecificationEvaluator<T, TId, TResult> where T : class, IEntity<TId>
public class EfSpecificationEvaluator<T, TResult> where T : class
{
public static IQueryable<TResult> GetQuery(IQueryable<T> inputQuery, ISpecification<T, TResult> specification)
public static async Task<IQueryable<TResult>> GetQuery(IQueryable<T> inputQuery, ISpecification<T, TResult> specification)
{
var query = EfSpecificationEvaluator<T, TId>.GetQuery(inputQuery, specification);
var query = await EfSpecificationEvaluator<T>.GetQuery(inputQuery, specification);

// Apply selector
var selectQuery = query.Select(specification.Selector);
Expand All @@ -16,13 +17,13 @@ public static IQueryable<TResult> GetQuery(IQueryable<T> inputQuery, ISpecificat
}
}

public class EfSpecificationEvaluator<T, TId> where T : class, IEntity<TId>
public class EfSpecificationEvaluator<T> where T : class
{
public static IQueryable<T> GetQuery(IQueryable<T> inputQuery, ISpecification<T> specification)
public static async Task<IQueryable<T>> GetQuery(IQueryable<T> inputQuery, ISpecification<T> specification)
{
var query = inputQuery;

query = SpecificationEvaluator<T, TId>.GetQuery(query, specification);
query = await SpecificationEvaluator<T>.GetQuery(query, specification);

// Includes all expression-based includes
query = specification.Includes.Aggregate(query,
Expand Down
2 changes: 1 addition & 1 deletion src/Ardalis.Specification/ISpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ISpecification<T>
Expression<Func<T, object>> OrderBy { get; }
Expression<Func<T, object>> ThenBy { get; }
Expression<Func<T, object>> OrderByDescending { get; }
Expression<Func<T, object>> GroupBy { get; }
//Expression<Func<T, object>> GroupBy { get; }

int Take { get; }
int Skip { get; }
Expand Down
17 changes: 10 additions & 7 deletions src/Ardalis.Specification/SpecificationEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;

namespace Ardalis.Specification
{
public class SpecificationEvaluator<T, TId> where T : class, IEntity<TId>
public class SpecificationEvaluator<T> where T : class
{
public static IQueryable<T> GetQuery(IQueryable<T> inputQuery, ISpecification<T> specification)
public static async Task<IQueryable<T>> GetQuery(IQueryable<T> inputQuery, ISpecification<T> specification)
{
var query = inputQuery;

Expand Down Expand Up @@ -33,10 +35,11 @@ public static IQueryable<T> GetQuery(IQueryable<T> inputQuery, ISpecification<T>
query = query.OrderByDescending(specification.OrderByDescending);
}

if (specification.GroupBy != null)
{
query = query.GroupBy(specification.GroupBy).SelectMany(x => x);
}
//TODO: Breaking changes in EF Core 3.0 have made this difficult. Need to re-think how this is done.
//if (specification.GroupBy != null)
//{

//}

// Apply paging if enabled
if (specification.IsPagingEnabled)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.3.1">
<PackageReference Include="coverlet.msbuild" Version="2.9.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="ReportGenerator" Version="4.2.5" />
<PackageReference Include="Dapper" Version="1.60.5" />
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="ReportGenerator" Version="4.6.1" />
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Ardalis.Specification.IntegrationTests.SampleSpecs;
using Dapper;
using FluentAssertions;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -132,14 +132,14 @@ public void EnableCacheShouldSetCacheKeyProperly()
spec.CacheKey.Should().Be($"BlogWithPostsSpec-{BlogBuilder.VALID_BLOG_ID}");
}

[Fact]
public async Task GroupByShouldWorkProperlyl()
{
var spec = new PostsGroupedByIdSpec();
var result = (await _postRepository.ListAsync(spec)).ToList();
//[Fact]
//public async Task GroupByShouldWorkProperly()
//{
// var spec = new PostsGroupedByIdSpec();
// var result = (await _postRepository.ListAsync(spec)).ToList();

result.First().Id.Should().Be(301);
result.Skip(1).Take(1).First().Id.Should().Be(303);
}
// result.First().Id.Should().Be(301);
// result.Skip(1).Take(1).First().Id.Should().Be(303);
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public async Task DeleteAsync(T entity)

private IQueryable<T> ApplySpecification(ISpecification<T> spec)
{
return EfSpecificationEvaluator<T, int>.GetQuery(_dbContext.Set<T>().AsQueryable(), spec);
return EfSpecificationEvaluator<T>.GetQuery(_dbContext.Set<T>().AsQueryable(), spec).Result;
}

private IQueryable<TResult> ApplySpecification<TResult>(ISpecification<T, TResult> spec)
{
return EfSpecificationEvaluator<T, int, TResult>.GetQuery(_dbContext.Set<T>().AsQueryable(), spec);
return EfSpecificationEvaluator<T, TResult>.GetQuery(_dbContext.Set<T>().AsQueryable(), spec).Result;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using System.Collections.Generic;

namespace Ardalis.Specification.IntegrationTests.SampleClient
{
public class SampleDbContext : DbContext
{
public static readonly ILoggerFactory loggerFactory = new LoggerFactory(new[] {
new ConsoleLoggerProvider((_, __) => true, true)
});
public static readonly ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddFilter("Ardalis.Specification", LogLevel.Debug);
builder.AddConsole();
});

public DbSet<Author> Authors { get; set; }
public DbSet<Blog> Blogs { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public class PostsGroupedByIdSpec : BaseSpecification<Post>
{
public PostsGroupedByIdSpec() : base(p => true)
{
ApplyGroupBy(p => p.Id % 2 == 0);
// Removed in version 3.0
//ApplyGroupBy(p => p.Id % 2 == 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.3.1">
<PackageReference Include="coverlet.msbuild" Version="2.9.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="ReportGenerator" Version="4.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="ReportGenerator" Version="4.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Ardalis.Specification.UnitTests
Expand All @@ -20,16 +21,18 @@ public ItemWithIdSpecification(int id) : base(i => i.Id == id)
}

[Fact]
public void ReturnsEntityWithId()
public async Task ReturnsEntityWithId()
{
var spec = new ItemWithIdSpecification(_testId);

var result = SpecificationEvaluator<TestItem,int>.GetQuery(
var result = await SpecificationEvaluator<TestItem>.GetQuery(
GetTestListOfItems()
.AsQueryable(),
spec).Single();
spec);

Assert.Equal(_testId, result.Id);
var result1 = result.Single();

Assert.Equal(_testId, result1.Id);
}

private List<TestItem> GetTestListOfItems()
Expand Down

0 comments on commit 193a6a0

Please sign in to comment.