From bda22253e9800e6aea8c6a83096c09075e8cfea8 Mon Sep 17 00:00:00 2001 From: Kahbazi Date: Mon, 28 Oct 2019 21:16:56 +0330 Subject: [PATCH] Make MapPathMiddlewareTests async (#15376) --- .../test/MapPathMiddlewareTests.cs | 28 +++++++++---------- .../test/MapPredicateMiddlewareTests.cs | 16 +++++------ .../test/UsePathBaseExtensionsTests.cs | 26 ++++++++--------- .../test/UseWhenExtensionsTests.cs | 12 ++++---- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs index 47637a5a54..f9d935b086 100644 --- a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs @@ -54,13 +54,13 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/foo", "/Bar", "/foo/cho/")] [InlineData("/foo/cho", "/Bar", "/foo/cho")] [InlineData("/foo/cho", "/Bar", "/foo/cho/do")] - public void PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath) + public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, UseSuccess); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(basePath, context.Request.PathBase.Value); @@ -82,13 +82,13 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/foo", "/Bar", "/Foo/Cho/")] [InlineData("/foo/cho", "/Bar", "/Foo/Cho")] [InlineData("/foo/cho", "/Bar", "/Foo/Cho/do")] - public void PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath) + public async Task PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, subBuilder => subBuilder.Run(Success)); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(basePath + requestPath.Substring(0, matchPath.Length), (string)context.Items["test.PathBase"]); @@ -140,14 +140,14 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/foo", "/foo", "/bar")] [InlineData("/foo", "", "/bar/foo")] [InlineData("/foo/bar", "/foo", "/bar")] - public void PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath) + public async Task PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, UseNotImplemented); builder.Run(Success); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(basePath, context.Request.PathBase.Value); @@ -162,14 +162,14 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/foo", "/foo", "/bar")] [InlineData("/foo", "", "/bar/foo")] [InlineData("/foo/bar", "/foo", "/bar")] - public void PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath) + public async Task PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, UseNotImplemented); builder.Run(Success); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(basePath, context.Request.PathBase.Value); @@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions } [Fact] - public void ChainedRoutes_Success() + public async Task ChainedRoutes_Success() { var builder = new ApplicationBuilder(serviceProvider: null); builder.Map("/route1", map => @@ -189,28 +189,28 @@ namespace Microsoft.AspNetCore.Builder.Extensions var app = builder.Build(); HttpContext context = CreateRequest(string.Empty, "/route1"); - Assert.Throws(() => app.Invoke(context).Wait()); + await Assert.ThrowsAsync(() => app.Invoke(context)); context = CreateRequest(string.Empty, "/route1/subroute1"); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(string.Empty, context.Request.PathBase.Value); Assert.Equal("/route1/subroute1", context.Request.Path.Value); context = CreateRequest(string.Empty, "/route2"); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(404, context.Response.StatusCode); Assert.Equal(string.Empty, context.Request.PathBase.Value); Assert.Equal("/route2", context.Request.Path.Value); context = CreateRequest(string.Empty, "/route2/subroute2"); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(string.Empty, context.Request.PathBase.Value); Assert.Equal("/route2/subroute2", context.Request.Path.Value); context = CreateRequest(string.Empty, "/route2/subroute2/subsub2"); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); Assert.Equal(string.Empty, context.Request.PathBase.Value); Assert.Equal("/route2/subroute2/subsub2", context.Request.Path.Value); diff --git a/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs b/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs index 9274ab4207..048d522579 100644 --- a/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs @@ -61,44 +61,44 @@ namespace Microsoft.AspNetCore.Builder.Extensions } [Fact] - public void PredicateTrue_BranchTaken() + public async Task PredicateTrue_BranchTaken() { HttpContext context = CreateRequest(); var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(TruePredicate, UseSuccess); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); } [Fact] - public void PredicateTrueAction_BranchTaken() + public async Task PredicateTrueAction_BranchTaken() { HttpContext context = CreateRequest(); var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(TruePredicate, UseSuccess); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); } [Fact] - public void PredicateFalseAction_PassThrough() + public async Task PredicateFalseAction_PassThrough() { HttpContext context = CreateRequest(); var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(FalsePredicate, UseNotImplemented); builder.Run(Success); var app = builder.Build(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); } [Fact] - public void ChainedPredicates_Success() + public async Task ChainedPredicates_Success() { var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(TruePredicate, map1 => @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions var app = builder.Build(); HttpContext context = CreateRequest(); - app.Invoke(context).Wait(); + await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); } diff --git a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs index 4b8e9d71cb..e5f7903bc5 100644 --- a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -76,9 +76,9 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/base/more", "/oldbase", "/base/more", "/oldbase/base/more", "")] [InlineData("/base/more", "/oldbase", "/base/more/something", "/oldbase/base/more", "/something")] [InlineData("/base/more", "/oldbase", "/base/more/something/", "/oldbase/base/more", "/something/")] - public void RequestPathBaseContainingPathBase_IsSplit(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) + public Task RequestPathBaseContainingPathBase_IsSplit(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) { - TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); + return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); } [Theory] @@ -90,9 +90,9 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/base", "/oldbase", "/baseandsomething", "/oldbase", "/baseandsomething")] [InlineData("/base", "/oldbase", "/ba", "/oldbase", "/ba")] [InlineData("/base", "/oldbase", "/ba/se", "/oldbase", "/ba/se")] - public void RequestPathBaseNotContainingPathBase_IsNotSplit(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) + public Task RequestPathBaseNotContainingPathBase_IsNotSplit(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) { - TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); + return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); } [Theory] @@ -106,17 +106,17 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/base", "/oldbase", "/base/", "/oldbase/base", "/")] [InlineData("/base/", "/oldbase", "/base", "/oldbase/base", "")] [InlineData("/base/", "/oldbase", "/base/", "/oldbase/base", "/")] - public void PathBaseNeverEndsWithSlash(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) + public Task PathBaseNeverEndsWithSlash(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) { - TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); + return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); } [Theory] [InlineData("/base", "", "/Base/Something", "/Base", "/Something")] [InlineData("/base", "/OldBase", "/Base/Something", "/OldBase/Base", "/Something")] - public void PathBaseAndPathPreserveRequestCasing(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) + public Task PathBaseAndPathPreserveRequestCasing(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) { - TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); + return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); } [Theory] @@ -126,12 +126,12 @@ namespace Microsoft.AspNetCore.Builder.Extensions [InlineData("/b♫se", "/oldb♫se", "/b♫se/something", "/oldb♫se/b♫se", "/something")] [InlineData("/b♫se", "/oldb♫se", "/b♫se/Something", "/oldb♫se/b♫se", "/Something")] [InlineData("/b♫se", "/oldb♫se", "/B♫se/something", "/oldb♫se/B♫se", "/something")] - public void PathBaseCanHaveUnicodeCharacters(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) + public Task PathBaseCanHaveUnicodeCharacters(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) { - TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); + return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath); } - private static void TestPathBase(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) + private static async Task TestPathBase(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath) { HttpContext requestContext = CreateRequest(pathBase, requestPath); var builder = CreateBuilder() @@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions context.Items["test.PathBase"] = context.Request.PathBase; return Task.FromResult(0); }); - builder.Build().Invoke(requestContext).Wait(); + await builder.Build().Invoke(requestContext); // Assert path and pathBase are split after middleware Assert.Equal(expectedPath, ((PathString)requestContext.Items["test.Path"]).Value); diff --git a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs index 902a003b26..901454b62e 100644 --- a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions } [Fact] - public void PredicateTrue_BranchTaken_WillRejoin() + public async Task PredicateTrue_BranchTaken_WillRejoin() { // Arrange var context = CreateContext(); @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions parent.Use(Increment("parent")); // Act - parent.Build().Invoke(context).Wait(); + await parent.Build().Invoke(context); // Assert Assert.Equal(1, Count(context, "parent")); @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions } [Fact] - public void PredicateTrue_BranchTaken_CanTerminate() + public async Task PredicateTrue_BranchTaken_CanTerminate() { // Arrange var context = CreateContext(); @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions parent.Use(Increment("parent")); // Act - parent.Build().Invoke(context).Wait(); + await parent.Build().Invoke(context); // Assert Assert.Equal(0, Count(context, "parent")); @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions } [Fact] - public void PredicateFalse_PassThrough() + public async Task PredicateFalse_PassThrough() { // Arrange var context = CreateContext(); @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions parent.Use(Increment("parent")); // Act - parent.Build().Invoke(context).Wait(); + await parent.Build().Invoke(context); // Assert Assert.Equal(1, Count(context, "parent"));