Fix dispatching functional tests not using dispatching startup (#8052)

This commit is contained in:
James Newton-King 2018-07-12 14:19:48 +12:00 committed by GitHub
parent 183ecd85d6
commit c367e1d681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 41 deletions

View File

@ -1,7 +1,12 @@
// 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;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
@ -12,5 +17,63 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
: base(fixture)
{
}
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
public override Task AttributeRoutedAction_InArea_ExplicitLeaveArea()
{
return Task.CompletedTask;
}
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
public override Task AttributeRoutedAction_InArea_StaysInArea_ActionDoesntExist()
{
return Task.CompletedTask;
}
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
public override Task ConventionalRoutedAction_InArea_ExplicitLeaveArea()
{
return Task.CompletedTask;
}
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
public override Task ConventionalRoutedAction_InArea_StaysInArea()
{
return Task.CompletedTask;
}
[Fact]
public async override Task RouteData_Routers_ConventionalRoute()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/RouteData/Conventional");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(body);
Assert.Equal(
Array.Empty<string>(),
result.Routers);
}
[Fact]
public async override Task RouteData_Routers_AttributeRoute()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/RouteData/Attribute");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(body);
Assert.Equal(
Array.Empty<string>(),
result.Routers);
}
}
}

View File

@ -1,6 +1,13 @@
// 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.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
public class RoutingTests : RoutingTestsBase<RoutingWebSite.Startup>
@ -9,5 +16,48 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
: base(fixture)
{
}
[Fact]
public async override Task RouteData_Routers_ConventionalRoute()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/RouteData/Conventional");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(body);
Assert.Equal(
new string[]
{
typeof(RouteCollection).FullName,
typeof(Route).FullName,
typeof(MvcRouteHandler).FullName,
},
result.Routers);
}
[Fact]
public async override Task RouteData_Routers_AttributeRoute()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/RouteData/Attribute");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(body);
Assert.Equal(new string[]
{
typeof(RouteCollection).FullName,
typeof(AttributeRoute).FullName,
typeof(MvcAttributeRouteHandler).FullName,
},
result.Routers);
}
}
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json;
@ -18,53 +19,20 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
protected RoutingTestsBase(MvcTestFixture<TStartup> fixture)
{
Client = fixture.CreateDefaultClient();
var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder);
Client = factory.CreateDefaultClient();
}
private static void ConfigureWebHostBuilder(IWebHostBuilder builder) =>
builder.UseStartup<TStartup>();
public HttpClient Client { get; }
[Fact]
public async Task RouteData_Routers_ConventionalRoute()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/RouteData/Conventional");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(body);
Assert.Equal(
new string[]
{
typeof(RouteCollection).FullName,
typeof(Route).FullName,
typeof(MvcRouteHandler).FullName,
},
result.Routers);
}
public abstract Task RouteData_Routers_ConventionalRoute();
[Fact]
public async Task RouteData_Routers_AttributeRoute()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/RouteData/Attribute");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(body);
Assert.Equal(new string[]
{
typeof(RouteCollection).FullName,
typeof(AttributeRoute).FullName,
typeof(MvcAttributeRouteHandler).FullName,
},
result.Routers);
}
public abstract Task RouteData_Routers_AttributeRoute();
// Verifies that components in the MVC pipeline can modify datatokens
// without impacting any static data.
@ -95,7 +63,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Single(result.DataTokens, kvp => kvp.Key == "actionName" && ((string)kvp.Value) == "Conventional");
}
private class ResultData
protected class ResultData
{
public Dictionary<string, object> DataTokens { get; set; }