Skip to content

Commit 3eec608

Browse files
Merge pull request #650 from johelvisguzman/GH-649
(GH-649) Ensure spec predicate not missing from options for find methods
2 parents c81dac8 + bc263c7 commit 3eec608

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/DotNetToolkit.Repository/RepositoryBase.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,11 @@ public TResult Find<TResult>(IQueryOptions<TEntity> options, [NotNull] Expressio
16641664
{
16651665
LogExecutingMethod();
16661666

1667-
InterceptError(() => Guard.NotNull(selector, nameof(selector)));
1667+
InterceptError(() =>
1668+
{
1669+
Guard.NotNull(selector, nameof(selector));
1670+
Guard.EnsureNotNull(options.SpecificationStrategy, Resources.SpecificationMissingFromQueryOptions);
1671+
});
16681672

16691673
TResult Getter() =>
16701674
UseContext<TResult>(
@@ -2462,7 +2466,11 @@ await InterceptAsync(x => x.DeleteExecutingAsync(
24622466
{
24632467
LogExecutingMethod();
24642468

2465-
InterceptError(() => Guard.NotNull(selector, nameof(selector)));
2469+
InterceptError(() =>
2470+
{
2471+
Guard.NotNull(selector, nameof(selector));
2472+
Guard.EnsureNotNull(options.SpecificationStrategy, Resources.SpecificationMissingFromQueryOptions);
2473+
});
24662474

24672475
Task<TResult> Getter() =>
24682476
UseContextAsync<TResult>(

test/DotNetToolkit.Repository.Integration.Test/Tests/Repository/RepositoryTests.Find.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private static void TestFind(IRepositoryFactory repoFactory)
225225

226226
const string name = "Random Name";
227227

228-
var options = new QueryOptions<Customer>();
228+
var options = new QueryOptions<Customer>().SatisfyBy(x => x.Name.Equals(name));
229229
var entity = new Customer { Id = 1, Name = name };
230230

231231
Assert.Null(repo.Find(x => x.Name.Equals(name)));
@@ -266,7 +266,7 @@ private static void TestFindWithSortingOptionsDescending(IRepositoryFactory repo
266266
new Customer { Id = 2, Name = "Random Name 1" }
267267
};
268268

269-
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name);
269+
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
270270

271271
Assert.Null(repo.Find(x => x.Name.Contains("Random Name"))?.Name);
272272
Assert.Null(repo.Find(options)?.Name);
@@ -291,7 +291,7 @@ private static void TestFindWithSortingOptionsAscending(IRepositoryFactory repoF
291291
new Customer { Id = 2, Name = "Random Name 1" }
292292
};
293293

294-
var options = new QueryOptions<Customer>().OrderBy(x => x.Name);
294+
var options = new QueryOptions<Customer>().OrderBy(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
295295

296296
Assert.Null(repo.Find(x => x.Name.Contains("Random Name"))?.Name);
297297
Assert.Null(repo.Find(options)?.Name);
@@ -818,7 +818,7 @@ private static async Task TestFindAsync(IRepositoryFactory repoFactory)
818818

819819
const string name = "Random Name";
820820

821-
var options = new QueryOptions<Customer>();
821+
var options = new QueryOptions<Customer>().SatisfyBy(x => x.Name.Equals(name));
822822
var entity = new Customer { Id = 1, Name = name };
823823

824824
Assert.Null(await repo.FindAsync(x => x.Name.Equals(name)));
@@ -859,7 +859,7 @@ private static async Task TestFindWithSortingOptionsDescendingAsync(IRepositoryF
859859
new Customer { Id = 2, Name = "Random Name 1" }
860860
};
861861

862-
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name);
862+
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
863863

864864
Assert.Null((await repo.FindAsync(x => x.Name.Contains("Random Name")))?.Name);
865865
Assert.Null((await repo.FindAsync(options))?.Name);
@@ -884,7 +884,7 @@ private static async Task TestFindWithSortingOptionsAscendingAsync(IRepositoryFa
884884
new Customer { Id = 2, Name = "Random Name 1" }
885885
};
886886

887-
var options = new QueryOptions<Customer>().OrderBy(x => x.Name);
887+
var options = new QueryOptions<Customer>().OrderBy(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
888888

889889
Assert.Null((await repo.FindAsync(x => x.Name.Contains("Random Name")))?.Name);
890890
Assert.Null((await repo.FindAsync(options))?.Name);

test/DotNetToolkit.Repository.Integration.Test/Tests/Service/ServiceTests.Get.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static void TestGet(IServiceFactory serviceFactory)
149149

150150
const string name = "Random Name";
151151

152-
var options = new QueryOptions<Customer>();
152+
var options = new QueryOptions<Customer>().SatisfyBy(x => x.Name.Equals(name)); ;
153153
var entity = new Customer {Name = name};
154154

155155
Assert.Null(service.Get(x => x.Name.Equals(name)));
@@ -175,7 +175,7 @@ private static void TestGetWithSortingOptionsDescending(IServiceFactory serviceF
175175
new Customer {Name = "Random Name 1"}
176176
};
177177

178-
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name);
178+
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
179179

180180
Assert.Null(service.Get(x => x.Name.Contains("Random Name"))?.Name);
181181
Assert.Null(service.Get(options)?.Name);
@@ -200,7 +200,7 @@ private static void TestGetWithSortingOptionsAscending(IServiceFactory serviceFa
200200
new Customer {Name = "Random Name 1"}
201201
};
202202

203-
var options = new QueryOptions<Customer>().OrderBy(x => x.Name);
203+
var options = new QueryOptions<Customer>().OrderBy(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
204204

205205
Assert.Null(service.Get(x => x.Name.Contains("Random Name"))?.Name);
206206
Assert.Null(service.Get(options)?.Name);
@@ -523,7 +523,7 @@ private static async Task TestGetAsync(IServiceFactory serviceFactory)
523523

524524
const string name = "Random Name";
525525

526-
var options = new QueryOptions<Customer>();
526+
var options = new QueryOptions<Customer>().SatisfyBy(x => x.Name.Equals(name));
527527
var entity = new Customer {Name = name};
528528

529529
Assert.Null(await service.GetAsync(x => x.Name.Equals(name)));
@@ -549,7 +549,7 @@ private static async Task TestGetWithSortingOptionsDescendingAsync(IServiceFacto
549549
new Customer {Name = "Random Name 1"}
550550
};
551551

552-
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name);
552+
var options = new QueryOptions<Customer>().OrderByDescending(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
553553

554554
Assert.Null((await service.GetAsync(x => x.Name.Contains("Random Name")))?.Name);
555555
Assert.Null((await service.GetAsync(options))?.Name);
@@ -575,7 +575,7 @@ private static async Task TestGetWithSortingOptionsAscendingAsync(IServiceFactor
575575
new Customer {Name = "Random Name 1"}
576576
};
577577

578-
var options = new QueryOptions<Customer>().OrderBy(x => x.Name);
578+
var options = new QueryOptions<Customer>().OrderBy(x => x.Name).SatisfyBy(x => x.Name.Contains("Random Name"));
579579

580580
Assert.Null((await service.GetAsync(x => x.Name.Contains("Random Name")))?.Name);
581581
Assert.Null((await service.GetAsync(options))?.Name);

0 commit comments

Comments
 (0)