Skip to content

Commit a50040c

Browse files
committed
build: resolve ancillary project warnings
1 parent 492407a commit a50040c

26 files changed

+124
-120
lines changed

QueryKit.IntegrationTests/TestFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class TestFixtureCollection : ICollectionFixture<TestFixture> {}
2121

2222
public class TestFixture : IAsyncLifetime
2323
{
24-
public static IServiceScopeFactory BaseScopeFactory;
25-
private PostgreSqlContainer _dbContainer;
24+
public static IServiceScopeFactory BaseScopeFactory = null!;
25+
private PostgreSqlContainer _dbContainer = null!;
2626

2727
public async Task InitializeAsync()
2828
{
@@ -43,7 +43,7 @@ public async Task InitializeAsync()
4343
services.ReplaceServiceWithSingletonMock<IHttpContextAccessor>();
4444

4545
var provider = services.BuildServiceProvider();
46-
BaseScopeFactory = provider.GetService<IServiceScopeFactory>();
46+
BaseScopeFactory = provider.GetRequiredService<IServiceScopeFactory>();
4747
SetupDateAssertions();
4848
}
4949

@@ -53,7 +53,7 @@ private static async Task RunMigration(string connectionString)
5353
.UseNpgsql(connectionString)
5454
.Options;
5555
var context = new TestingDbContext(options);
56-
await context?.Database?.MigrateAsync();
56+
await context.Database.MigrateAsync();
5757
}
5858

5959
public async Task DisposeAsync()

QueryKit.IntegrationTests/TestingServiceScope.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ public TestingServiceScope()
1616
_scope = BaseScopeFactory.CreateScope();
1717
}
1818

19-
public TScopedService GetService<TScopedService>()
19+
public TScopedService GetService<TScopedService>() where TScopedService : notnull
2020
{
21-
var service = _scope.ServiceProvider.GetService<TScopedService>();
21+
var service = _scope.ServiceProvider.GetRequiredService<TScopedService>();
2222
return service;
2323
}
2424

2525
public async Task<TResponse> SendAsync<TResponse>(IRequest<TResponse> request)
2626
{
27-
var mediator = _scope.ServiceProvider.GetService<ISender>();
27+
var mediator = _scope.ServiceProvider.GetRequiredService<ISender>();
2828
return await mediator.Send(request);
2929
}
3030

31-
public async Task<TEntity> FindAsync<TEntity>(params object[] keyValues)
31+
public async Task<TEntity?> FindAsync<TEntity>(params object[] keyValues)
3232
where TEntity : class
3333
{
34-
var context = _scope.ServiceProvider.GetService<TestingDbContext>();
34+
var context = _scope.ServiceProvider.GetRequiredService<TestingDbContext>();
3535
return await context.FindAsync<TEntity>(keyValues);
3636
}
3737

