Skip to content

Commit f69abb1

Browse files
committed
Feat: IQueryable.With()
1 parent c6f2917 commit f69abb1

File tree

12 files changed

+109
-17
lines changed

12 files changed

+109
-17
lines changed

src/CodeOfChaos.Extensions.EntityFrameworkCore/CodeOfChaos.Extensions.EntityFrameworkCore.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
7+
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
8+
89
<!-- Main package name -->
910
<PackageId>CodeOfChaos.Extensions.EntityFrameworkCore</PackageId>
1011
<Version>0.39.4</Version>

src/CodeOfChaos.Extensions.EntityFrameworkCore/LinqExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// ---------------------------------------------------------------------------------------------------------------------
44
using System.Linq.Expressions;
55

6-
// ReSharper disable once CheckNamespace
76
namespace Microsoft.EntityFrameworkCore;
87
// ---------------------------------------------------------------------------------------------------------------------
98
// Code
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using System.Diagnostics;
5+
6+
namespace Microsoft.EntityFrameworkCore;
7+
// ---------------------------------------------------------------------------------------------------------------------
8+
// Code
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
public static class LinqWithExtensions {
11+
12+
[DebuggerStepThrough]
13+
public static IQueryable<T> With<T, T0>(this IQueryable<T> source, Func<IQueryable<T>, T0, IQueryable<T>> query, T0 arg0)
14+
=> query(source, arg0);
15+
16+
[DebuggerStepThrough]
17+
public static IQueryable<T> With<T, T0, T1>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, IQueryable<T>> query, T0 arg0, T1 arg1)
18+
=> query(source, arg0, arg1);
19+
20+
[DebuggerStepThrough]
21+
public static IQueryable<T> With<T, T0, T1, T2>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, T2, IQueryable<T>> query, T0 arg0, T1 arg1, T2 arg2)
22+
=> query(source, arg0, arg1, arg2);
23+
24+
[DebuggerStepThrough]
25+
public static IQueryable<T> With<T, T0, T1, T2, T3>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, T2, T3, IQueryable<T>> query, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
26+
=> query(source, arg0, arg1, arg2, arg3);
27+
28+
[DebuggerStepThrough]
29+
public static IQueryable<T> With<T, T0, T1, T2, T3, T4>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, T2, T3, T4, IQueryable<T>> query, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
30+
=> query(source, arg0, arg1, arg2, arg3, arg4);
31+
32+
[DebuggerStepThrough]
33+
public static IQueryable<T> With<T, T0, T1, T2, T3, T4, T5>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, T2, T3, T4, T5, IQueryable<T>> query, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
34+
=> query(source, arg0, arg1, arg2, arg3, arg4, arg5);
35+
36+
[DebuggerStepThrough]
37+
public static IQueryable<T> With<T, T0, T1, T2, T3, T4, T5, T6>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, T2, T3, T4, T5, T6, IQueryable<T>> query, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
38+
=> query(source, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
39+
40+
[DebuggerStepThrough]
41+
public static IQueryable<T> With<T, T0, T1, T2, T3, T4, T5, T6, T7>(this IQueryable<T> source, Func<IQueryable<T>, T0, T1, T2, T3, T4, T5, T6, T7, IQueryable<T>> query, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
42+
=> query(source, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
43+
}

tests/Tests.CodeOfChaos.Extensions.Analyzers/Tests.CodeOfChaos.Extensions.Analyzers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="CodeOfChaos.Testing.TUnit" Version="0.7.2" />
14-
<PackageReference Include="TUnit" Version="0.13.23" />
13+
<PackageReference Include="CodeOfChaos.Testing.TUnit" Version="0.8.0" />
14+
<PackageReference Include="TUnit" Version="0.14.6" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.AspNetCore/Tests.CodeOfChaos.Extensions.AspNetCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.13.23" />
17-
<PackageReference Include="Bogus" Version="35.6.1"/>
16+
<PackageReference Include="TUnit" Version="0.14.6" />
17+
<PackageReference Include="Bogus" Version="35.6.2" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.DependencyInjection.Generators/Tests.CodeOfChaos.Extensions.DependencyInjection.Generators.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="CodeOfChaos.Testing.TUnit" Version="0.7.2" />
10+
<PackageReference Include="CodeOfChaos.Testing.TUnit" Version="0.8.0" />
1111
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1212
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
1313
<PrivateAssets>all</PrivateAssets>
@@ -19,7 +19,7 @@
1919
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
2020
<PackageReference Include="Moq" Version="4.20.72" />
2121
<PackageReference Include="System.Formats.Asn1" Version="9.0.2" />
22-
<PackageReference Include="TUnit" Version="0.13.23" />
22+
<PackageReference Include="TUnit" Version="0.14.6" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.DependencyInjection/Tests.CodeOfChaos.Extensions.DependencyInjection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1616
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
1717
<PackageReference Include="Moq" Version="4.20.72" />
18-
<PackageReference Include="TUnit" Version="0.13.23" />
18+
<PackageReference Include="TUnit" Version="0.14.6" />
1919
</ItemGroup>
2020

2121
<ItemGroup>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.EntityFrameworkCore;
5+
6+
namespace Tests.CodeOfChaos.Extensions.EntityFrameworkCore;
7+
8+
// ---------------------------------------------------------------------------------------------------------------------
9+
// Code
10+
// ---------------------------------------------------------------------------------------------------------------------
11+
public class LinqWithQueryTests {
12+
[Test]
13+
[Arguments("a", new[] { "a", "b", "c" }, new[] { "a" })]
14+
[Arguments("b", new[] { "a", "b", "c" }, new[] { "b" })]
15+
[Arguments("c", new[] { "a", "b", "c" }, new[] { "c" })]
16+
public async Task ConditionalInclude_ShouldReturnSourceAsIs(string filter, IEnumerable<string> input, IEnumerable<string> expected) {
17+
// Arrange
18+
IQueryable<string> source = input.AsQueryable();
19+
20+
// Act
21+
IQueryable<string> output = source.With(WhereArg,filter);
22+
23+
// Assert
24+
await Assert.That(output).IsEquivalentTo(expected);
25+
return;
26+
27+
IQueryable<string> WhereArg(IQueryable<string> s, string f) => source.Where(x => x == f);
28+
}
29+
30+
[Test]
31+
[Arguments("a", "c", new[] { "a", "b", "c" }, new[] { "a", "c" })]
32+
[Arguments("b", "", new[] { "a", "b", "c" }, new[] { "b" })]
33+
[Arguments("c", "c", new[] { "a", "b", "c" }, new[] { "c" })]
34+
public async Task ConditionalInclude_ShouldReturnSourceAsIs(string arg0, string arg1, IEnumerable<string> input, IEnumerable<string> expected) {
35+
// Arrange
36+
IQueryable<string> source = input.AsQueryable();
37+
38+
// Act
39+
IQueryable<string> output = source.With(WhereArg,arg0, arg1);
40+
41+
// Assert
42+
await Assert.That(output).IsEquivalentTo(expected);
43+
return;
44+
45+
IQueryable<string> WhereArg(IQueryable<string> s, string a0, string a1) => source.Where(x =>
46+
!string.IsNullOrWhiteSpace(a1) && (x == a0 || x == a1)
47+
|| string.IsNullOrWhiteSpace(a1) && x == a0);
48+
}
49+
}

tests/Tests.CodeOfChaos.Extensions.EntityFrameworkCore/Tests.CodeOfChaos.Extensions.EntityFrameworkCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.13.23" />
17-
<PackageReference Include="Bogus" Version="35.6.1"/>
16+
<PackageReference Include="TUnit" Version="0.14.6" />
17+
<PackageReference Include="Bogus" Version="35.6.2" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.FluentValidation/Tests.CodeOfChaos.Extensions.FluentValidation.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.13.23" />
17-
<PackageReference Include="Bogus" Version="35.6.1"/>
16+
<PackageReference Include="TUnit" Version="0.14.6" />
17+
<PackageReference Include="Bogus" Version="35.6.2" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)