Skip to content

Commit

Permalink
Extract QueryableExtensions into own NuGet package (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Lycken committed Nov 1, 2017
1 parent 81238d3 commit fd9ef32
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/RdbmsEventStore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RdbmsEventStore.Tests", "Rd
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RdbmsEventStore.EntityFramework.Tests", "RdbmsEventStore.EntityFramework.Tests\RdbmsEventStore.EntityFramework.Tests.csproj", "{0096C881-9347-454E-B0A0-73C7CABDBF37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tlycken.Extensions", "tlycken.Extensions\tlycken.Extensions.csproj", "{3D60C8BA-ACC3-4CBC-B47C-79A504553C93}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tlycken.Extensions.Tests", "tlycken.Extensions.Tests\tlycken.Extensions.Tests.csproj", "{08FAE0C2-B435-4BA9-8CC4-52EC7FE1EDD6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,13 +51,22 @@ Global
{0096C881-9347-454E-B0A0-73C7CABDBF37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0096C881-9347-454E-B0A0-73C7CABDBF37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0096C881-9347-454E-B0A0-73C7CABDBF37}.Release|Any CPU.Build.0 = Release|Any CPU
{3D60C8BA-ACC3-4CBC-B47C-79A504553C93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D60C8BA-ACC3-4CBC-B47C-79A504553C93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D60C8BA-ACC3-4CBC-B47C-79A504553C93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D60C8BA-ACC3-4CBC-B47C-79A504553C93}.Release|Any CPU.Build.0 = Release|Any CPU
{08FAE0C2-B435-4BA9-8CC4-52EC7FE1EDD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08FAE0C2-B435-4BA9-8CC4-52EC7FE1EDD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08FAE0C2-B435-4BA9-8CC4-52EC7FE1EDD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08FAE0C2-B435-4BA9-8CC4-52EC7FE1EDD6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E58D4AE3-79B6-4B36-9693-9D852222D06E} = {B3BDC65F-EA8A-4CDC-85FC-0AA1C48C95A8}
{0096C881-9347-454E-B0A0-73C7CABDBF37} = {B3BDC65F-EA8A-4CDC-85FC-0AA1C48C95A8}
{08FAE0C2-B435-4BA9-8CC4-52EC7FE1EDD6} = {B3BDC65F-EA8A-4CDC-85FC-0AA1C48C95A8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CA4860B3-3208-41C0-8FB9-719E00FBAD0D}
Expand Down
4 changes: 4 additions & 0 deletions src/RdbmsEventStore/RdbmsEventStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<PackageReference Include="Nito.AsyncEx.Coordination" Version="1.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\tlycken.Extensions\tlycken.Extensions.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions src/tlycken.Extensions.Tests/QueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Linq;
using Xunit;

namespace tlycken.Extensions.Tests
{
public class QueryableExtensions
{
public class Foo
{
public bool Bar { get; set; }
}

[Fact]
public void CanApplyProjectionToQueryables()
{
var foos = new[] { new Foo { Bar = true }, new Foo { Bar = false }, new Foo { Bar = true } }.AsQueryable();

var result = foos.Apply(fs => fs.Where(foo => foo.Bar));

Assert.Equal(2, result.Count());
}
}
}
19 changes: 19 additions & 0 deletions src/tlycken.Extensions.Tests/tlycken.Extensions.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

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

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\tlycken.Extensions\tlycken.Extensions.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/tlycken.Extensions/FuncExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ReSharper disable once CheckNamespace
namespace System
{
public static class FuncExtensions
{
/// <summary>
/// Fluently applies the function <paramref name="projection"/> to the argument <paramref name="source"/>.
/// </summary>
/// <remarks>My main use case for this as an abstraction for queryables, taking a
/// <code>Func{IQueryable{S}, IQueryable{T}}</code> as an argument and applying it
/// in a longer LINQ method chain.</remarks>
/// <typeparam name="S">The element type of the queryable sequence</typeparam>
/// <typeparam name="T">The element type of the result</typeparam>
/// <param name="source">The source sequence</param>
/// <param name="projection">A projection to apply to the <paramref name="source"/> sequence</param>
/// <returns>projection(source)</returns>
public static T Apply<S, T>(this S source, Func<S, T> projection) => projection(source);
}
}
7 changes: 7 additions & 0 deletions src/tlycken.Extensions/tlycken.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>

0 comments on commit fd9ef32

Please sign in to comment.