3838
public async Task AddAsync<TEntity>(TEntity entity)
3939
where TEntity : class
4040
{
41-
var context = _scope.ServiceProvider.GetService<TestingDbContext>();
41+
var context = _scope.ServiceProvider.GetRequiredService<TestingDbContext>();
4242
context.Add(entity);
4343

4444
await context.SaveChangesAsync();
@@ -48,7 +48,7 @@ public async Task<T> ExecuteScopeAsync<T>(Func<IServiceProvider, Task<T>> action
4848
=> await action(_scope.ServiceProvider);
4949

5050
public Task<T> ExecuteDbContextAsync<T>(Func<TestingDbContext, Task<T>> action)
51-
=> ExecuteScopeAsync(sp => action(sp.GetService<TestingDbContext>()));
51+
=> ExecuteScopeAsync(sp => action(sp.GetRequiredService<TestingDbContext>()));
5252

5353
public Task<int> InsertAsync<T>(params T[] entities) where T : class
5454
{

QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ public async Task can_filter_with_child_props()
866866
var queryablePeople = testingServiceScope.DbContext().People;
867867
var config = new QueryKitConfiguration(config =>
868868
{
869-
config.Property<TestingPerson>(x => x.Email.Value).HasQueryName("email");
869+
config.Property<TestingPerson>(x => x.Email!.Value!).HasQueryName("email");
870870
});
871871
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config);
872872
var people = await appliedQueryable.ToListAsync();
@@ -1171,7 +1171,7 @@ public async Task can_handle_case_insensitive_in_for_string()
11711171
var fakePersonTwo = new FakeTestingPersonBuilder().Build();
11721172
await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo);
11731173

1174-
var input = $"""Title ^^* ["{fakePersonOne.Title.ToUpper()}"]""";
1174+
var input = $"""Title ^^* ["{fakePersonOne.Title!.ToUpper()}"]""";
11751175

11761176
// Act
11771177
var queryablePeople = testingServiceScope.DbContext().People;
@@ -1192,7 +1192,7 @@ public async Task can_handle_case_sensitive_in_for_string()
11921192
var fakePersonOne = new FakeTestingPersonBuilder().Build();
11931193
await testingServiceScope.InsertAsync(fakePersonOne);
11941194

1195-
var input = $"""Title ^^ ["{fakePersonOne.Title.ToUpper()}"]""";
1195+
var input = $"""Title ^^ ["{fakePersonOne.Title!.ToUpper()}"]""";
11961196

11971197
// Act
11981198
var queryablePeople = testingServiceScope.DbContext().People;
@@ -1238,7 +1238,7 @@ public async Task can_handle_case_insensitive_not_in_for_string()
12381238
var fakePersonTwo = new FakeTestingPersonBuilder().Build();
12391239
await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo);
12401240

1241-
var input = $"""Title !^^* ["{fakePersonOne.Title.ToUpper()}"]""";
1241+
var input = $"""Title !^^* ["{fakePersonOne.Title!.ToUpper()}"]""";
12421242

