Fix null reference errors in tests (#23091)
Fixes https://github.com/dotnet/aspnetcore/issues/22992
This commit is contained in:
parent
d3f816a766
commit
a44c1ad78c
|
|
@ -164,7 +164,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal
|
||||||
httpContext.Request.Headers.Add("header-name", "header-value");
|
httpContext.Request.Headers.Add("header-name", "header-value");
|
||||||
|
|
||||||
// Will not be accessed
|
// Will not be accessed
|
||||||
httpContext.Request.Form = null;
|
httpContext.Request.Form = null!;
|
||||||
|
|
||||||
var options = new AntiforgeryOptions
|
var options = new AntiforgeryOptions
|
||||||
{
|
{
|
||||||
|
|
@ -191,7 +191,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal
|
||||||
httpContext.Request.ContentType = "application/json";
|
httpContext.Request.ContentType = "application/json";
|
||||||
|
|
||||||
// Will not be accessed
|
// Will not be accessed
|
||||||
httpContext.Request.Form = null;
|
httpContext.Request.Form = null!;
|
||||||
|
|
||||||
var options = new AntiforgeryOptions
|
var options = new AntiforgeryOptions
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.AddHealthChecks();
|
services.AddHealthChecks();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(services.OrderBy(s => s.ServiceType.FullName).ThenBy(s => s.ImplementationType.FullName),
|
Assert.Collection(services.OrderBy(s => s.ServiceType.FullName).ThenBy(s => s.ImplementationType!.FullName),
|
||||||
actual =>
|
actual =>
|
||||||
{
|
{
|
||||||
Assert.Equal(ServiceLifetime.Singleton, actual.Lifetime);
|
Assert.Equal(ServiceLifetime.Singleton, actual.Lifetime);
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NullArguments_ArgumentNullException()
|
public void NullArguments_ArgumentNullException()
|
||||||
{
|
{
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build();
|
var noMiddleware = new ApplicationBuilder(serviceProvider: null!).Build();
|
||||||
var noOptions = new MapOptions();
|
var noOptions = new MapOptions();
|
||||||
Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", configuration: null!));
|
Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", configuration: null!));
|
||||||
Assert.Throws<ArgumentNullException>(() => new MapMiddleware(noMiddleware, null!));
|
Assert.Throws<ArgumentNullException>(() => new MapMiddleware(noMiddleware, null!));
|
||||||
|
|
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath)
|
public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath)
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest(basePath, requestPath);
|
HttpContext context = CreateRequest(basePath, requestPath);
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.Map(matchPath, UseSuccess);
|
builder.Map(matchPath, UseSuccess);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.Invoke(context);
|
await app.Invoke(context);
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath)
|
public async Task PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath)
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest(basePath, requestPath);
|
HttpContext context = CreateRequest(basePath, requestPath);
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.Map(matchPath, subBuilder => subBuilder.Run(Success));
|
builder.Map(matchPath, subBuilder => subBuilder.Run(Success));
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.Invoke(context);
|
await app.Invoke(context);
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PathMatchAction_BranchTaken_WithPreserveMatchedPathSegment(string matchPath, string basePath, string requestPath)
|
public async Task PathMatchAction_BranchTaken_WithPreserveMatchedPathSegment(string matchPath, string basePath, string requestPath)
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest(basePath, requestPath);
|
HttpContext context = CreateRequest(basePath, requestPath);
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.Map(matchPath, true, subBuilder => subBuilder.Run(Success));
|
builder.Map(matchPath, true, subBuilder => subBuilder.Run(Success));
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.Invoke(context);
|
await app.Invoke(context);
|
||||||
|
|
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
[InlineData("/foo/cho/")]
|
[InlineData("/foo/cho/")]
|
||||||
public void MatchPathWithTrailingSlashThrowsException(string matchPath)
|
public void MatchPathWithTrailingSlashThrowsException(string matchPath)
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null).Map(matchPath, map => { }).Build());
|
Assert.Throws<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null!).Map(matchPath, map => { }).Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath)
|
public async Task PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath)
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest(basePath, requestPath);
|
HttpContext context = CreateRequest(basePath, requestPath);
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.Map(matchPath, UseNotImplemented);
|
builder.Map(matchPath, UseNotImplemented);
|
||||||
builder.Run(Success);
|
builder.Run(Success);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath)
|
public async Task PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath)
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest(basePath, requestPath);
|
HttpContext context = CreateRequest(basePath, requestPath);
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.Map(matchPath, UseNotImplemented);
|
builder.Map(matchPath, UseNotImplemented);
|
||||||
builder.Run(Success);
|
builder.Run(Success);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ChainedRoutes_Success()
|
public async Task ChainedRoutes_Success()
|
||||||
{
|
{
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.Map("/route1", map =>
|
builder.Map("/route1", map =>
|
||||||
{
|
{
|
||||||
map.Map("/subroute1", UseSuccess);
|
map.Map("/subroute1", UseSuccess);
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NullArguments_ArgumentNullException()
|
public void NullArguments_ArgumentNullException()
|
||||||
{
|
{
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build();
|
var noMiddleware = new ApplicationBuilder(serviceProvider: null!).Build();
|
||||||
var noOptions = new MapWhenOptions();
|
var noOptions = new MapWhenOptions();
|
||||||
Assert.Throws<ArgumentNullException>(() => builder.MapWhen(null!, UseNotImplemented));
|
Assert.Throws<ArgumentNullException>(() => builder.MapWhen(null!, UseNotImplemented));
|
||||||
Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, configuration: null!));
|
Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, configuration: null!));
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PredicateTrue_BranchTaken()
|
public async Task PredicateTrue_BranchTaken()
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest();
|
HttpContext context = CreateRequest();
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.MapWhen(TruePredicate, UseSuccess);
|
builder.MapWhen(TruePredicate, UseSuccess);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.Invoke(context);
|
await app.Invoke(context);
|
||||||
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PredicateTrueAction_BranchTaken()
|
public async Task PredicateTrueAction_BranchTaken()
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest();
|
HttpContext context = CreateRequest();
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.MapWhen(TruePredicate, UseSuccess);
|
builder.MapWhen(TruePredicate, UseSuccess);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.Invoke(context);
|
await app.Invoke(context);
|
||||||
|
|
@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
public async Task PredicateFalseAction_PassThrough()
|
public async Task PredicateFalseAction_PassThrough()
|
||||||
{
|
{
|
||||||
HttpContext context = CreateRequest();
|
HttpContext context = CreateRequest();
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.MapWhen(FalsePredicate, UseNotImplemented);
|
builder.MapWhen(FalsePredicate, UseNotImplemented);
|
||||||
builder.Run(Success);
|
builder.Run(Success);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ChainedPredicates_Success()
|
public async Task ChainedPredicates_Success()
|
||||||
{
|
{
|
||||||
var builder = new ApplicationBuilder(serviceProvider: null);
|
var builder = new ApplicationBuilder(serviceProvider: null!);
|
||||||
builder.MapWhen(TruePredicate, map1 =>
|
builder.MapWhen(TruePredicate, map1 =>
|
||||||
{
|
{
|
||||||
map1.MapWhen((Predicate)FalsePredicate, UseNotImplemented);
|
map1.MapWhen((Predicate)FalsePredicate, UseNotImplemented);
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
set { _wrappedBuilder.ApplicationServices = value; }
|
set { _wrappedBuilder.ApplicationServices = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDictionary<string, object> Properties => _wrappedBuilder.Properties;
|
public IDictionary<string, object?> Properties => _wrappedBuilder.Properties;
|
||||||
public IFeatureCollection ServerFeatures => _wrappedBuilder.ServerFeatures;
|
public IFeatureCollection ServerFeatures => _wrappedBuilder.ServerFeatures;
|
||||||
public RequestDelegate Build() => _wrappedBuilder.Build();
|
public RequestDelegate Build() => _wrappedBuilder.Build();
|
||||||
public IApplicationBuilder New() => _wrappedBuilder.New();
|
public IApplicationBuilder New() => _wrappedBuilder.New();
|
||||||
|
|
@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
|
|
||||||
private static ApplicationBuilder CreateBuilder()
|
private static ApplicationBuilder CreateBuilder()
|
||||||
{
|
{
|
||||||
return new ApplicationBuilder(serviceProvider: null);
|
return new ApplicationBuilder(serviceProvider: null!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions
|
||||||
|
|
||||||
private static ApplicationBuilder CreateBuilder()
|
private static ApplicationBuilder CreateBuilder()
|
||||||
{
|
{
|
||||||
return new ApplicationBuilder(serviceProvider: null);
|
return new ApplicationBuilder(serviceProvider: null!);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TruePredicate(HttpContext context)
|
private static bool TruePredicate(HttpContext context)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue