Skip to content

Commit 3a105ba

Browse files
committed
Add include string tests for custom specs.
1 parent 11108d6 commit 3a105ba

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespace Tests.Evaluators;
2+
3+
[Collection("SharedCollection")]
4+
public class IncludeStringEvaluatorCustomSpecTests(TestFactory factory) : IntegrationTest(factory)
5+
{
6+
private static readonly IncludeStringEvaluator _evaluator = IncludeStringEvaluator.Instance;
7+
8+
[Fact]
9+
public void QueriesMatch_GivenNoIncludeString()
10+
{
11+
var spec = new CustomSpecification<Store>();
12+
13+
var actual = _evaluator
14+
.GetQuery(DbContext.Stores, spec)
15+
.ToQueryString();
16+
17+
var expected = DbContext.Stores
18+
.ToQueryString();
19+
20+
actual.Should().Be(expected);
21+
}
22+
23+
[Fact]
24+
public void QueriesMatch_GivenIncludeString()
25+
{
26+
var spec = new CustomSpecification<Store>();
27+
spec.Includes.Add(nameof(Address));
28+
29+
var actual = _evaluator
30+
.GetQuery(DbContext.Stores, spec)
31+
.ToQueryString();
32+
33+
var expected = DbContext.Stores
34+
.Include(nameof(Address))
35+
.ToQueryString();
36+
37+
actual.Should().Be(expected);
38+
}
39+
40+
[Fact]
41+
public void QueriesMatch_GivenMultipleIncludeStrings()
42+
{
43+
var spec = new CustomSpecification<Store>();
44+
spec.Includes.Add(nameof(Address));
45+
spec.Includes.Add($"{nameof(Company)}.{nameof(Country)}");
46+
47+
var actual = _evaluator
48+
.GetQuery(DbContext.Stores, spec)
49+
.ToQueryString();
50+
51+
var expected = DbContext.Stores
52+
.Include(nameof(Address))
53+
.Include($"{nameof(Company)}.{nameof(Country)}")
54+
.ToQueryString();
55+
56+
actual.Should().Be(expected);
57+
}
58+
59+
public class CustomSpecification<T> : ISpecification<T>
60+
{
61+
public List<string> Includes { get; set; } = new();
62+
public List<WhereExpressionInfo<T>> Where { get; set; } = new();
63+
public List<SearchExpressionInfo<T>> Search { get; set; } = new();
64+
public IEnumerable<string> IncludeStrings => Includes;
65+
public IEnumerable<SearchExpressionInfo<T>> SearchCriterias => Search;
66+
public IEnumerable<WhereExpressionInfo<T>> WhereExpressions => Where;
67+
68+
public ISpecificationBuilder<T> Query => throw new NotImplementedException();
69+
public IEnumerable<OrderExpressionInfo<T>> OrderExpressions => throw new NotImplementedException();
70+
public IEnumerable<IncludeExpressionInfo> IncludeExpressions => throw new NotImplementedException();
71+
public Dictionary<string, object> Items => throw new NotImplementedException();
72+
public int Take => throw new NotImplementedException();
73+
public int Skip => throw new NotImplementedException();
74+
public Func<IEnumerable<T>, IEnumerable<T>>? PostProcessingAction => throw new NotImplementedException();
75+
public IEnumerable<string> QueryTags => throw new NotImplementedException();
76+
public bool CacheEnabled => throw new NotImplementedException();
77+
public string? CacheKey => throw new NotImplementedException();
78+
public bool AsTracking => throw new NotImplementedException();
79+
public bool AsNoTracking => throw new NotImplementedException();
80+
public bool AsSplitQuery => throw new NotImplementedException();
81+
public bool AsNoTrackingWithIdentityResolution => throw new NotImplementedException();
82+
public bool IgnoreQueryFilters => throw new NotImplementedException();
83+
public bool IgnoreAutoIncludes => throw new NotImplementedException();
84+
public IEnumerable<T> Evaluate(IEnumerable<T> entities)
85+
=> throw new NotImplementedException();
86+
public bool IsSatisfiedBy(T entity)
87+
=> throw new NotImplementedException();
88+
}
89+
}

0 commit comments

Comments
 (0)