12431243
// Act
12441244
var queryablePeople = testingServiceScope.DbContext().People;
@@ -1310,9 +1310,9 @@ public async Task can_filter_on_child_entity()
13101310
private class RecipeDto
13111311
{
13121312
public Guid Id { get; set; }
1313-
public string Title { get; set; }
1314-
public string AuthorName { get; set; }
1315-
public string AuthorInfo { get; set; }
1313+
public string Title { get; set; } = null!;
1314+
public string AuthorName { get; set; } = null!;
1315+
public string AuthorInfo { get; set; } = null!;
13161316
}
13171317
[Fact]
13181318
public async Task can_filter_on_projection()
@@ -1486,7 +1486,7 @@ public async Task can_filter_with_child_props_for_complex_property()
14861486
var queryableRecipes = testingServiceScope.DbContext().Recipes;
14871487
var config = new QueryKitConfiguration(config =>
14881488
{
1489-
config.Property<Recipe>(x => x.CollectionEmail.Value);
1489+
config.Property<Recipe>(x => x.CollectionEmail!.Value!);
14901490
});
14911491
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
14921492
var people = await appliedQueryable.ToListAsync();
@@ -1515,7 +1515,7 @@ public async Task can_filter_with_child_props_for_aliased_complex_property()
15151515
var queryableRecipes = testingServiceScope.DbContext().Recipes;
15161516
var config = new QueryKitConfiguration(config =>
15171517
{
1518-
config.Property<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
1518+
config.Property<Recipe>(x => x.CollectionEmail!.Value!).HasQueryName("email");
15191519
});
15201520
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
15211521
var people = await appliedQueryable.ToListAsync();
@@ -1544,7 +1544,7 @@ public async Task can_filter_with_child_props_for_null_aliased_complex_property(
15441544
var queryableRecipes = testingServiceScope.DbContext().Recipes;
15451545
var config = new QueryKitConfiguration(config =>
15461546
{
1547-
config.Property<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
1547+
config.Property<Recipe>(x => x.CollectionEmail!.Value!).HasQueryName("email");
15481548
});
15491549
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
15501550
var people = await appliedQueryable.ToListAsync();
@@ -1573,7 +1573,7 @@ public async Task can_filter_with_child_props_for_complex_property_with_alias()
15731573
var queryableRecipes = testingServiceScope.DbContext().Recipes;
15741574
var config = new QueryKitConfiguration(config =>
15751575
{
1576-
config.Property<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
1576+
config.Property<Recipe>(x => x.CollectionEmail!.Value!).HasQueryName("email");
15771577
});
15781578
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
15791579
var people = await appliedQueryable.ToListAsync();
@@ -2598,10 +2598,10 @@ public async Task can_filter_with_custom_operation_complex_business_logic()
25982598

25992599
var config = new QueryKitConfiguration(config =>
26002600
{
2601-
config.CustomOperation<TestingPerson>((x, op, value) =>
2602-
(bool)value ?
2603-
(x.Age > 30 && x.Rating > 7 && x.FirstName.Contains("VIP")) :
2604-
!(x.Age > 30 && x.Rating > 7 && x.FirstName.Contains("VIP")))
2601+
config.CustomOperation<TestingPerson>((x, op, value) =>
2602+
(bool)value ?
2603+
(x.Age > 30 && x.Rating > 7 && x.FirstName!.Contains("VIP")) :
2604+
!(x.Age > 30 && x.Rating > 7 && x.FirstName!.Contains("VIP")))
26052605
.HasQueryName("isVipCustomer");
26062606
});
26072607

@@ -3651,11 +3651,13 @@ public async Task can_filter_with_derived_property_using_not_equal_on_child_navi
36513651
var input = $"""authorInfo == "John_{uniqueId}" && Title == "RecipeWithAuthor_{uniqueId}" """;
36523652
var config = new QueryKitConfiguration(config =>
36533653
{
3654-
config.DerivedProperty<Recipe>(x =>
3655-
x.Author != null
3656-
? x.Author.Name
3654+
#pragma warning disable CS8603 // Possible null reference return - intentional for this test
3655+
config.DerivedProperty<Recipe>(x =>
3656+
x.Author != null
3657+
? x.Author.Name
36573658
: null)
36583659
.HasQueryName("authorInfo");
3660+
#pragma warning restore CS8603
36593661
});
36603662

36613663
// Act
@@ -3824,12 +3826,14 @@ public async Task can_filter_with_derived_property_containing_complex_conditiona
38243826
// Create config with conditional derived property
38253827
var config = new QueryKitConfiguration(config =>
38263828
{
3829+
#pragma warning disable CS8603 // Possible null reference return - intentional for this test
38273830
config.DerivedProperty<TestingPerson>(x =>
38283831
x.Date.HasValue
38293832
? (x.Date.Value.ToDateTime(TimeOnly.MinValue) -
38303833
DateOnly.FromDateTime(DateTime.UtcNow).ToDateTime(TimeOnly.MinValue)).Days
38313834
: (int?)null
38323835
).HasQueryName("daysFromNow");
3836+
#pragma warning restore CS8603
38333837
});
38343838

38353839
// Act & Assert - Should not throw "Unsupported value '0' for type 'Object'"

QueryKit.IntegrationTests/Tests/DatabaseSortingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public async Task can_sort_by_derived_property_using_complex_patient_like_scenar
343343

344344
// Act - Sort by the derived property (this previously caused Entity Framework translation errors)
345345
var queryablePeople = testingServiceScope.DbContext().People
346-
.Where(p => p.Title.Contains($"Patient") && p.Title.Contains(uniqueId));
346+
.Where(p => p.Title != null && p.Title.Contains("Patient") && p.Title.Contains(uniqueId));
347347

348348
// This should NOT generate LeftJoin with `.OrderBy(a => (object)a.Inner)' error
349349
var appliedQueryable = queryablePeople.ApplyQueryKitSort("patient asc", config);

QueryKit.IntegrationTests/Tests/GuidFilterBugTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace QueryKit.IntegrationTests.Tests;
88
using WebApiTestProject.Entities;
99
using Xunit.Abstractions;
1010

11-
public class GuidFilterBugTests(ITestOutputHelper testOutputHelper) : TestBase
11+
public class GuidFilterBugTests : TestBase
1212
{
1313
[Fact]
1414
public async Task guid_filter_with_converted_property_should_reproduce_ef_core_translation_error()
@@ -146,7 +146,7 @@ public async Task guid_filter_with_inequality_and_complex_conditions_reproduces_
146146
// Configure QueryKit similar to user's scenario with custom query names
147147
var config = new QueryKitConfiguration(config =>
148148
{
149-
config.Property<TestingPerson>(x => x.Title)
149+
config.Property<TestingPerson>(x => x.Title!)
150150
.HasQueryName("status");
151151
config.Property<TestingPerson>(x => x.Id)
152152
.HasQueryName("id");

QueryKit.IntegrationTests/Tests/HasConversionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace QueryKit.IntegrationTests.Tests;
88
using WebApiTestProject.Entities;
99
using Xunit.Abstractions;
1010

11-
public class HasConversionTests(ITestOutputHelper testOutputHelper) : TestBase
11+
public class HasConversionTests : TestBase
1212
{
1313
[Fact]
1414
public async Task can_filter_by_email_with_has_conversion()

QueryKit.UnitTests/CustomFilterPropertyTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void can_have_custom_prop_name_for_string()
6969

7070
var config = new QueryKitConfiguration(config =>
7171
{
72-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
72+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
7373
});
7474
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
7575
filterExpression.ToString().Should().Be($"""x => (x.Title == "{value}")""");
@@ -84,7 +84,7 @@ public void can_handle_alias_in_value()
8484

8585
var config = new QueryKitConfiguration(config =>
8686
{
87-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
87+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
8888
});
8989
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
9090
filterExpression.ToString().Should().Be($"""x => (x.Title == "{value} with special_value")""");
@@ -99,7 +99,7 @@ public void can_handle_alias_in_value_with_operator_after_it()
9999

100100
var config = new QueryKitConfiguration(config =>
101101
{
102-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
102+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
103103
});
104104
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
105105
filterExpression.ToString().Should().Be($"""x => (x.Title == "{value} with special_value @=* a thing")""");
@@ -115,7 +115,7 @@ public void can_have_custom_prop_name_for_multiple_props()
115115

116116
var config = new QueryKitConfiguration(config =>
117117
{
118-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
118+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
119119
config.Property<TestingPerson>(x => x.Id).HasQueryName("identifier");
120120
});
121121
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
@@ -132,7 +132,7 @@ public void can_have_custom_prop_name_for_some_props()
132132

133133
var config = new QueryKitConfiguration(config =>
134134
{
135-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
135+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
136136
});
137137
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
138138
filterExpression.ToString().Should().Be($"""x => ((x.Title == "{stringValue}") OrElse (x.Id == {guidValue}))""");
@@ -147,7 +147,7 @@ public void can_handle_case_insensitive_custom_props()
147147

148148
var config = new QueryKitConfiguration(config =>
149149
{
150-
config.Property<TestingPerson>(x => x.Title).HasQueryName("specialtitle");
150+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("specialtitle");
151151
});
152152
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
153153
filterExpression.ToString().Should().Be($"""x => (x.Title == "{value}")""");
@@ -163,7 +163,7 @@ public void can_have_custom_prop_excluded_from_filter()
163163

164164
var config = new QueryKitConfiguration(config =>
165165
{
166-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
166+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
167167
config.Property<TestingPerson>(x => x.Id).PreventFilter();
168168
});
169169
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
@@ -180,7 +180,7 @@ public void can_have_custom_prop_excluded_from_filter_with_custom_propname()
180180

181181
var config = new QueryKitConfiguration(config =>
182182
{
183-
config.Property<TestingPerson>(x => x.Title).HasQueryName("special_title");
183+
config.Property<TestingPerson>(x => x.Title!).HasQueryName("special_title");
184184
config.Property<TestingPerson>(x => x.Id).HasQueryName("identifier").PreventFilter();
185185
});
186186
var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);

0 commit comments

Comments
 (0)