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