Skip to content

Commit a44c1ad

Browse files
authored
Fix null reference errors in tests (#23091)
Fixes #22992
1 parent d3f816a commit a44c1ad

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public async Task GetRequestTokens_NonFormContentType_UsesHeaderToken()
164164
httpContext.Request.Headers.Add("header-name", "header-value");
165165

166166
// Will not be accessed
167-
httpContext.Request.Form = null;
167+
httpContext.Request.Form = null!;
168168

169169
var options = new AntiforgeryOptions
170170
{
@@ -191,7 +191,7 @@ public async Task GetRequestTokens_NoHeaderToken_NonFormContentType_ReturnsNullT
191191
httpContext.Request.ContentType = "application/json";
192192

193193
// Will not be accessed
194-
httpContext.Request.Form = null;
194+
httpContext.Request.Form = null!;
195195

196196
var options = new AntiforgeryOptions
197197
{

src/HealthChecks/HealthChecks/test/DependencyInjection/ServiceCollectionExtensionsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void AddHealthChecks_RegistersPublisherService_WhenOtherHostedServicesReg
5353
services.AddHealthChecks();
5454

5555
// Assert
56-
Assert.Collection(services.OrderBy(s => s.ServiceType.FullName).ThenBy(s => s.ImplementationType.FullName),
56+
Assert.Collection(services.OrderBy(s => s.ServiceType.FullName).ThenBy(s => s.ImplementationType!.FullName),
5757
actual =>
5858
{
5959
Assert.Equal(ServiceLifetime.Singleton, actual.Lifetime);

src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ private static void UseNotImplemented(IApplicationBuilder app)
3939
[Fact]
4040
public void NullArguments_ArgumentNullException()
4141
{
42-
var builder = new ApplicationBuilder(serviceProvider: null);
43-
var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build();
42+
var builder = new ApplicationBuilder(serviceProvider: null!);
43+
var noMiddleware = new ApplicationBuilder(serviceProvider: null!).Build();
4444
var noOptions = new MapOptions();
4545
Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", configuration: null!));
4646
Assert.Throws<ArgumentNullException>(() => new MapMiddleware(noMiddleware, null!));
@@ -57,7 +57,7 @@ public void NullArguments_ArgumentNullException()
5757
public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath)
5858
{
5959
HttpContext context = CreateRequest(basePath, requestPath);
60-
var builder = new ApplicationBuilder(serviceProvider: null);
60+
var builder = new ApplicationBuilder(serviceProvider: null!);
6161
builder.Map(matchPath, UseSuccess);
6262
var app = builder.Build();
6363
await app.Invoke(context);
@@ -85,7 +85,7 @@ public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, s
8585
public async Task PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath)
8686
{
8787
HttpContext context = CreateRequest(basePath, requestPath);
88-
var builder = new ApplicationBuilder(serviceProvider: null);
88+
var builder = new ApplicationBuilder(serviceProvider: null!);
8989
builder.Map(matchPath, subBuilder => subBuilder.Run(Success));
9090
var app = builder.Build();
9191
await app.Invoke(context);
@@ -113,7 +113,7 @@ public async Task PathMatchAction_BranchTaken(string matchPath, string basePath,
113113
public async Task PathMatchAction_BranchTaken_WithPreserveMatchedPathSegment(string matchPath, string basePath, string requestPath)
114114
{
115115
HttpContext context = CreateRequest(basePath, requestPath);
116-
var builder = new ApplicationBuilder(serviceProvider: null);
116+
var builder = new ApplicationBuilder(serviceProvider: null!);
117117
builder.Map(matchPath, true, subBuilder => subBuilder.Run(Success));
118118
var app = builder.Build();
119119
await app.Invoke(context);
@@ -129,7 +129,7 @@ public async Task PathMatchAction_BranchTaken_WithPreserveMatchedPathSegment(str
129129
[InlineData("/foo/cho/")]
130130
public void MatchPathWithTrailingSlashThrowsException(string matchPath)
131131
{
132-
Assert.Throws<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null).Map(matchPath, map => { }).Build());
132+
Assert.Throws<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null!).Map(matchPath, map => { }).Build());
133133
}
134134

135135
[Theory]
@@ -143,7 +143,7 @@ public void MatchPathWithTrailingSlashThrowsException(string matchPath)
143143
public async Task PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath)
144144
{
145145
HttpContext context = CreateRequest(basePath, requestPath);
146-
var builder = new ApplicationBuilder(serviceProvider: null);
146+
var builder = new ApplicationBuilder(serviceProvider: null!);
147147
builder.Map(matchPath, UseNotImplemented);
148148
builder.Run(Success);
149149
var app = builder.Build();
@@ -165,7 +165,7 @@ public async Task PathMismatchFunc_PassedThrough(string matchPath, string basePa
165165
public async Task PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath)
166166
{
167167
HttpContext context = CreateRequest(basePath, requestPath);
168-
var builder = new ApplicationBuilder(serviceProvider: null);
168+
var builder = new ApplicationBuilder(serviceProvider: null!);
169169
builder.Map(matchPath, UseNotImplemented);
170170
builder.Run(Success);
171171
var app = builder.Build();
@@ -179,7 +179,7 @@ public async Task PathMismatchAction_PassedThrough(string matchPath, string base
179179
[Fact]
180180
public async Task ChainedRoutes_Success()
181181
{
182-
var builder = new ApplicationBuilder(serviceProvider: null);
182+
var builder = new ApplicationBuilder(serviceProvider: null!);
183183
builder.Map("/route1", map =>
184184
{
185185
map.Map("/subroute1", UseSuccess);

src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ private bool FalsePredicate(HttpContext context)
4848
[Fact]
4949
public void NullArguments_ArgumentNullException()
5050
{
51-
var builder = new ApplicationBuilder(serviceProvider: null);
52-
var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build();
51+
var builder = new ApplicationBuilder(serviceProvider: null!);
52+
var noMiddleware = new ApplicationBuilder(serviceProvider: null!).Build();
5353
var noOptions = new MapWhenOptions();
5454
Assert.Throws<ArgumentNullException>(() => builder.MapWhen(null!, UseNotImplemented));
5555
Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, configuration: null!));
@@ -63,7 +63,7 @@ public void NullArguments_ArgumentNullException()
6363
public async Task PredicateTrue_BranchTaken()
6464
{
6565
HttpContext context = CreateRequest();
66-
var builder = new ApplicationBuilder(serviceProvider: null);
66+
var builder = new ApplicationBuilder(serviceProvider: null!);
6767
builder.MapWhen(TruePredicate, UseSuccess);
6868
var app = builder.Build();
6969
await app.Invoke(context);
@@ -75,7 +75,7 @@ public async Task PredicateTrue_BranchTaken()
7575
public async Task PredicateTrueAction_BranchTaken()
7676
{
7777
HttpContext context = CreateRequest();
78-
var builder = new ApplicationBuilder(serviceProvider: null);
78+
var builder = new ApplicationBuilder(serviceProvider: null!);
7979
builder.MapWhen(TruePredicate, UseSuccess);
8080
var app = builder.Build();
8181
await app.Invoke(context);
@@ -87,7 +87,7 @@ public async Task PredicateTrueAction_BranchTaken()
8787
public async Task PredicateFalseAction_PassThrough()
8888
{
8989
HttpContext context = CreateRequest();
90-
var builder = new ApplicationBuilder(serviceProvider: null);
90+
var builder = new ApplicationBuilder(serviceProvider: null!);
9191
builder.MapWhen(FalsePredicate, UseNotImplemented);
9292
builder.Run(Success);
9393
var app = builder.Build();
@@ -99,7 +99,7 @@ public async Task PredicateFalseAction_PassThrough()
9999
[Fact]
100100
public async Task ChainedPredicates_Success()
101101
{
102-
var builder = new ApplicationBuilder(serviceProvider: null);
102+
var builder = new ApplicationBuilder(serviceProvider: null!);
103103
builder.MapWhen(TruePredicate, map1 =>
104104
{
105105
map1.MapWhen((Predicate)FalsePredicate, UseNotImplemented);

src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public IServiceProvider ApplicationServices
5454
set { _wrappedBuilder.ApplicationServices = value; }
5555
}
5656

57-
public IDictionary<string, object> Properties => _wrappedBuilder.Properties;
57+
public IDictionary<string, object?> Properties => _wrappedBuilder.Properties;
5858
public IFeatureCollection ServerFeatures => _wrappedBuilder.ServerFeatures;
5959
public RequestDelegate Build() => _wrappedBuilder.Build();
6060
public IApplicationBuilder New() => _wrappedBuilder.New();
@@ -163,7 +163,7 @@ private static HttpContext CreateRequest(string pathBase, string requestPath)
163163

164164
private static ApplicationBuilder CreateBuilder()
165165
{
166-
return new ApplicationBuilder(serviceProvider: null);
166+
return new ApplicationBuilder(serviceProvider: null!);
167167
}
168168
}
169169
}

src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static HttpContext CreateContext()
111111

112112
private static ApplicationBuilder CreateBuilder()
113113
{
114-
return new ApplicationBuilder(serviceProvider: null);
114+
return new ApplicationBuilder(serviceProvider: null!);
115115
}
116116

117117
private static bool TruePredicate(HttpContext context)

0 commit comments

Comments
 (0)