Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageVersion Include="Testcontainers.MsSql" Version="4.6.0" />
<PackageVersion Include="Polyfill" Version="8.8.0" />
<PackageVersion Include="FluentAssertions" Version="[7.2.0]" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class IncludeStringEvaluatorCustomSpecTests(TestFactory factory) : Integr
[Fact]
public void QueriesMatch_GivenNoIncludeString()
{
var spec = new CustomSpecification<Store>();
var spec = Substitute.For<ISpecification<Store>>();

var actual = _evaluator
.GetQuery(DbContext.Stores, spec)
Expand All @@ -23,8 +23,11 @@ public void QueriesMatch_GivenNoIncludeString()
[Fact]
public void QueriesMatch_GivenIncludeString()
{
var spec = new CustomSpecification<Store>();
spec.Includes.Add(nameof(Address));
var spec = Substitute.For<ISpecification<Store>>();
spec.IncludeStrings.Returns(
[
nameof(Address)
]);

var actual = _evaluator
.GetQuery(DbContext.Stores, spec)
Expand All @@ -40,9 +43,12 @@ public void QueriesMatch_GivenIncludeString()
[Fact]
public void QueriesMatch_GivenMultipleIncludeStrings()
{
var spec = new CustomSpecification<Store>();
spec.Includes.Add(nameof(Address));
spec.Includes.Add($"{nameof(Company)}.{nameof(Country)}");
var spec = Substitute.For<ISpecification<Store>>();
spec.IncludeStrings.Returns(
[
nameof(Address),
$"{nameof(Company)}.{nameof(Country)}"
]);

var actual = _evaluator
.GetQuery(DbContext.Stores, spec)
Expand All @@ -55,35 +61,4 @@ public void QueriesMatch_GivenMultipleIncludeStrings()

actual.Should().Be(expected);
}

public class CustomSpecification<T> : ISpecification<T>
{
public List<string> Includes { get; set; } = new();
public List<WhereExpressionInfo<T>> Where { get; set; } = new();
public List<SearchExpressionInfo<T>> Search { get; set; } = new();
public IEnumerable<string> IncludeStrings => Includes;
public IEnumerable<SearchExpressionInfo<T>> SearchCriterias => Search;
public IEnumerable<WhereExpressionInfo<T>> WhereExpressions => Where;

public ISpecificationBuilder<T> Query => throw new NotImplementedException();
public IEnumerable<OrderExpressionInfo<T>> OrderExpressions => throw new NotImplementedException();
public IEnumerable<IncludeExpressionInfo> IncludeExpressions => throw new NotImplementedException();
public Dictionary<string, object> Items => throw new NotImplementedException();
public int Take => throw new NotImplementedException();
public int Skip => throw new NotImplementedException();
public Func<IEnumerable<T>, IEnumerable<T>>? PostProcessingAction => throw new NotImplementedException();
public IEnumerable<string> QueryTags => throw new NotImplementedException();
public bool CacheEnabled => throw new NotImplementedException();
public string? CacheKey => throw new NotImplementedException();
public bool AsTracking => throw new NotImplementedException();
public bool AsNoTracking => throw new NotImplementedException();
public bool AsSplitQuery => throw new NotImplementedException();
public bool AsNoTrackingWithIdentityResolution => throw new NotImplementedException();
public bool IgnoreQueryFilters => throw new NotImplementedException();
public bool IgnoreAutoIncludes => throw new NotImplementedException();
public IEnumerable<T> Evaluate(IEnumerable<T> entities)
=> throw new NotImplementedException();
public bool IsSatisfiedBy(T entity)
=> throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Tests.Evaluators;
using Azure;

namespace Tests.Evaluators;

[Collection("SharedCollection")]
public class QueryTagEvaluatorCustomTests(TestFactory factory) : IntegrationTest(factory)
Expand All @@ -10,8 +12,8 @@ public void QueriesMatch_GivenTag()
{
var tag = "asd";

var spec = new CustomSpecification<Country>();
spec.Tags.Add(tag);
var spec = Substitute.For<ISpecification<Country>>();
spec.QueryTags.Returns([tag]);

var actual = _evaluator.GetQuery(DbContext.Countries, spec)
.ToQueryString();
Expand All @@ -29,9 +31,8 @@ public void QueriesMatch_GivenMultipleTags()
var tag1 = "asd";
var tag2 = "qwe";

var spec = new CustomSpecification<Country>();
spec.Tags.Add(tag1);
spec.Tags.Add(tag2);
var spec = Substitute.For<ISpecification<Country>>();
spec.QueryTags.Returns([tag1, tag2]);

var actual = _evaluator.GetQuery(DbContext.Countries, spec)
.ToQueryString();
Expand All @@ -48,7 +49,7 @@ public void QueriesMatch_GivenMultipleTags()
[Fact]
public void DoesNothing_GivenNoTag()
{
var spec = new CustomSpecification<Country>();
var spec = Substitute.For<ISpecification<Country>>();

var actual = _evaluator.GetQuery(DbContext.Countries, spec)
.Expression
Expand All @@ -67,8 +68,8 @@ public void Applies_GivenSingleTag()
{
var tag = "asd";

var spec = new CustomSpecification<Country>();
spec.Tags.Add(tag);
var spec = Substitute.For<ISpecification<Country>>();
spec.QueryTags.Returns([tag]);

var actual = _evaluator.GetQuery(DbContext.Countries, spec)
.Expression
Expand All @@ -88,9 +89,8 @@ public void Applies_GivenTwoTags()
var tag1 = "asd";
var tag2 = "qwe";

var spec = new CustomSpecification<Country>();
spec.Tags.Add(tag1);
spec.Tags.Add(tag2);
var spec = Substitute.For<ISpecification<Country>>();
spec.QueryTags.Returns([tag1, tag2]);

var actual = _evaluator.GetQuery(DbContext.Countries, spec)
.Expression
Expand All @@ -112,10 +112,8 @@ public void Applies_GivenMultipleTags()
var tag2 = "qwe";
var tag3 = "zxc";

var spec = new CustomSpecification<Country>();
spec.Tags.Add(tag1);
spec.Tags.Add(tag2);
spec.Tags.Add(tag3);
var spec = Substitute.For<ISpecification<Country>>();
spec.QueryTags.Returns([tag1, tag2, tag3]);

var actual = _evaluator.GetQuery(DbContext.Countries, spec)
.Expression
Expand All @@ -130,35 +128,4 @@ public void Applies_GivenMultipleTags()

actual.Should().Be(expected);
}

public class CustomSpecification<T> : ISpecification<T>
{
public List<string> Tags { get; set; } = new();
public List<WhereExpressionInfo<T>> Where { get; set; } = new();
public List<SearchExpressionInfo<T>> Search { get; set; } = new();
public IEnumerable<string> QueryTags => Tags;
public IEnumerable<SearchExpressionInfo<T>> SearchCriterias => Search;
public IEnumerable<WhereExpressionInfo<T>> WhereExpressions => Where;

public ISpecificationBuilder<T> Query => throw new NotImplementedException();
public IEnumerable<OrderExpressionInfo<T>> OrderExpressions => throw new NotImplementedException();
public IEnumerable<IncludeExpressionInfo> IncludeExpressions => throw new NotImplementedException();
public IEnumerable<string> IncludeStrings => throw new NotImplementedException();
public Dictionary<string, object> Items => throw new NotImplementedException();
public int Take => throw new NotImplementedException();
public int Skip => throw new NotImplementedException();
public Func<IEnumerable<T>, IEnumerable<T>>? PostProcessingAction => throw new NotImplementedException();
public bool CacheEnabled => throw new NotImplementedException();
public string? CacheKey => throw new NotImplementedException();
public bool AsTracking => throw new NotImplementedException();
public bool AsNoTracking => throw new NotImplementedException();
public bool AsSplitQuery => throw new NotImplementedException();
public bool AsNoTrackingWithIdentityResolution => throw new NotImplementedException();
public bool IgnoreQueryFilters => throw new NotImplementedException();
public bool IgnoreAutoIncludes => throw new NotImplementedException();
public IEnumerable<T> Evaluate(IEnumerable<T> entities)
=> throw new NotImplementedException();
public bool IsSatisfiedBy(T entity)
=> throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ public class SearchEvaluatorCustomSpecTests(TestFactory factory) : IntegrationTe
[Fact]
public void QueriesMatch_GivenNoSearch()
{
var spec = new CustomSpecification<Store>();
spec.Where.Add(new WhereExpressionInfo<Store>(x => x.Id > 0));
var spec = Substitute.For<ISpecification<Store>>();
spec.WhereExpressions.Returns(
[
new WhereExpressionInfo<Store>(x => x.Id > 0)
]);

var actual = _evaluator.GetQuery(DbContext.Stores, spec)
.ToQueryString();
Expand All @@ -26,9 +29,15 @@ public void QueriesMatch_GivenSingleSearch()
{
var storeTerm = "ab1";

var spec = new CustomSpecification<Store>();
spec.Where.Add(new WhereExpressionInfo<Store>(x => x.Id > 0));
spec.Search.Add(new SearchExpressionInfo<Store>(x => x.Name, $"%{storeTerm}%"));
var spec = Substitute.For<ISpecification<Store>>();
spec.WhereExpressions.Returns(
[
new WhereExpressionInfo<Store>(x => x.Id > 0)
]);
spec.SearchCriterias.Returns(
[
new SearchExpressionInfo<Store>(x => x.Name, $"%{storeTerm}%")
]);

var actual = _evaluator.GetQuery(DbContext.Stores, spec)
.ToQueryString();
Expand All @@ -48,12 +57,18 @@ public void QueriesMatch_GivenMultipleSearch()
var countryTerm = "ab3";
var streetTerm = "ab4";

var spec = new CustomSpecification<Store>();
spec.Where.Add(new WhereExpressionInfo<Store>(x => x.Id > 0));
spec.Search.Add(new SearchExpressionInfo<Store>(x => x.Name, $"%{storeTerm}%"));
spec.Search.Add(new SearchExpressionInfo<Store>(x => x.Company.Name, $"%{companyTerm}%"));
spec.Search.Add(new SearchExpressionInfo<Store>(x => x.Address.Street, $"%{streetTerm}%", 2));
spec.Search.Add(new SearchExpressionInfo<Store>(x => x.Company.Country.Name, $"%{countryTerm}%", 3));
var spec = Substitute.For<ISpecification<Store>>();
spec.WhereExpressions.Returns(
[
new WhereExpressionInfo<Store>(x => x.Id > 0)
]);
spec.SearchCriterias.Returns(
[
new SearchExpressionInfo<Store>(x => x.Name, $"%{storeTerm}%"),
new SearchExpressionInfo<Store>(x => x.Company.Name, $"%{companyTerm}%"),
new SearchExpressionInfo<Store>(x => x.Address.Street, $"%{streetTerm}%", 2),
new SearchExpressionInfo<Store>(x => x.Company.Country.Name, $"%{countryTerm}%", 3)
]);

var actual = _evaluator.GetQuery(DbContext.Stores, spec)
.ToQueryString();
Expand All @@ -67,34 +82,4 @@ public void QueriesMatch_GivenMultipleSearch()

actual.Should().Be(expected);
}

public class CustomSpecification<T> : ISpecification<T>
{
public List<WhereExpressionInfo<T>> Where { get; set; } = new();
public List<SearchExpressionInfo<T>> Search { get; set; } = new();
public IEnumerable<SearchExpressionInfo<T>> SearchCriterias => Search;
public IEnumerable<WhereExpressionInfo<T>> WhereExpressions => Where;

public ISpecificationBuilder<T> Query => throw new NotImplementedException();
public IEnumerable<OrderExpressionInfo<T>> OrderExpressions => throw new NotImplementedException();
public IEnumerable<IncludeExpressionInfo> IncludeExpressions => throw new NotImplementedException();
public IEnumerable<string> IncludeStrings => throw new NotImplementedException();
public Dictionary<string, object> Items => throw new NotImplementedException();
public int Take => throw new NotImplementedException();
public int Skip => throw new NotImplementedException();
public Func<IEnumerable<T>, IEnumerable<T>>? PostProcessingAction => throw new NotImplementedException();
public IEnumerable<string> QueryTags => throw new NotImplementedException();
public bool CacheEnabled => throw new NotImplementedException();
public string? CacheKey => throw new NotImplementedException();
public bool AsTracking => throw new NotImplementedException();
public bool AsNoTracking => throw new NotImplementedException();
public bool AsSplitQuery => throw new NotImplementedException();
public bool AsNoTrackingWithIdentityResolution => throw new NotImplementedException();
public bool IgnoreQueryFilters => throw new NotImplementedException();
public bool IgnoreAutoIncludes => throw new NotImplementedException();
public IEnumerable<T> Evaluate(IEnumerable<T> entities)
=> throw new NotImplementedException();
public bool IsSatisfiedBy(T entity)
=> throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
global using System.Threading.Tasks;
global using Tests.Fixture;
global using Xunit;
global using NSubstitute;
Loading