diff options
author | Pranav K <prkrishn@hotmail.com> | 2020-06-18 21:05:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 21:05:54 +0300 |
commit | a44c1ad78c54c0e9e5d584fbd0d0095ed420f3bf (patch) | |
tree | 85afd7ad0e8337c5f529d5b93382225221750604 /src | |
parent | d3f816a76674c186e90a94647168b5fcc0a984b7 (diff) |
Fix null reference errors in tests (#23091)
Fixes https://github.com/dotnet/aspnetcore/issues/22992
Diffstat (limited to 'src')
6 files changed, 21 insertions, 21 deletions
diff --git a/src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs b/src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs index d205f8efc2..e4af2032f5 100644 --- a/src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs +++ b/src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs @@ -164,7 +164,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal httpContext.Request.Headers.Add("header-name", "header-value"); // Will not be accessed - httpContext.Request.Form = null; + httpContext.Request.Form = null!; var options = new AntiforgeryOptions { @@ -191,7 +191,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal httpContext.Request.ContentType = "application/json"; // Will not be accessed - httpContext.Request.Form = null; + httpContext.Request.Form = null!; var options = new AntiforgeryOptions { diff --git a/src/HealthChecks/HealthChecks/test/DependencyInjection/ServiceCollectionExtensionsTest.cs b/src/HealthChecks/HealthChecks/test/DependencyInjection/ServiceCollectionExtensionsTest.cs index 4a191a365f..c715ce8833 100644 --- a/src/HealthChecks/HealthChecks/test/DependencyInjection/ServiceCollectionExtensionsTest.cs +++ b/src/HealthChecks/HealthChecks/test/DependencyInjection/ServiceCollectionExtensionsTest.cs @@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddHealthChecks(); // 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 => { Assert.Equal(ServiceLifetime.Singleton, actual.Lifetime); diff --git a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs index 7131f28bc2..6e907814d9 100644 --- a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs @@ -39,8 +39,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions [Fact] public void NullArguments_ArgumentNullException() { - var builder = new ApplicationBuilder(serviceProvider: null); - var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); + var builder = new ApplicationBuilder(serviceProvider: null!); + var noMiddleware = new ApplicationBuilder(serviceProvider: null!).Build(); var noOptions = new MapOptions(); Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", configuration: 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) { HttpContext context = CreateRequest(basePath, requestPath); - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.Map(matchPath, UseSuccess); var app = builder.Build(); await app.Invoke(context); @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public async Task PathMatchAction_BranchTaken(string matchPath, string basePath, string 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)); var app = builder.Build(); 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) { 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)); var app = builder.Build(); await app.Invoke(context); @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/foo/cho/")] 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] @@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public async Task PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.Map(matchPath, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public async Task PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.Map(matchPath, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions [Fact] public async Task ChainedRoutes_Success() { - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.Map("/route1", map => { map.Map("/subroute1", UseSuccess); diff --git a/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs b/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs index 1765859e02..c83bb47bcc 100644 --- a/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs @@ -48,8 +48,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions [Fact] public void NullArguments_ArgumentNullException() { - var builder = new ApplicationBuilder(serviceProvider: null); - var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); + var builder = new ApplicationBuilder(serviceProvider: null!); + var noMiddleware = new ApplicationBuilder(serviceProvider: null!).Build(); var noOptions = new MapWhenOptions(); Assert.Throws<ArgumentNullException>(() => builder.MapWhen(null!, UseNotImplemented)); Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, configuration: null!)); @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public async Task PredicateTrue_BranchTaken() { HttpContext context = CreateRequest(); - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.MapWhen(TruePredicate, UseSuccess); var app = builder.Build(); await app.Invoke(context); @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public async Task PredicateTrueAction_BranchTaken() { HttpContext context = CreateRequest(); - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.MapWhen(TruePredicate, UseSuccess); var app = builder.Build(); await app.Invoke(context); @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public async Task PredicateFalseAction_PassThrough() { HttpContext context = CreateRequest(); - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.MapWhen(FalsePredicate, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions [Fact] public async Task ChainedPredicates_Success() { - var builder = new ApplicationBuilder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null!); builder.MapWhen(TruePredicate, map1 => { map1.MapWhen((Predicate)FalsePredicate, UseNotImplemented); diff --git a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs index f67d23487f..f5724d28bc 100644 --- a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions set { _wrappedBuilder.ApplicationServices = value; } } - public IDictionary<string, object> Properties => _wrappedBuilder.Properties; + public IDictionary<string, object?> Properties => _wrappedBuilder.Properties; public IFeatureCollection ServerFeatures => _wrappedBuilder.ServerFeatures; public RequestDelegate Build() => _wrappedBuilder.Build(); public IApplicationBuilder New() => _wrappedBuilder.New(); @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions private static ApplicationBuilder CreateBuilder() { - return new ApplicationBuilder(serviceProvider: null); + return new ApplicationBuilder(serviceProvider: null!); } } } diff --git a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs index 2173df9138..478e592b7f 100644 --- a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs @@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions private static ApplicationBuilder CreateBuilder() { - return new ApplicationBuilder(serviceProvider: null); + return new ApplicationBuilder(serviceProvider: null!); } private static bool TruePredicate(HttpContext context) |