Quick fixes: Clean up test code
- remove useless `configuration` variables and `Configuration` instances
- remove "Review" code comment
- unintentionally included in commit 4b5dd19
- reduce repeated code in `TestHelper` for functional tests
- `CreateServer()` methods had duplicate code, an ambiguous match, and an odd order
- rename `GetTestConfiguration()` to `UseCultureReplacer()` in functional tests
This commit is contained in:
parent
9ac6ebd2b2
commit
fc1017fba8
|
|
@ -77,7 +77,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
}
|
||||
|
||||
// REVIEW: Welcome back to life delegating SP!!!
|
||||
private class WrappingServiceProvider : IServiceProvider
|
||||
{
|
||||
private readonly IServiceProvider _fallback;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
string applicationWebSiteName,
|
||||
string applicationPath)
|
||||
{
|
||||
return CreateServer(builder, applicationWebSiteName, applicationPath, configureServices: null);
|
||||
return CreateServer(
|
||||
builder,
|
||||
applicationWebSiteName,
|
||||
applicationPath,
|
||||
configureServices: (Action<IServiceCollection>)null);
|
||||
}
|
||||
|
||||
public static TestServer CreateServer(
|
||||
|
|
@ -43,6 +47,29 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
configureServices: configureServices);
|
||||
}
|
||||
|
||||
public static TestServer CreateServer(
|
||||
Action<IApplicationBuilder> builder,
|
||||
string applicationWebSiteName,
|
||||
string applicationPath,
|
||||
Action<IServiceCollection> configureServices)
|
||||
{
|
||||
return TestServer.Create(
|
||||
builder,
|
||||
services => AddTestServices(services, applicationWebSiteName, applicationPath, configureServices));
|
||||
}
|
||||
|
||||
public static TestServer CreateServer(
|
||||
Action<IApplicationBuilder> builder,
|
||||
string applicationWebSiteName,
|
||||
Func<IServiceCollection, IServiceProvider> configureServices)
|
||||
{
|
||||
return CreateServer(
|
||||
builder,
|
||||
applicationWebSiteName,
|
||||
applicationPath: null,
|
||||
configureServices: configureServices);
|
||||
}
|
||||
|
||||
public static TestServer CreateServer(
|
||||
Action<IApplicationBuilder> builder,
|
||||
string applicationWebSiteName,
|
||||
|
|
@ -59,32 +86,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
});
|
||||
}
|
||||
|
||||
public static TestServer CreateServer(
|
||||
Action<IApplicationBuilder> builder,
|
||||
string applicationWebSiteName,
|
||||
Func<IServiceCollection, IServiceProvider> configureServices)
|
||||
{
|
||||
return TestServer.Create(
|
||||
CallContextServiceLocator.Locator.ServiceProvider,
|
||||
builder,
|
||||
services =>
|
||||
{
|
||||
AddTestServices(services, applicationWebSiteName, applicationPath: null, configureServices: null);
|
||||
return configureServices(services);
|
||||
});
|
||||
}
|
||||
|
||||
public static TestServer CreateServer(
|
||||
Action<IApplicationBuilder> builder,
|
||||
string applicationWebSiteName,
|
||||
string applicationPath,
|
||||
Action<IServiceCollection> configureServices)
|
||||
{
|
||||
return TestServer.Create(
|
||||
builder,
|
||||
services => AddTestServices(services, applicationWebSiteName, applicationPath, configureServices));
|
||||
}
|
||||
|
||||
private static void AddTestServices(
|
||||
IServiceCollection services,
|
||||
string applicationWebSiteName,
|
||||
|
|
|
|||
|
|
@ -52,12 +52,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
// Arrange
|
||||
var collection = new ServiceCollection();
|
||||
var assemblies = new[] { GetType().Assembly };
|
||||
var configuration = new Configuration();
|
||||
var controllerTypes = new[] { typeof(ControllerTypeA), typeof(TypeBController) };
|
||||
|
||||
// Act
|
||||
MvcServiceCollectionExtensions.WithControllersAsServices(collection,
|
||||
assemblies);
|
||||
MvcServiceCollectionExtensions.WithControllersAsServices(collection, assemblies);
|
||||
|
||||
// Assert
|
||||
var services = collection.ToList();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace ActionConstraintsWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace ActionResultsWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace ActivatorWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Used to report exceptions that MVC doesn't handle
|
||||
app.UseErrorReporter();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace AddServicesWebSite
|
|||
{
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Not calling AddMvc() here.
|
||||
// The purpose of the Website is to demonstrate that it throws
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace AntiForgeryWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace ApiExplorerWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace ApplicationModelWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace AutofacWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace BasicWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
app.UseMvc(routes =>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace BestEffortLinkGenerationWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace CompositeViewEngineWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
app.UseMvc(routes =>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace ContentNegotiationWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace ControllerDiscoveryConventionsWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace ControllersFromServicesWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace CorsMiddlewareWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseCors(policy => policy.WithOrigins("http://example.com"));
|
||||
app.UseMvc();
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace CorsWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace CustomRouteWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace ErrorPageMiddlewareWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorPage();
|
||||
app.UseMvc();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace FilesWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMiddleware<SendFileMiddleware>();
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace FiltersWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace FormatFilterWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace FormatterWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
app.UseMvc(routes =>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace InlineConstraints
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace LoggingWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.Map("/logs", (appBuilder) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace LowercaseUrlsWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,22 +2,15 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Mvc.TestConfiguration;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
public static class BuilderExtensions
|
||||
{
|
||||
public static IConfiguration GetTestConfiguration(this IApplicationBuilder app)
|
||||
// Should be added to the pipeline as early as possible.
|
||||
public static IApplicationBuilder UseCultureReplacer(this IApplicationBuilder app)
|
||||
{
|
||||
// Unconditionally place CultureReplacerMiddleware as early as possible in the pipeline.
|
||||
app.UseMiddleware<CultureReplacerMiddleware>();
|
||||
|
||||
// Until we update all references, return a useful configuration.
|
||||
var configuration = app.ApplicationServices.GetService<IConfiguration>() ?? new Configuration();
|
||||
|
||||
return configuration;
|
||||
return app.UseMiddleware<CultureReplacerMiddleware>();
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseErrorReporter(this IApplicationBuilder app)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace ModelBindingWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace MvcTagHelpersWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace PrecompilationWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace RazorCompilerCacheWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace RazorEmbeddedViewsWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace RazorPageExecutionInstrumentationWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.Use(async (HttpContext context, Func<Task> next) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace RazorWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
app.UseMvc(routes =>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace RequestServicesWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Initializes the RequestId service for each request
|
||||
app.UseMiddleware<RequestIdMiddleware>();
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace ResponseCacheWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace RoutingWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace TagHelpersWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace TempDataWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseInMemorySession();
|
||||
app.UseMvc(routes =>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace UrlHelperWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace ValidationWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Set up file serving for JavaScript files.
|
||||
app.UseFileServer();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace ValueProvidersWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
app.UseMvc(routes =>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace VersioningWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace ViewComponentWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace WebApiCompatShimWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace XmlFormattersWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
app.UseCultureReplacer();
|
||||
|
||||
app.UseErrorReporter();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue