diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs index e0ea73ae53..c685b3027a 100644 --- a/samples/MvcSample.Web/Startup.cs +++ b/samples/MvcSample.Web/Startup.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; +#if DNX451 using System.IO; using Autofac; #endif @@ -16,97 +16,91 @@ using Microsoft.Framework.DependencyInjection; #if DNX451 using Microsoft.Framework.DependencyInjection.Autofac; using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; #endif using MvcSample.Web.Filters; using MvcSample.Web.Services; - namespace MvcSample.Web { public class Startup { - public void Configure(IApplicationBuilder app) +#if DNX451 + private bool _autoFac; +#endif + + public IServiceProvider ConfigureServices(IServiceCollection services) { - app.UseStatusCodePages(); - app.UseFileServer(); + services.AddCaching(); + services.AddSession(); + + services.AddMvc(); + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + + services.ConfigureMvc(options => + { + options.Filters.Add(typeof(PassThroughAttribute), order: 17); + options.AddXmlDataContractSerializerFormatter(); + options.Filters.Add(new FormatFilterAttribute()); + }); #if DNX451 // Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine // but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment. // Functional tests update that service but not in the static provider. - var applicationEnvironment = app.ApplicationServices.GetRequiredService(); + var applicationEnvironment = services.BuildServiceProvider().GetRequiredService(); var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json"); // Set up configuration sources. var configuration = new Configuration() .AddJsonFile(configurationPath) .AddEnvironmentVariables(); - string diSystem; if (configuration.TryGet("DependencyInjection", out diSystem) && diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase)) { - app.UseMiddleware(); - - app.UseServices(services => + _autoFac = true; + services.ConfigureRazorViewEngine(options => { - services.AddCaching(); - services.AddSession(); - - services.AddMvc(); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient(); - - services.ConfigureMvc(options => - { - options.Filters.Add(typeof(PassThroughAttribute), order: 17); - options.AddXmlDataContractSerializerFormatter(); - options.Filters.Add(new FormatFilterAttribute()); - }); - services.ConfigureRazorViewEngine(options => - { - var expander = new LanguageViewLocationExpander( - context => context.HttpContext.Request.Query["language"]); - options.ViewLocationExpanders.Insert(0, expander); - }); - - // Create the autofac container - ContainerBuilder builder = new ContainerBuilder(); - - // Create the container and use the default application services as a fallback - AutofacRegistration.Populate( - builder, - services); - - builder.RegisterModule(); - - IContainer container = builder.Build(); - - return container.Resolve(); + var expander = new LanguageViewLocationExpander( + context => context.HttpContext.Request.Query["language"]); + options.ViewLocationExpanders.Insert(0, expander); }); + + // Create the autofac container + var builder = new ContainerBuilder(); + + // Create the container and use the default application services as a fallback + AutofacRegistration.Populate( + builder, + services); + + builder.RegisterModule(); + + var container = builder.Build(); + + return container.Resolve(); } else #endif { - app.UseServices(services => - { - services.AddCaching(); - services.AddSession(); - - services.AddMvc(); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient(); - - services.ConfigureMvc(options => - { - options.Filters.Add(typeof(PassThroughAttribute), order: 17); - options.AddXmlDataContractSerializerFormatter(); - options.Filters.Add(new FormatFilterAttribute()); - }); - }); + return services.BuildServiceProvider(); } + } + + public void Configure(IApplicationBuilder app) + { + app.UseStatusCodePages(); + app.UseFileServer(); + +#if DNX451 + if (_autoFac) + { + app.UseMiddleware(); + } +#endif app.UseInMemorySession(); app.UseMvc(routes => diff --git a/samples/TagHelperSample.Web/Startup.cs b/samples/TagHelperSample.Web/Startup.cs index e69df298f6..0d2745f524 100644 --- a/samples/TagHelperSample.Web/Startup.cs +++ b/samples/TagHelperSample.Web/Startup.cs @@ -11,15 +11,16 @@ namespace TagHelperSample.Web { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.AddSingleton(); + } + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { - app.UseServices(services => - { - services.AddMvc(); - - services.AddSingleton(); - }); - loggerFactory.AddConsole((name, logLevel) => name.StartsWith("Microsoft.AspNet.Mvc.TagHelpers", StringComparison.OrdinalIgnoreCase) || (name.StartsWith("Microsoft.Net.Http.Server.WebListener", StringComparison.OrdinalIgnoreCase) diff --git a/src/Microsoft.AspNet.Mvc.Core/Internal/MvcServicesHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Internal/MvcServicesHelper.cs index 5fb9f13067..4ea4852c37 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Internal/MvcServicesHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Internal/MvcServicesHelper.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.Internal { throw new InvalidOperationException(Resources.FormatUnableToFindServices( "IServiceCollection.AddMvc()", - "IApplicationBuilder.UseServices(...)", + "IApplicationBuilder.ConfigureServices(...)", "IApplicationBuilder.UseMvc(...)")); } } diff --git a/src/Microsoft.AspNet.Mvc/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc/Properties/Resources.Designer.cs index 3ee6068e7c..e1c008b8f1 100644 --- a/src/Microsoft.AspNet.Mvc/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Mvc/Properties/Resources.Designer.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc = new ResourceManager("Microsoft.AspNet.Mvc.Resources", typeof(Resources).GetTypeInfo().Assembly); /// - /// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc()/UseServices() in the Application Startup. + /// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc() in the Application Startup. /// internal static string UnableToFindServices { @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc } /// - /// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc()/UseServices() in the Application Startup. + /// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc() in the Application Startup. /// internal static string FormatUnableToFindServices() { diff --git a/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs b/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs index 7721b7b3e7..c67cd5930b 100644 --- a/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs +++ b/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs @@ -2,15 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; using System.Runtime.Versioning; -using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Mvc.Razor; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime; @@ -56,9 +49,6 @@ namespace Microsoft.AspNet.Mvc // Create something similar to a HttpContext.RequestServices provider. Necessary because this class is // instantiated in a lower-level "HttpContext.ApplicationServices" context. One important added service // is an IOptions but use AddMvc() for simplicity and flexibility. - var serviceCollection = HostingServices.Create(_appServices); - serviceCollection.AddMvc(); - // We also need an IApplicationEnvironment with a base path that matches the containing web site, to // find the razor files. We don't have a guarantee that the base path of the current application is // this site. For example similar functional test changes to the IApplicationEnvironment happen later, @@ -68,10 +58,13 @@ namespace Microsoft.AspNet.Mvc var precompilationApplicationEnvironment = new PrecompilationApplicationEnvironment( applicationEnvironment, context.ProjectContext.ProjectDirectory); - serviceCollection.AddInstance(precompilationApplicationEnvironment); - var serviceProvider = serviceCollection.BuildServiceProvider(); - var viewCompiler = new RazorPreCompiler(serviceProvider, context, _memoryCache, compilationSettings) + var replacedServices = new ServiceCollection(); + replacedServices.AddMvc(); + replacedServices.AddInstance(precompilationApplicationEnvironment); + var wrappedServices = new WrappingServiceProvider(_appServices, replacedServices); + + var viewCompiler = new RazorPreCompiler(wrappedServices, context, _memoryCache, compilationSettings) { GenerateSymbols = GenerateSymbols }; @@ -84,6 +77,25 @@ namespace Microsoft.AspNet.Mvc { } + // REVIEW: Welcome back to life delegating SP!!! + private class WrappingServiceProvider : IServiceProvider + { + private readonly IServiceProvider _fallback; + private readonly IServiceProvider _override; + + // Need full wrap for generics like IOptions + public WrappingServiceProvider(IServiceProvider fallback, IServiceCollection replacedServices) + { + _fallback = fallback; + _override = replacedServices.BuildServiceProvider(); + } + + public object GetService(Type serviceType) + { + return _override.GetService(serviceType) ?? _fallback.GetService(serviceType); + } + } + private class PrecompilationApplicationEnvironment : IApplicationEnvironment { private readonly IApplicationEnvironment _originalApplicationEnvironment; diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Internal/MvcServicesHelperTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Internal/MvcServicesHelperTests.cs index 5637d35546..d1e257a3d0 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Internal/MvcServicesHelperTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Internal/MvcServicesHelperTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc services.Setup(o => o.GetService(typeof(IEnumerable))) .Returns(new List()); var expectedMessage = "Unable to find the required services. Please add all the required " + - "services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.UseServices(...)' " + + "services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.ConfigureServices(...)' " + "or 'IApplicationBuilder.UseMvc(...)' in the application startup code."; // Act & Assert diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs index bb5469f07c..b715808643 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading.Tasks; using ActionResultsWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -18,12 +19,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ActionResultsWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task BadRequestResult_CanBeReturned() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{\"SampleInt\":10}"; @@ -45,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsRelativePathInLocationHeader() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -65,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsAbsolutePathInLocationHeader() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -85,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsQualifiedPathInLocationHeader() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -107,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsUriInLocationHeader() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -127,7 +129,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedAtActionResult_GeneratesUri_WithActionAndController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -147,7 +149,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedAtRouteResult_GeneratesUri_WithRouteValues() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -167,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedAtRouteResult_GeneratesUri_WithRouteName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -187,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SerializableError_CanSerializeNormalObjects() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "" + @@ -210,7 +212,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ContentResult_WritesContent_SetsDefaultContentTypeAndEncoding() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -230,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ContentResult_WritesContent_SetsContentTypeWithDefaultEncoding() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -250,7 +252,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ContentResult_WritesContent_SetsContentTypeAndEncoding() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -270,7 +272,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ObjectResult_WithStatusCodeAndNoContent_SetsSameStatusCode() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Get, @@ -287,7 +289,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HttpNotFoundObjectResult_NoResponseContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -306,7 +308,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HttpNotFoundObjectResult_WithResponseContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -325,7 +327,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HttpNotFoundObjectResult_WithDisposableObject() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var nameValueCollection = new List> { diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs index c8350aafb1..bed3a5ce4d 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using ActivatorWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -13,12 +14,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ActivatorWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task ControllerThatCannotBeActivated_ThrowsWhenAttemptedToBeInvoked() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMessage = "The property 'Service' on controller 'ActivatorWebSite.CannotBeActivatedController' " + @@ -36,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesForPocoControllersAreInitialized() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "4|some-text"; @@ -54,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesForTypesDerivingFromControllerAreInitialized() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "Hello world"; @@ -69,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewActivator_ActivatesDefaultInjectedProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @" world! /View/ConsumeServicesFromBaseType"; @@ -84,7 +86,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewActivator_ActivatesAndContextualizesInjectedServices() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "4 test-value"; @@ -99,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewActivator_ActivatesServicesFromBaseType() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @"/content/scripts/test.js"; @@ -114,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentActivator_ActivatesProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @"Random Number:4"; @@ -129,7 +131,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentActivator_ActivatesPropertiesAndContextualizesThem() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "test-value"; @@ -144,7 +146,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentActivator_ActivatesPropertiesAndContextualizesThem_WhenMultiplePropertiesArePresent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "Random Number:4 test-value"; @@ -159,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentThatCannotBeActivated_ThrowsWhenAttemptedToBeInvoked() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMessage = "No service for type 'ActivatorWebSite.CannotBeActivatedComponent+FakeType' " + "has been registered."; @@ -176,7 +178,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TagHelperActivation_ActivateHtmlHelper_RendersProperly() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "

Activation Test

" + Environment.NewLine + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs index 24c3fc3203..8df272737c 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs @@ -8,6 +8,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,12 +17,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(AntiForgeryWebSite); private readonly Action _app = new AntiForgeryWebSite.Startup().Configure; + private readonly Action _configureServices = new AntiForgeryWebSite.Startup().ConfigureServices; [Fact] public async Task MultipleAFTokensWithinTheSamePage_GeneratesASingleCookieToken() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -44,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleFormPostWithingASingleView_AreAllowed() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // do a get response. @@ -79,7 +81,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task InvalidCookieToken_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var getResponse = await client.GetAsync("http://localhost/Account/Login"); @@ -111,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task InvalidFormToken_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var getResponse = await client.GetAsync("http://localhost/Account/Login"); @@ -141,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task IncompatibleCookieToken_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // do a get response. @@ -179,7 +181,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MissingCookieToken_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // do a get response. @@ -209,7 +211,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MissingAFToken_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var getResponse = await client.GetAsync("http://localhost/Account/Login"); var resposneBody = await getResponse.Content.ReadAsStringAsync(); @@ -238,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetCookieAndHeaderBeforeFlushAsync_GeneratesCookieTokenAndHeader() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -258,7 +260,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetCookieAndHeaderBeforeFlushAsync_PostToForm() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // do a get response. diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs index a17e6dd3b7..e11db02e48 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ApiExplorerWebSite); private readonly Action _app = new ApiExplorerWebSite.Startup().Configure; + private readonly Action _configureServices = new ApiExplorerWebSite.Startup().ConfigureServices; [Fact] public async Task ApiExplorer_IsVisible_EnabledWithConvention() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -39,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_IsVisible_DisabledWithConvention() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -56,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_IsVisible_DisabledWithAttribute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_IsVisible_EnabledWithAttribute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -90,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_GroupName_SetByConvention() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -108,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_GroupName_SetByAttributeOnController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -126,7 +128,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_GroupName_SetByAttributeOnAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -144,7 +146,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_DisplaysFixedRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -162,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_DisplaysRouteWithParameters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -186,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_StripsInlineConstraintsFromThePath() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/Constraint/5"; @@ -211,7 +213,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_StripsCatchAllsFromThePath() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/CatchAll/5"; @@ -235,7 +237,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_StripsCatchAllsWithConstraintsFromThePath() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/CatchAllAndConstraint/5"; @@ -262,7 +264,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplateStripsMultipleConstraints_OnTheSamePathSegment() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/" @@ -301,7 +303,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplateStripsMultipleConstraints_InMultipleSegments() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/" + "MultipleParametersInMultipleSegments/12/01/1987"; @@ -339,7 +341,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_DescribeParameters_FromAllSources() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/MultipleTypesOfParameters/1/2/3"; @@ -370,7 +372,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_MakesParametersOptional() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -392,7 +394,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_HttpMethod_All() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -410,7 +412,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_HttpMethod_Single() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -432,7 +434,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_HttpMethod_Single(string httpMethod) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -458,7 +460,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_VoidWithoutAttribute(string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -483,7 +485,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_UnknownWithoutAttribute(string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -506,7 +508,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_KnownWithoutAttribute(string action, string type) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -530,7 +532,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_KnownWithAttribute(string action, string type) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -551,7 +553,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_OverrideOnAction(string action, string type) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -570,7 +572,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseContentType_Unset() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -600,7 +602,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseContentType_Specific() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -626,7 +628,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseContentType_NoMatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -651,7 +653,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string formatterType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -673,7 +675,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_Default() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -701,7 +703,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_BinderMetadataOnParameters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -729,7 +731,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ParametersSimpleModel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -753,7 +755,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_SimpleModel_FromBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -781,7 +783,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_ComplexModel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs index 54b6429c57..9d3138df88 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -14,12 +15,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ApplicationModelWebSite); private readonly Action _app = new ApplicationModelWebSite.Startup().Configure; + private readonly Action _configureServices = new ApplicationModelWebSite.Startup().ConfigureServices; [Fact] public async Task ControllerModel_CustomizedWithAttribute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -36,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionModel_CustomizedWithAttribute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -53,7 +55,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParameterModel_CustomizedWithAttribute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -70,7 +72,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModel_AddPropertyToActionDescriptor_FromApplicationModel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -87,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModel_AddPropertyToActionDescriptor_ControllerModelOverwritesCommonApplicationProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -104,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModel_ProvidesMetadataToActionDescriptor_ActionModelOverwritesControllerModelProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -121,7 +123,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModelExtensions_AddsConventionToAllControllers() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -140,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModelExtensions_AddsConventionToAllActions() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Home/GetHelloWorld"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs index 54c20dbd47..28102ec6f6 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Threading.Tasks; using BasicWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -19,6 +20,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; // Some tests require comparing the actual response body against an expected response baseline // so they require a reference to the assembly on which the resources are located, in order to @@ -33,7 +35,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanRender_ViewsWithLayout(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -57,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanRender_SimpleViews() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync("compiler/resources/BasicWebSite.Home.PlainView.html"); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -77,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanReturn_ResultsWithoutContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -95,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ReturningTaskFromAction_ProducesNoContentResult() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -110,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionDescriptors_CreatedOncePerRequest() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = "1"; @@ -130,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionWithRequireHttps_RedirectsToSecureUrl_ForNonHttpsGetRequests() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -150,7 +152,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionWithRequireHttps_ReturnsBadRequestResponse_ForNonHttpsNonGetRequests() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -172,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionWithRequireHttps_AllowsHttpsRequests(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -188,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonViewComponent_RendersJson() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = new HttpClient(server.CreateHandler(), false); var expectedBody = JsonConvert.SerializeObject(new BasicWebSite.Models.Person() { @@ -247,7 +249,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HtmlHelperLinkGeneration(string viewName, string expectedLink) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -263,7 +265,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConfigureMvc_AddsOptionsProperly() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -279,7 +281,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesWithoutControllerSuffix_DerivingFromTypesWithControllerSuffix_CanBeAccessed() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -293,7 +295,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesMarkedAsNonAction_AreInaccessible() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = new HttpClient(server.CreateHandler(), false); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs index 7f993adac8..687e450029 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs @@ -6,6 +6,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(BestEffortLinkGenerationWebSite); private readonly Action _app = new BestEffortLinkGenerationWebSite.Startup().Configure; + private readonly Action _configureServices = new BestEffortLinkGenerationWebSite.Startup().ConfigureServices; private const string ExpectedOutput = @" @@ -26,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GenerateLink_NonExistentAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/Home/Index"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs index b9d0079b84..de37a76b6b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using RazorWebSite; using Xunit; @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task CompilationOptions_AreUsedByViewsAndPartials() @@ -31,7 +33,7 @@ This method is only defined in DNX451"; This method is only defined in DNXCORE50"; #endif - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs index fa02027309..cbdb72b214 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -12,12 +13,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(CompositeViewEngineWebSite); private readonly Action _app = new CompositeViewEngineWebSite.Startup().Configure; + private readonly Action _configureServices = new CompositeViewEngineWebSite.Startup().ConfigureServices; [Fact] public async Task CompositeViewEngine_FindsPartialViewsAcrossAllEngines() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -31,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CompositeViewEngine_FindsViewsAcrossAllEngines() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs index 061510af52..1d04798ce8 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using ActionConstraintsWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ActionConstraintsWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task NoRequestContentType_SelectsActionWithoutConstraint() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -41,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoRequestContentType_Throws_IfMultipleActionsWithConstraints() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -65,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -87,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Selects_Action_BasedOnRequestContentType(string requestContentType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{SampleString:\""+requestContentType+"\"}"; @@ -110,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionLevelAttribute_OveridesClassLevel(string requestContentType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{SampleString:\"" + requestContentType + "\"}"; @@ -133,7 +135,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task DerivedClassLevelAttribute_OveridesBaseClassLevel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = " _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task ProducesAttribute_SingleContentType_PicksTheFirstSupportedFormatter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Selects custom even though it is last in the list. @@ -43,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_MultipleContentTypes_RunsConnegToSelectFormatter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\r\n \"Name\": \"My name\",\r\n \"Address\": \"My address\"\r\n}"; @@ -61,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoProducesAttribute_ActionReturningString_RunsUsingTextFormatter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("text/plain;charset=utf-8"); var expectedBody = "NormalController"; @@ -79,7 +81,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoProducesAttribute_ActionReturningAnyObject_RunsUsingDefaultFormatters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -94,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttributeWithTypeOnly_RunsRegularContentNegotiation() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -114,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_WithTypeAndContentType_UsesContentType() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); var expectedContentType = MediaTypeHeaderValue.Parse("application/xml;charset=utf-8"); @@ -138,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoAcceptAndRequestContentTypeHeaders_UsesFirstFormatterWhichCanWriteType(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -156,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchingFormatter_ForTheGivenContentType_Returns406() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -175,7 +177,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedResponseBody) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); expectedResponseBody = expectedResponseBody.Replace("#", Environment.NewLine); @@ -196,7 +198,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnAction_OverridesTheValueOnClass() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Value on the class is application/json. @@ -216,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnDerivedClass_OverridesTheValueOnBaseClass() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_ProducesContentOnClassController;charset=utf-8"); @@ -235,7 +237,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnDerivedAction_OverridesTheValueOnBaseClass() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_NoProducesContentOnClassController_Action;charset=utf-8"); @@ -253,7 +255,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnDerivedAction_OverridesTheValueOnBaseAction() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_NoProducesContentOnClassController_Action;charset=utf-8"); @@ -272,7 +274,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_OnDerivedClassAndAction_OverridesTheValueOnBaseClass() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_ProducesContentOnClassController_Action;charset=utf-8"); @@ -291,7 +293,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_IsNotHonored_ForJsonResult() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"Produces_WithNonObjectResult\"}"; @@ -309,7 +311,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_UsesDefaultContentTypes_IfNoneAreAddedExplicitly() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"ReturnJsonResult\"}"; @@ -327,7 +329,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_UsesExplicitContentTypeAndFormatter_IfAdded() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/custom-json;charset=utf-8"); var expectedBody = "{ MethodName = ReturnJsonResult_WithCustomMediaType }"; @@ -345,7 +347,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_UsesDefaultJsonFormatter_IfNoMatchingFormatterIsFound() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"ReturnJsonResult_WithCustomMediaType_NoFormatter\"}"; @@ -363,7 +365,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonFormatter_SupportedMediaType_DoesNotChangeAcrossRequests() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"ReturnJsonResult\"}"; @@ -383,7 +385,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlFormatter_SupportedMediaType_DoesNotChangeAcrossRequests() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); @@ -409,7 +411,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchOn_RequestContentType_FallsBackOnTypeBasedMatch_MatchFound(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "1234"; @@ -434,7 +436,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ObjectResult_WithStringReturnType_WritesTextPlainFormat(bool matchFormatterOnObjectType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var targetUri = "http://localhost/FallbackOnTypeBasedMatch/ReturnString?matchFormatterOnObjectType=" + matchFormatterOnObjectType; @@ -457,7 +459,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchOn_RequestContentType_SkipTypeMatchByAddingACustomFormatter(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var targetUri = "http://localhost/FallbackOnTypeBasedMatch/" + actionName + "/?input=1234"; var content = new StringContent("1234", Encoding.UTF8, "application/custom"); @@ -476,7 +478,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchOn_RequestContentType_FallsBackOnTypeBasedMatch_NoMatchFound_Returns406() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var targetUri = "http://localhost/FallbackOnTypeBasedMatch/FallbackGivesNoMatch/?input=1234"; var content = new StringContent("1234", Encoding.UTF8, "application/custom"); @@ -495,7 +497,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_And_FormatFilterAttribute_Conflicting() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json"); @@ -510,7 +512,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_And_FormatFilterAttribute_Collaborating() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs index 6ae8e62a22..e3ffd298f3 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs @@ -18,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ControllerDiscoveryConventionsWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task AbstractControllers_AreSkipped() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -38,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesDerivingFromControllerBaseTypesThatDoNotReferenceMvc_AreSkipped() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesMarkedWithNonController_AreSkipped() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -68,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PocoTypesWithControllerSuffix_AreDiscovered() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesDerivingFromTypesWithControllerSuffix_AreDiscovered() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -106,7 +107,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var server = TestHelper.CreateServer( _app, SiteName, - services => services.AddTransient()); + services => + { + _configureServices(services); + services.AddTransient(); + }); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs index 7439403599..2c7dabc0c2 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Threading.Tasks; using ControllersFromServicesWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,13 +16,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ControllersFromServicesWebSite); private readonly Action _app = new Startup().Configure; + private readonly Func _configureServices = new Startup().ConfigureServices; [Fact] public async Task ControllersWithConstructorInjectionAreCreatedAndActivated() { // Arrange var expected = "/constructorinjection 14 test-header-value"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Test-Header", "test-header-value"); @@ -37,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "No schedules available for 23"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -52,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "4"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -67,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "Updated record employee303"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -84,7 +86,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "Saved record employee #211"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -104,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AddControllersFromServices_UsesControllerDiscoveryContentions(string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsMiddlewareTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsMiddlewareTests.cs index a332b951f0..37ab7c6847 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsMiddlewareTests.cs @@ -7,7 +7,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Cors.Core; -using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(CorsMiddlewareWebSite); private readonly Action _app = new CorsMiddlewareWebSite.Startup().Configure; + private readonly Action _configureServices = new CorsMiddlewareWebSite.Startup().ConfigureServices; [Theory] [InlineData("GET")] @@ -24,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResourceWithSimpleRequestPolicy_Allows_SimpleRequests(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var origin = "http://example.com"; @@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PolicyFailed_Disallows_PreFlightRequest(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Adding a custom header makes it a non simple request. @@ -80,7 +81,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PolicyFailed_Allows_ActualRequest_WithMissingResponseHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Adding a custom header makes it a non simple request. diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsTests.cs index 760b67f7d5..facbdee05a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CorsTests.cs @@ -7,7 +7,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Cors.Core; -using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(CorsWebSite); private readonly Action _app = new CorsWebSite.Startup().Configure; + private readonly Action _configureServices = new CorsWebSite.Startup().ConfigureServices; [Theory] [InlineData("GET")] @@ -24,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResourceWithSimpleRequestPolicy_Allows_SimpleRequests(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var origin = "http://example.com"; @@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PolicyFailed_Disallows_PreFlightRequest(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Adding a custom header makes it a non simple request. @@ -80,7 +81,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SuccessfulCorsRequest_AllowsCredentials_IfThePolicyAllowsCredentials() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Adding a custom header makes it a non simple request. @@ -113,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SuccessfulPreflightRequest_AllowsCredentials_IfThePolicyAllowsCredentials() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Adding a custom header makes it a non simple request. @@ -150,7 +151,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PolicyFailed_Allows_ActualRequest_WithMissingResponseHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Adding a custom header makes it a non simple request. @@ -178,7 +179,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task DisableCors_ActionsCanOverride_ControllerLevel(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Exclusive content is not available on other sites. @@ -205,7 +206,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task DisableCors_PreFlight_ActionsCanOverride_ControllerLevel(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Exclusive content is not available on other sites. diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs index f989a9d70d..35a5477aca 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -14,6 +15,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(CustomRouteWebSite); private readonly Action _app = new CustomRouteWebSite.Startup().Configure; + private readonly Action _configureServices = new CustomRouteWebSite.Startup().ConfigureServices; + [Theory] [InlineData("Javier", "Hola from Spain.")] @@ -22,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteToLocale_ConventionalRoute_BasedOnUser(string user, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/CustomRoute_Products/Index"); @@ -44,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteWithAttributeRoute_IncludesLocale_BasedOnUser(string user, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/CustomRoute_Orders/5"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs index 57d4f3e208..4ba6f42759 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -20,13 +21,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(UrlHelperWebSite); private readonly Action _app = new UrlHelperWebSite.Startup().Configure; + private readonly Action _configureServices = new UrlHelperWebSite.Startup().ConfigureServices; + private const string _cdnServerBaseUrl = "http://cdn.contoso.com"; [Fact] public async Task CustomUrlHelper_GeneratesUrlFromController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -42,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CustomUrlHelper_GeneratesUrlFromView() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -60,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LowercaseUrls_LinkGeneration(string url, string expectedLink) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs index e2e3ccd0b8..52cff2b448 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs @@ -10,6 +10,7 @@ using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Description; using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.ViewComponents; +using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; using Xunit; @@ -20,6 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; + private readonly Action _configureServices = new BasicWebSite.Startup().ConfigureServices; [Theory] [InlineData(typeof(IActionDescriptorProvider), typeof(ControllerActionDescriptorProvider), -1000)] @@ -33,7 +35,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ServiceOrder_GetOrder(Type serviceType, Type actualType, int order) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/Order/GetServiceOrder?serviceType=" + serviceType.AssemblyQualifiedName; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs index c9f03fe6d6..757e08a73a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs @@ -6,6 +6,7 @@ using System; using System.Threading.Tasks; using AutofacWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -14,6 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(AutofacWebSite); private readonly Action _app = new Startup().Configure; + private readonly Func _configureServices = new Startup().ConfigureServices; [Theory] [InlineData("http://localhost/di", "

Builder Output: Hello from builder.

")] @@ -22,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange & Act & Assert (does not throw) // This essentially calls into the Startup.Configuration method - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); // Make a request to start resolving DI pieces var response = await server.CreateClient().GetAsync(url); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs index 25b24c3482..927583c5aa 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using RazorWebSite; using Xunit; @@ -13,12 +14,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task ViewsInheritsUsingsAndInjectDirectivesFromViewStarts() { var expected = @"Hello Person1"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -32,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewInheritsBasePageFromViewStarts() { var expected = @"WriteLiteral says:layout:Write says:Write says:Hello Person2"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs index a2152480cd..59becc0d41 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Threading.Tasks; using ErrorPageMiddlewareWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -19,6 +20,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ErrorPageMiddlewareWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; + private readonly Assembly _resourcesAssembly = typeof(ErrorPageTests).GetTypeInfo().Assembly; [Theory] @@ -31,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CompilationFailuresAreListedByErrorPageMiddleware(string action, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs index 6ad4a9de4c..1f72952e01 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -13,12 +14,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FilesWebSite); private readonly Action _app = new FilesWebSite.Startup().Configure; + private readonly Action _configureServices = new FilesWebSite.Startup().ConfigureServices; + [Fact] public async Task FileFromDisk_CanBeEnabled_WithMiddleware() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -39,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromDisk_ReturnsFileWithFileName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -64,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromStream_ReturnsFile() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -85,7 +88,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromStream_ReturnsFileWithFileName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -110,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromBinaryData_ReturnsFile() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -131,7 +134,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromBinaryData_ReturnsFileWithFileName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -156,7 +159,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromEmbeddedResources_ReturnsFileWithFileName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedBody = "Sample text file as embedded resource."; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs index 34b0b1aff4..703a7c9888 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -17,6 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FiltersWebSite); private readonly Action _app = new FiltersWebSite.Startup().Configure; + private readonly Action _configureServices = new FiltersWebSite.Startup().ConfigureServices; // A controller can only be an action filter and result filter, so we don't have entries // for the other filter types implemented by the controller. @@ -24,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ListAllFilters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = new string[] @@ -80,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AnonymousUsersAreBlocked() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -94,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllowsAnonymousUsersToAccessController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -113,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanAuthorize(string testAction) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -129,7 +131,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllowAnonymousOverridesAuthorize() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -145,7 +147,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ImpossiblePolicyFailsAuthorize() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -160,7 +162,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ServiceFilterUsesRegisteredServicesAsFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -175,7 +177,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ServiceFilterThrowsIfServiceIsNotRegistered() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/RandomNumber/GetAuthorizedRandomNumber"; @@ -191,7 +193,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypeFilterInitializesArguments() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/RandomNumber/GetModifiedRandomNumber?randomNumber=10"; @@ -207,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypeFilterThrowsIfServicesAreNotRegistered() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/RandomNumber/GetHalfOfModifiedRandomNumber?randomNumber=3"; @@ -223,7 +225,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFilterOverridesActionExecuted() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -240,7 +242,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilterOverridesOnResultExecuting() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -257,7 +259,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilterOverridesOnResultExecuted() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -274,7 +276,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task OrderOfExecutionOfFilters_WhenOrderAttribute_IsNotMentioned() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -292,7 +294,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionsHandledInActionFilters_WillNotShortCircuitResultFilters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -309,7 +311,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionFilter_OnAction_ShortCircuitsResultFilters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -328,7 +330,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GlobalExceptionFilter_HandlesAnException() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -345,7 +347,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionFilter_Scope() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -366,7 +368,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFilter_Scope() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -393,7 +395,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilter_Scope() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -416,7 +418,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FiltersWithOrder() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -433,7 +435,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFiltersWithOrder() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -454,7 +456,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFiltersWithOrder() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -473,7 +475,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFilterShortCircuitsAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -490,7 +492,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilterShortCircuitsResult() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -507,7 +509,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionFilterShortCircuitsAnotherExceptionFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -524,7 +526,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingFilters_ResultFilter_NotHandledByGlobalExceptionFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -541,7 +543,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingFilters_ActionFilter_HandledByGlobalExceptionFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -558,7 +560,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingFilters_AuthFilter_NotHandledByGlobalExceptionFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -575,7 +577,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingExceptionFilter_ExceptionFilter_NotHandledByGlobalExceptionFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -592,7 +594,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var input = "{ sampleInt: 10 }"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Json"); @@ -617,7 +619,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // There's nothing that can deserialize the body, so the result contains the default // value. - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Json"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs index c611bd3d35..bd2f0c53a1 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs @@ -16,12 +16,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task FlushPointsAreExecutedForPagesWithLayouts() { var waitService = new WaitService(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); + var server = TestHelper.CreateServer(_app, SiteName, + services => + { + _configureServices(services); + services.AddInstance(waitService); + }); var client = server.CreateClient(); // Act @@ -44,7 +50,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FlushPointsAreExecutedForPagesWithoutLayouts() { var waitService = new WaitService(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); + var server = TestHelper.CreateServer(_app, SiteName, + services => + { + _configureServices(services); + services.AddInstance(waitService); + }); var client = server.CreateClient(); // Act @@ -79,7 +90,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FlushPointsAreExecutedForPagesWithComponentsPartialsAndSections(string action, string title) { var waitService = new WaitService(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); + var server = TestHelper.CreateServer(_app, SiteName, + services => + { + _configureServices(services); + services.AddInstance(waitService); + }); var client = server.CreateClient(); // Act @@ -115,7 +131,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var waitService = new WaitService(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); + var server = TestHelper.CreateServer(_app, SiteName, + services => + { + _configureServices(services); + services.AddInstance(waitService); + }); var client = server.CreateClient(); // Act @@ -136,7 +157,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FlushBeforeCallingLayout() { var waitService = new WaitService(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); + var server = TestHelper.CreateServer(_app, SiteName, + services => + { + _configureServices(services); + services.AddInstance(waitService); + }); var client = server.CreateClient(); var expectedMessage = "A layout page cannot be rendered after 'FlushAsync' has been invoked."; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs index d608387a4f..71a173675d 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -13,12 +14,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FormatFilterWebSite); private readonly Action _app = new FormatFilterWebSite.Startup().Configure; + private readonly Action _configureServices = new FormatFilterWebSite.Startup().ConfigureServices; [Fact] public async Task FormatFilter_NoExtensionInRequest() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -33,7 +35,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_Default() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -48,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_Optional() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -63,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_Custom() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -78,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_CaseInsensitivity() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -93,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_NonExistant() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -107,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_And_ProducesFilter_Match() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -122,7 +124,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_And_ProducesFilter_Conflict() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -136,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_And_OverrideProducesFilter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs index 01772713d1..81f0ae2377 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs @@ -8,6 +8,7 @@ using System.Net.Http; using System.Threading.Tasks; using InlineConstraints; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(InlineConstraintsWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -38,7 +40,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -56,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductById_IntConstraintForOptionalId_IdPresent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -75,7 +77,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductById_IntConstraintForOptionalId_NoId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -92,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductById_IntConstraintForOptionalId_NotIntId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -106,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByName_AlphaContraintForMandatoryName_ValidName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -124,7 +126,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByName_AlphaContraintForMandatoryName_NonAlphaName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -138,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByName_AlphaContraintForMandatoryName_NoName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -152,7 +154,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByManufacturingDate_DateTimeConstraintForMandatoryDateTime_ValidDateTime() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -172,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryName_StringLengthConstraint_ForOptionalCategoryName_ValidCatName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -190,7 +192,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryName_StringLengthConstraint_ForOptionalCategoryName_InvalidCatName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -205,7 +207,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryName_StringLength1To20Constraint_ForOptionalCategoryName_NoCatName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -222,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryId_Int10To100Constraint_ForMandatoryCatId_ValidId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -240,7 +242,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryId_Int10To100Constraint_ForMandatoryCatId_InvalidId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -254,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryId_Int10To100Constraint_ForMandatoryCatId_NotIntId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -268,7 +270,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByPrice_FloatContraintForOptionalPrice_Valid() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -286,7 +288,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByPrice_FloatContraintForOptionalPrice_NoPrice() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -303,7 +305,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByManufacturerId_IntMin10Constraint_ForOptionalManufacturerId_Valid() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -321,7 +323,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByManufacturerId_IntMin10Cinstraint_ForOptionalManufacturerId_NoId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -338,7 +340,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetUserByName_RegExConstraint_ForMandatoryName_Valid() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -356,7 +358,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetUserByName_RegExConstraint_ForMandatoryName_InValid() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -370,7 +372,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreById_GuidConstraintForOptionalId_Valid() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -389,7 +391,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreById_GuidConstraintForOptionalId_NoId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -406,7 +408,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreById_GuidConstraintForOptionalId_NotGuidId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -420,7 +422,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_Valid() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -438,7 +440,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_MoreLength() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -452,7 +454,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_LessLength() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -466,7 +468,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_NoAlpha() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -623,7 +625,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedLink) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs index 63b102eba7..055c2962b9 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs @@ -8,6 +8,7 @@ using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,12 +18,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; + private readonly Action _configureServices = new FormatterWebSite.Startup().ConfigureServices; + [Fact] public async Task CheckIfXmlInputFormatterIsBeingCalled() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var sampleInputInt = 10; var input = "" + @@ -47,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsSelectedForJsonRequest(string requestContentType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var sampleInputInt = 10; var input = "{\"SampleInt\":10}"; @@ -79,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var actionName = filterHandlesModelStateError ? "ActionFilterHandlesError" : "ActionHandlesError"; var expectedSource = filterHandlesModelStateError ? "filter" : "action"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{\"SampleInt\":10}"; var content = new StringContent(input); @@ -110,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsModelStateValid_ForValidContentType(string requestContentType, string jsonInput, int expectedSampleIntValue) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent(jsonInput, Encoding.UTF8, requestContentType); @@ -130,7 +133,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsModelStateInvalid_ForEmptyContentType(string jsonInput) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent(jsonInput, Encoding.UTF8, "application/json"); content.Headers.Clear(); @@ -149,7 +152,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsModelStateValid_ForTransferEncodingChunk(string requestContentType, string jsonInput, int expectedSampleIntValue) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent(jsonInput, Encoding.UTF8, requestContentType); client.DefaultRequestHeaders.TransferEncodingChunked = true; @@ -169,7 +172,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CustomFormatter_IsSelected_ForSupportedContentTypeAndEncoding(string encoding) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent("Test Content", Encoding.GetEncoding(encoding), "text/plain"); @@ -188,7 +191,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CustomFormatter_NotSelected_ForUnsupportedContentType(string contentType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent("Test Content", Encoding.UTF8, contentType); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs index 33b10d785a..a286994446 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.WebUtilities; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -19,6 +20,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; + private readonly Action _configureServices = new FormatterWebSite.Startup().ConfigureServices; // Parameters: Request Content, Expected status code, Expected model state error message public static IEnumerable SimpleTypePropertiesModelRequestData @@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfObjectIsDeserializedWithoutErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var sampleId = 2; var sampleName = "SampleUser"; @@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfObjectIsDeserialized_WithErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var sampleId = 0; var sampleName = "user"; @@ -100,7 +102,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfExcludedFieldsAreNotValidated() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent("{\"Alias\":\"xyz\"}", Encoding.UTF8, "application/json"); @@ -117,7 +119,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ShallowValidation_HappensOnExcluded_ComplexTypeProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var requestData = "{\"Name\":\"Library Manager\", \"Suppliers\": [{\"Name\":\"Contoso Corp\"}]}"; var content = new StringContent(requestData, Encoding.UTF8, "application/json"); @@ -150,7 +152,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedModelStateErrorMessage) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent(requestContent, Encoding.UTF8, "application/json"); @@ -172,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfExcludedField_IsValidatedForNonBodyBoundModels() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var kvps = new List>(); kvps.Add(new KeyValuePair("Alias", "xyz")); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs index 1162e80259..39e6fe1a82 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs @@ -8,6 +8,7 @@ using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,6 +18,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; + private readonly Action _configureServices = new FormatterWebSite.Startup().ConfigureServices; + [Fact] public async Task JsonOutputFormatter_ReturnsIndentedJson() @@ -35,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests serializerSettings.Formatting = Formatting.Indented; var expectedBody = JsonConvert.SerializeObject(user, serializerSettings); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -50,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SerializableErrorIsReturnedInExpectedFormat() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "" + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs index 12cf32f9c5..aeeb086249 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -14,6 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; + private readonly Action _configureServices = new BasicWebSite.Startup().ConfigureServices; [Theory] [InlineData("application/json")] @@ -21,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_Conneg(string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/Plain"; @@ -47,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_Conneg_Fails(string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/Plain"; @@ -70,7 +72,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_Null() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/Null"; @@ -92,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_String() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/String"; @@ -115,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_CustomFormatter_Conneg(string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/CustomFormatter"; @@ -141,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_CustomFormatter_Conneg_Fails(string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/CustomFormatter"; @@ -163,7 +165,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_CustomContentType() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/JsonResult/CustomContentType"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs index 28f1d6a246..24aede01de 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs @@ -7,6 +7,7 @@ using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,6 +16,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; + private readonly Action _configureServices = new BasicWebSite.Startup().ConfigureServices; + // Some tests require comparing the actual response body against an expected response baseline // so they require a reference to the assembly on which the resources are located, in order to @@ -28,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GeneratedLinksWithActionResults_AreRelativeLinks_WhenSetOnLocationHeader(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -47,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GeneratedLinks_AreNotPunyEncoded_WhenGeneratedOnViews() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs index c312dd32d8..7a44c89fc8 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using LoggingWebSite; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Logging; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -20,12 +21,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(LoggingWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task Successful_ActionSelection_Logged() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var requestTraceId = Guid.NewGuid().ToString(); @@ -60,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Failed_ActionSelection_Logged() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var requestTraceId = Guid.NewGuid().ToString(); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs index a589c3deb8..36f19f8fd7 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs @@ -11,6 +11,7 @@ using LoggingWebSite.Controllers; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Logging; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -20,6 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(LoggingWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task AssemblyValues_LoggedAtStartup() @@ -87,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private async Task> GetLogsByDataTypeAsync() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var response = await client.GetStringAsync("http://localhost/logs"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs index 2ca0a68ea4..204164aeed 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite; using ModelBindingWebSite.Controllers; using ModelBindingWebSite.Models; @@ -18,12 +19,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task FromForm_CustomModelPrefix_ForParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateCompany"; @@ -51,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_CustomModelPrefix_ForCollectionParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateCompanyFromEmployees"; @@ -77,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_CustomModelPrefix_ForProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateCompany"; @@ -103,7 +105,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_CustomModelPrefix_ForCollectionProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateDepartment"; @@ -130,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_NonExistingValueAddsValidationErrors_OnProperty_UsingCustomModelPrefix() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/ValidateDepartment"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs index 9336702ad2..78eea0ea15 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -15,7 +16,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new ModelBindingWebSite.Startup().Configure; - + private readonly Action _configureServices = new ModelBindingWebSite.Startup().ConfigureServices; + // The action that this test hits will echo back the model-bound value [Theory] [InlineData("transactionId", "1e331f25-0869-4c87-8a94-64e6e40cb5a0")] @@ -26,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = headerValue; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringParameter"); @@ -50,7 +52,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var title = "How to make really really good soup."; var tags = new string[] { "Cooking", "Recipes", "Awesome" }; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToProperty/CustomName"); @@ -76,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var tags = new string[] { "Cooking", "Recipes", "Awesome" }; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToProperty/CustomName"); @@ -99,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_NonExistingHeaderAddsValidationErrors_OnCollectionProperty_CustomName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToProperty/CustomName"); @@ -125,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = "1e331f25-0869-4c87-8a94-64e6e40cb5a0"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringParameter/CustomName"); @@ -153,7 +155,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = headerValue; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringParameter"); @@ -181,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string headerValue) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -212,7 +214,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = headerValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringArrayParameter"); @@ -240,7 +242,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var title = "How to make really really good soup."; var tags = new string[] { "Cooking", "Recipes", "Awesome" }; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToModel?author=Marvin"); @@ -268,7 +270,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_BindHeader_ToModel_NoValues_ValidationError() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToModel?author=Marvin"); @@ -298,7 +300,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_BindHeader_ToModel_NoValues_InitializedValue_ValidationError() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -330,7 +332,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_BindHeader_ToModel_NoValues_DefaultValue_NoValidationError() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs index 9fd6f78fee..11243fbe9c 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite; using ModelBindingWebSite.Controllers; using ModelBindingWebSite.Models; @@ -16,12 +17,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task FromQuery_CustomModelPrefix_ForParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [FromQuery(Name = "customPrefix")] is used to apply a prefix @@ -43,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_CustomModelPrefix_ForCollectionParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = @@ -64,7 +66,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_CustomModelPrefix_ForProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [FromQuery(Name = "EmployeeId")] is used to apply a prefix @@ -87,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_CustomModelPrefix_ForCollectionProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = @@ -110,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_NonExistingValueAddsValidationErrors_OnProperty_UsingCustomModelPrefix() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs index 31e02e28b9..8664b0f4b0 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite; using ModelBindingWebSite.Models; using Newtonsoft.Json; @@ -17,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task FromRoute_CustomModelPrefix_ForParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [FromRoute(Name = "customPrefix")] is used to apply a prefix @@ -42,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromRoute_CustomModelPrefix_ForProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [FromRoute(Name = "EmployeeId")] is used to apply a prefix @@ -63,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromRoute_NonExistingValueAddsValidationErrors_OnProperty_UsingCustomModelPrefix() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [FromRoute(Name = "TestEmployees")] is used to apply a prefix diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs index 57d3d54bb7..f56b3ecb57 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite.Models; using Newtonsoft.Json; using Xunit; @@ -14,12 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new ModelBindingWebSite.Startup().Configure; + private readonly Action _configureServices = new ModelBindingWebSite.Startup().ConfigureServices; + [Fact] public async Task ModelBinderAttribute_CustomModelPrefix() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [ModelBinder(Name = "customPrefix")] is used to apply a prefix @@ -41,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_CustomModelPrefix_OnProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = @@ -64,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_WithPrefixOnParameter(string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // [ModelBinder(Name = "customPrefix")] is used to apply a prefix @@ -89,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_WithBinderOnParameter(string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = @@ -111,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_WithBinderOnEnum() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs index e550a7c1d1..5e0b962984 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite.Models; using ModelBindingWebSite.ViewModels; using Newtonsoft.Json; @@ -22,12 +23,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new ModelBindingWebSite.Startup().Configure; + private readonly Action _configureServices = new ModelBindingWebSite.Startup().ConfigureServices; [Fact] public async Task TypeBasedExclusion_ForBodyAndNonBodyBoundModels() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Make sure the body object gets created with an invalid zip. @@ -49,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelValidation_DoesNotValidate_AnAlreadyValidatedObject() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -69,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CompositeModelBinder_Restricts_ValueProviders(string actionName, string expectedValue) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -94,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_WithAPropertyFromBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // the name would be of customer.Department.Name @@ -120,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanModelBindServiceToAnArgument() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -134,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task CanModelBindServiceToAProperty() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -149,7 +151,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task CanModelBindServiceToAProperty_OnBaseType() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -165,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParametersMarkedWithFromBody_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -183,7 +185,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParameterAndPropertiesMarkedWithFromBody_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -201,7 +203,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParametersMarkedWith_FromFormAndFromBody_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -219,7 +221,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParameterAndPropertiesMarkedWith_FromFormAndFromBody_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -237,7 +239,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_MultipleParameters_UsingFromForm() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, @@ -275,7 +277,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_MultipleProperties_UsingFromForm() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, @@ -313,7 +315,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_OnParameters_UsingFromAttributes() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -357,7 +359,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_OnProperties_UsingFromAttributes() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -401,7 +403,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_OnProperties_UsingFromAttributes_WithBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -441,7 +443,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NonExistingModelBinder_ForABinderMetadata_DoesNotRecurseInfinitely() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act & Assert @@ -459,7 +461,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersWithNoValueProviderMetadataUseTheAvailableValueProviders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -481,7 +483,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersAreAlwaysCreated_IfValuesAreProvidedWithoutModelName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -503,7 +505,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersAreAlwaysCreated_IfValueIsProvidedForModelName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -524,7 +526,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersAreAlwaysCreated_IfNoValuesAreProvided() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -545,7 +547,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreBound_IfTheyAreProvidedByValueProviders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -567,7 +569,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreBound_IfTheyAreMarkedExplicitly() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -588,7 +590,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreBound_IfTheyArePocoMetadataMarkedTypes() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -613,7 +615,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreNotBound_ByDefault() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -635,7 +637,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_FromRouteData(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -658,7 +660,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindCancellationTokenParameteres() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -673,7 +675,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindCancellationToken_ForProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -689,7 +691,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindingBindsBase64StringsToByteArrays() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -704,7 +706,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindingBindsEmptyStringsToByteArrays() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -719,7 +721,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinding_LimitsErrorsToMaxErrorCount() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var queryString = string.Join("=&", Enumerable.Range(0, 10).Select(i => "field" + i)); @@ -744,7 +746,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinding_ValidatesAllPropertiesInModel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -762,7 +764,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_Filters_UsingDefaultPropertyFilterProvider_WithExpressions() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -785,7 +787,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_Filters_UsingPropertyFilterProvider_UsingServices() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -808,7 +810,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_Filters_UsingDefaultPropertyFilterProvider_WithPredicate() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -827,7 +829,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_AppliesAtBothParameterAndTypeLevelTogether_BlacklistedAtEitherLevelIsNotBound() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -846,7 +848,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_AppliesAtBothParameterAndTypeLevelTogether_IncludedAtBothLevelsIsBound() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -864,7 +866,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_AppliesAtBothParameterAndTypeLevelTogether_IncludingAtOneLevelIsNotBound() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -883,7 +885,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_BindsUsingParameterPrefix() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -899,7 +901,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_DoesNotUseTypePrefix() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -915,7 +917,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_FallsBackOnEmptyPrefixIfNoParameterPrefixIsProvided() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -931,7 +933,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_DoesNotFallBackOnEmptyPrefixIfParameterPrefixIsProvided() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -948,7 +950,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_IncludeTopLevelProperty_IncludesAllSubProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -977,7 +979,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_ChainedPropertyExpression_Throws() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); Expression> expression = model => model.Address.Country; @@ -999,7 +1001,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_FailsToUpdateProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1018,7 +1020,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_IncludeExpression_WorksOnlyAtTopLevel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1041,7 +1043,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_Validates_ForTopLevelNotIncludedProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1058,7 +1060,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelExcludeSpecific_Properties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1081,7 +1083,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelIncludeSpecific_Properties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1104,7 +1106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelIncludesAllProperties_ByDefault() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1127,7 +1129,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithJson_ProducesModelStateErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new { @@ -1163,7 +1165,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithJson_DoesPropertyValidationPriorToValidationAtType() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new { @@ -1197,7 +1199,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithJson_BindsBodyAndServices() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var trackingId = Guid.NewGuid().ToString(); var postedContent = new @@ -1234,7 +1236,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithXml_BindsBodyServicesAndHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var trackingId = Guid.NewGuid().ToString(); var postedContent = new VehicleViewModel @@ -1274,7 +1276,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/UpdateDealerVehicle_PopulatesPropertyErrorsInViews.txt"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var postedContent = new { @@ -1305,7 +1307,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/UpdateDealerVehicle_PopulatesValidationSummary.txt"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var postedContent = new { @@ -1336,7 +1338,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/UpdateDealerVehicle_UpdateSuccessful.txt"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var postedContent = new { @@ -1365,7 +1367,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_SingleFile() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadSingle"; var formData = new MultipartFormDataContent("Upload----"); @@ -1386,7 +1388,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_MultipleFiles() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadMultiple"; var formData = new MultipartFormDataContent("Upload----"); @@ -1411,7 +1413,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_MultipleListOfFiles() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadMultipleList"; var formData = new MultipartFormDataContent("Upload----"); @@ -1446,7 +1448,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_FileInsideModel() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadModelWithFile"; var formData = new MultipartFormDataContent("Upload----"); @@ -1471,7 +1473,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_ReturnDerivedAndBaseProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1494,7 +1496,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/ModelBindingWebSite.Vehicle.Details.html"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/vehicles/42"; @@ -1514,7 +1516,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/ModelBindingWebSite.Vehicle.Edit.html"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/vehicles/42/edit"; @@ -1534,7 +1536,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/ModelBindingWebSite.Vehicle.Edit.Invalid.html"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/vehicles/42/edit"; var contentDictionary = new Dictionary @@ -1572,7 +1574,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/Home/GetErrorMessage"; @@ -1595,7 +1597,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task OverriddenMetadataProvider_CanChangeAdditionalValues() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/AdditionalValues"; var expectedDictionary = new Dictionary @@ -1618,7 +1620,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task OverriddenMetadataProvider_CanUseAttributesToChangeAdditionalValues() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/GroupNames"; var expectedDictionary = new Dictionary @@ -1645,7 +1647,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelNonGeneric_IncludesAllProperties_CanBind() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1668,7 +1670,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CanBind_FormValues() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnValuesAsList"; var nameValueCollection = new List> @@ -1692,7 +1694,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CanBind_FormValuesWithDuplicateKeys() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnValuesAsList"; var nameValueCollection = new List> @@ -1717,7 +1719,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CannotBind_NonFormValues() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnCollectionCount"; var data = new StringContent("Non form content"); @@ -1736,7 +1738,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CanBind_FormWithFile() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnFileContent"; var expectedContent = "Test Content"; @@ -1756,7 +1758,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelNonGenericIncludesAllProperties_ByDefault() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1822,7 +1824,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests IEnumerable expectedModelStateErrorMessages) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new StringContent(input, Encoding.UTF8, "text/json"); @@ -1848,7 +1850,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithCollection() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new Dictionary { @@ -1874,7 +1876,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithCollection_SpecifyingIndex() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new[] { @@ -1900,7 +1902,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithNestedCollection() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new Dictionary { @@ -1935,7 +1937,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithIncorrectlyFormattedNestedCollectionValue() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new Dictionary { @@ -1958,7 +1960,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithNestedCollectionContainingRecursiveRelation() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new Dictionary { @@ -1996,7 +1998,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithNestedCollectionContainingRecursiveRelation_WithMalformedValue() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new Dictionary { @@ -2023,7 +2025,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests bool expectedResult) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new List> { @@ -2045,7 +2047,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_CheckBoxesList_BindSuccessful() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var content = new List> { @@ -2070,7 +2072,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_ClearsModelStateEntries() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/TryUpdateModel/TryUpdateModel_ClearsModelStateEntries"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs index ee3878dd0f..5630bfe2cc 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -16,12 +17,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ValidationWebSite); private readonly Action _app = new ValidationWebSite.Startup().Configure; + private readonly Action _configureServices = new ValidationWebSite.Startup().ConfigureServices; [Fact] public async Task ModelMetaDataTypeAttribute_ValidBaseClass_EmptyResponseBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Name\": \"MVC\", \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\",\"Price\": 21, \"ProductDetails\": {\"Detail1\": \"d1\"," + @@ -42,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidPropertiesAndSubPropertiesOnBaseClass_ReturnsErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Price\": 2, \"ProductDetails\": {\"Detail1\": \"d1\"}}"; var content = new StringContent(input, Encoding.UTF8, "application/json"); @@ -68,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidComplexTypePropertyOnBaseClass_ReturnsErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Contact\":\"4255678765\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\",\"Price\": 21 }"; @@ -90,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidClassAttributeOnBaseClass_ReturnsErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"UK\",\"Price\": 21, \"ProductDetails\": {\"Detail1\": \"d1\"," + @@ -114,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_ValidDerivedClass_EmptyResponseBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Name\": \"MVC\", \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\", \"Version\":\"2\"," + @@ -135,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidPropertiesOnDerivedClass_ReturnsErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Name\": \"MVC\", \"Contact\":\"425-895-9019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\",\"Price\": 2}"; @@ -158,7 +160,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidClassAttributeOnBaseClassProduct_ReturnsErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"UK\",\"Version\":\"2\"," + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs index 29bb157a80..b8f42955a9 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -22,6 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private readonly static string SamplesFolder = Path.Combine("..", "..", "samples"); private readonly Action _app = new MvcSample.Web.Startup().Configure; + private readonly Func _configureServices = new MvcSample.Web.Startup().ConfigureServices; [Theory] [InlineData("")] // Shared/MyView.cshtml @@ -39,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Home_Pages_ReturnSuccess(string path) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); // Act @@ -66,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormUrlEncoded_ReturnsAppropriateResults(string input, string expectedOutput) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/FormUrlEncoded/IsValidPerson"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -83,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormUrlEncoded_Index_ReturnSuccess() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); // Act @@ -98,7 +100,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Home_NotFoundAction_Returns404() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); // Act @@ -113,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Home_CreateUser_ReturnsXmlBasedOnAcceptHeader() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Home/ReturnUser"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8")); @@ -141,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FiltersController_Tests(string url, HttpStatusCode statusCode) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); // Act @@ -156,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FiltersController_Crash_ThrowsException() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs index 96ef8f72bb..606b38e0f7 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -17,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expectedMessage = "Unable to find the required services. Please add all the required " + - "services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.UseServices(...)' " + + "services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.ConfigureServices(...)' " + "or 'IApplicationBuilder.UseMvc(...)' in the application startup code."; // Act & Assert diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs index 21faad73fa..d569afdfa4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(MvcTagHelpersWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; private static readonly Assembly _resourcesAssembly = typeof(MvcTagHelpersTest).GetTypeInfo().Assembly; [Theory] @@ -48,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MvcTagHelpers_GeneratesExpectedResults(string action, string antiForgeryPath) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -79,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValidationTagHelpers_GeneratesExpectedSpansAndDivs() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Customer.Index.html"); @@ -113,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var assertFile = "compiler/resources/CacheTagHelper_CanCachePortionsOfViewsPartialViewsAndViewComponents.Assert"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); client.DefaultRequestHeaders.Add("Locale", "North"); @@ -162,7 +163,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_ExpiresContent_BasedOnExpiresParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -186,7 +187,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_UsesVaryByCookie_ToVaryContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -218,7 +219,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_VariesByRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -274,7 +275,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_VariesByUserId() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -301,7 +302,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_BubblesExpirationOfNestedTagHelpers() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -346,7 +347,12 @@ Products: Laptops (3)"; // Arrange var newServices = new ServiceCollection(); newServices.InitializeTagHelper((helper, _) => helper.AntiForgery = optionsAntiForgery); - var server = TestHelper.CreateServer(_app, SiteName, services => services.Add(newServices)); + var server = TestHelper.CreateServer(_app, SiteName, + services => + { + services.Add(newServices); + _configureServices(services); + }); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs index 0001fa51bb..0d0fafbaff 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs @@ -7,6 +7,7 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using ContentNegotiationWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ContentNegotiationWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Theory] [InlineData("ReturnTaskOfString")] @@ -24,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task StringOutputFormatter_ForStringValues_GetsSelectedReturnsTextPlainContentType(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("text/plain;charset=utf-8"); var expectedBody = actionName; @@ -44,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonOutputFormatter_ForNonStringValue_GetsSelected(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -61,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoContentFormatter_ForVoidAndTaskReturnType_GetsSelectedAndWritesResponse(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -83,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoContentFormatter_ForNullValue_ByDefault_GetsSelectedAndWritesResponse(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -106,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests NoContentFormatter_ForNullValue_AndTreatNullAsNoContentFlagSetToFalse_DoesNotGetSelected(string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs index cc00f9753f..065b71499f 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs @@ -21,13 +21,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private const string SiteName = nameof(PrecompilationWebSite); private static readonly TimeSpan _cacheDelayInterval = TimeSpan.FromSeconds(1); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task PrecompiledView_RendersCorrectly() { // Arrange IServiceCollection serviceCollection = null; - var server = TestHelper.CreateServer(_app, SiteName, services => serviceCollection = services); + var server = TestHelper.CreateServer(_app, SiteName, services => + { + _configureServices(services); + serviceCollection = services; + }); var client = server.CreateClient(); var serviceProvider = serviceCollection.BuildServiceProvider(); @@ -170,7 +175,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests @"Value set inside DNXCORE50 " + assemblyNamePrefix; #endif - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -187,7 +192,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = GetAssemblyNamePrefix(); IServiceCollection serviceCollection = null; - var server = TestHelper.CreateServer(_app, SiteName, services => serviceCollection = services); + var server = TestHelper.CreateServer(_app, SiteName, services => + { + _configureServices(services); + serviceCollection = services; + }); var client = server.CreateClient(); var serviceProvider = serviceCollection.BuildServiceProvider(); @@ -229,7 +238,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var expected = @"Back to List"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -247,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var assemblyNamePrefix = GetAssemblyNamePrefix(); var expected = @"root-content"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs index 3b2c24c308..17bb700688 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using RazorCompilerCacheWebSite; using Xunit; @@ -14,12 +15,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorCompilerCacheWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task CompilerCache_IsNotInitializedUntilFirstViewRequest() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs index f8ccc14b22..f9d380bb99 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using RazorEmbeddedViewsWebSite; using Xunit; @@ -13,13 +14,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorEmbeddedViewsWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateViews() { // Arrange var expectedMessage = "Hello test-user, this is /RazorEmbeddedViews_Home"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -34,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expectedMessage = "Hello admin-user, this is /Restricted/RazorEmbeddedViews_Admin/Login"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var target = "http://localhost/Restricted/RazorEmbeddedViews_Admin/Login?AdminUser=admin-user"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs index e362e3c8a6..c844a79744 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs @@ -15,6 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorPageExecutionInstrumentationWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; public static IEnumerable InstrumentationData { @@ -100,7 +101,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var context = new TestPageExecutionContext(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); + var server = TestHelper.CreateServer(_app, SiteName, services => + { + services.AddInstance(context); + _configureServices(services); + }); var client = server.CreateClient(); // Act @@ -120,7 +125,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var context = new TestPageExecutionContext(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); + var server = TestHelper.CreateServer(_app, SiteName, services => + { + services.AddInstance(context); + _configureServices(services); + }); var client = server.CreateClient(); client.DefaultRequestHeaders.Add("ENABLE-RAZOR-INSTRUMENTATION", "true"); @@ -141,7 +150,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange - 1 var context = new TestPageExecutionContext(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); + var server = TestHelper.CreateServer(_app, SiteName, services => + { + services.AddInstance(context); + _configureServices(services); + }); var client = server.CreateClient(); // Act - 1 @@ -183,7 +196,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests Tuple.Create(35, 8, true), }; var context = new TestPageExecutionContext(); - var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); + var server = TestHelper.CreateServer(_app, SiteName, services => + { + services.AddInstance(context); + _configureServices(services); + }); var client = server.CreateClient(); // Act - 1 diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs index e9161e485b..7129a41c7d 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using RazorWebSite; using Xunit; @@ -14,6 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private const string BaseUrl = "http://localhost/ViewNameSpecification_Home/"; private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Theory] [InlineData("LayoutSpecifiedWithPartialPathInViewStart")] @@ -26,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests @" _ViewStart that specifies partial Layout "; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -47,7 +49,7 @@ _ViewStart that specifies partial Layout @" Layout specified in page "; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -66,7 +68,7 @@ Layout specified in page @" Page With Non Partial Layout "; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -88,7 +90,7 @@ Page With Non Partial Layout Non Shared Partial "; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs index 5f3fbe59b4..f109f906ea 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs @@ -8,6 +8,7 @@ using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -18,6 +19,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private static readonly Assembly _resourcesAssembly = typeof(RemoteAttributeValidationTest).GetTypeInfo().Assembly; private readonly Action _app = new ValidationWebSite.Startup().Configure; + private readonly Action _configureServices = new ValidationWebSite.Startup().ConfigureServices; [Theory] [InlineData("Aria", "/Aria")] @@ -25,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RemoteAttribute_LeadsToExpectedValidationAttributes(string areaName, string pathSegment) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/ValidationWebSite." + areaName + ".RemoteAttribute_Home.Create.html"); @@ -52,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedContent) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost" + pathSegment + "/RemoteAttribute_Verify/IsIdAvailable?UserId1=Joe1&UserId2=Joe2&UserId3=Joe3&UserId4=Joe4"; @@ -76,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedContent) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost" + pathSegment + "/RemoteAttribute_Verify/IsIdAvailable"; var contentDictionary = new Dictionary diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs index d0091b8a73..e9bc996b2d 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RequestServicesWebSite); private readonly Action _app = new RequestServicesWebSite.Startup().Configure; + private readonly Action _configureServices = new RequestServicesWebSite.Startup().ConfigureServices; [Theory] [InlineData("http://localhost/RequestScoped/FromController")] @@ -27,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequestServices(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act & Assert @@ -48,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequestServices_TagHelper() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/Other/FromTagHelper"; @@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequestServices_ActionConstraint() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/Other/FromActionConstraint"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs index 3dc45c45e4..c687f12bbb 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; + private readonly Action _configureServices = new FormatterWebSite.Startup().ConfigureServices; [Theory] [InlineData("application/xml,*/*;0.2")] @@ -23,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllMediaRangeAcceptHeader_FirstFormatterInListWritesResponse(string acceptHeader) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Add("Accept", acceptHeader); @@ -45,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllMediaRangeAcceptHeader_ProducesAttributeIsHonored(string acceptHeader) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Add("Accept", acceptHeader); var expectedResponseData = " _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task ResponseCache_SetsAllHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -48,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsDifferentCacheControlHeaders(string url, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -63,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetsHeadersForAllActionsOfClass() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -86,7 +88,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HeadersSetInActionOverridesTheOnesInClass() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -101,7 +103,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HeadersToNotCacheAParticularAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -116,7 +118,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ClassLevelHeadersAreUnsetByActionLevelHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -136,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetsCacheControlPublicByDefault() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -151,7 +153,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowsWhenDurationIsNotSet() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act & Assert @@ -167,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsAllHeaders_FromCacheProfile() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -182,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsAllHeaders_ChosesTheRightProfile() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -197,7 +199,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsNoCacheHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -214,7 +216,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_AddsHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -231,7 +233,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_ModifiesHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -246,7 +248,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCacheAttribute_OnAction_OverridesTheValuesOnClass() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs index 15ae9f62d3..6df2a39a1a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite; using ModelBindingWebSite.Models; using Newtonsoft.Json; @@ -25,6 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; // Uses the expression p => p.Name [Fact] @@ -32,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "test-name"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -54,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = 40; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -76,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = 12; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -97,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RoundTrippedValues_GetsModelBound_ForStringIndexedProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -114,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "test-nested-name"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs index 6117b0dcd4..b0705b0ba0 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs @@ -9,6 +9,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing.Template; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -18,12 +19,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; + private readonly Action _configureServices = new BasicWebSite.Startup().ConfigureServices; [Fact] public async Task RouteData_Routers_ConventionalRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -48,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteData_Routers_AttributeRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -78,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteData_DataTokens_FilterCanSetDataTokens() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var response = await client.GetAsync("http://localhost/Routing/DataTokens"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs index 1753eb8c18..e50c427b2b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // This website sets the generation of lowercase URLs to true private readonly Action _app = new LowercaseUrlsWebSite.Startup().Configure; + private readonly Action _configureServices = new LowercaseUrlsWebSite.Startup().ConfigureServices; [Theory] // Generating lower case URL doesnt lowercase the query parameters @@ -34,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GenerateLowerCaseUrlsTests(string path, string expectedUrl) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs index a3e15d3761..d1681a3f57 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs @@ -9,6 +9,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Routing; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -18,12 +19,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RoutingWebSite); private readonly Action _app = new RoutingWebSite.Startup().Configure; + private readonly Action _configureServices = new RoutingWebSite.Startup().ConfigureServices; [Fact] public async Task ConventionRoutedController_ActionIsReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -51,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_ActionIsReachable_WithDefaults() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -79,7 +81,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_NonActionIsNotReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -93,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_InArea_ActionIsReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -122,7 +124,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_InArea_ActionBlockedByHttpMethod() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -136,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_IsReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -167,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_MultipleRouteAttributes_WorksWithNameAndOrder(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -196,7 +198,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var url = "http://localhost/api/v2/Maps"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -224,7 +226,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var url = "http://localhost/api/v1/Maps"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -244,7 +246,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -273,7 +275,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_MultipleHttpAttributesAndTokenReplacement(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedUrl = new Uri(url).AbsolutePath; @@ -307,7 +309,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedUrl = new Uri(url).AbsolutePath; @@ -323,7 +325,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_IsNotReachableWithTraditionalRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -339,7 +341,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_TriedBeforeConventionRouting() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -360,7 +362,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_WithActionParameter_IsReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -394,7 +396,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_IsReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -423,7 +425,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_RouteAttributeOnAction_IsReachable(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var message = new HttpRequestMessage(new HttpMethod(method), "http://localhost/Store/Shop/Orders"); @@ -450,7 +452,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_RouteAttributeOnActionAndController_IsReachable(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var message = new HttpRequestMessage(new HttpMethod(method), "http://localhost/api/Employee/5/Salary"); @@ -472,7 +474,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_RouteAttributeOnActionAndHttpGetOnDifferentAction_ReachesHttpGetAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var message = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Store/Shop/Orders"); @@ -497,7 +499,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_WithAcceptVerbs_IsReachable(string verb) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -521,7 +523,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_WithAcceptVerbsAndRouteTemplate_IsReachable(string verb) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -547,7 +549,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_AcceptVerbsAndRouteTemplate_IsReachable(string verb, string path) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedUrl = "/Bank"; @@ -570,7 +572,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_WithCustomHttpAttributes_IsReachable() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -596,7 +598,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_CombinedWithActionRoute_IsReachable(string verb, string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -622,7 +624,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ActionLevelRouteWithTildeSlash_OverridesControllerLevelRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -647,7 +649,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_OverrideActionOverridesOrderOnController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -672,7 +674,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_OrderOnActionOverridesOrderOnController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -693,7 +695,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkGeneration_OverrideActionOverridesOrderOnController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -708,7 +710,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkGeneration_OrderOnActionOverridesOrderOnController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -723,7 +725,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToSelf() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -746,7 +748,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithAmbientController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -769,7 +771,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToAttributeRoutedController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -793,7 +795,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToConventionalController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -818,7 +820,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithName_WithNameInheritedFromControllerRoute(string method, string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -842,7 +844,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithName_WithNameOverrridenFromController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -865,7 +867,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_Link_WithNonEmptyActionRouteTemplateAndNoActionRouteName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = LinkFrom("http://localhost") @@ -891,7 +893,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithName_WithNonEmptyActionRouteTemplateAndActionRouteName() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -918,7 +920,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ThowsIfConventionalRouteWithTheSameName(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMessage = "The supplied route name 'DuplicateRoute' is ambiguous and matched more than one route."; @@ -935,7 +937,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_LinkToArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -959,7 +961,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_ImplicitLinkToArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -982,7 +984,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_ExplicitLeaveArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1005,7 +1007,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_ImplicitLeaveArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1028,7 +1030,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1052,7 +1054,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_ImplicitLinkToArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1075,7 +1077,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_ExplicitLeaveArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1099,7 +1101,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_ImplicitLeaveArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1123,7 +1125,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_LinkToConventionalRoutedActionInArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1148,7 +1150,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_LinkToAttributeRoutedActionInArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1173,7 +1175,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_LinkToAnotherArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1198,7 +1200,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_LinkToAnotherArea() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1223,7 +1225,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_CanReachSpecificCountry() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1253,7 +1255,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_CannotReachWithoutCountry() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1267,7 +1269,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_GenerateLinkForSpecificCountry() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1287,7 +1289,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_GenerateLinkForFallback() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1307,7 +1309,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_GenerateLink_FailsWithoutCountry() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -1332,7 +1334,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRouting_MixedAcceptVerbsAndRoute_Reachable(string path, string verb, string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(verb), "http://localhost" + path); @@ -1359,7 +1361,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRouting_MixedAcceptVerbsAndRoute_Unreachable(string path, string verb) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(verb), "http://localhost" + path); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs index e4d8285058..63a423e5bf 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -17,6 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; + private readonly Action _configureServices = new XmlFormattersWebSite.Startup().ConfigureServices; [Theory] #if !DNXCORE50 @@ -26,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelStateErrors_AreSerialized(string acceptHeader) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader)); var expectedXml = "key1-errorThe input was not valid."; @@ -51,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PostedSerializableError_IsBound(string acceptHeader) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader)); var expectedXml = "key1-errorThe input was not valid."; @@ -75,7 +77,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task IsReturnedInExpectedFormat(string acceptHeader) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "" + "" + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs index d31a865c8f..346f2c3ea6 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using FormatterWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -13,6 +14,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Theory] [InlineData("SimpleMemoryStream", null)] @@ -23,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task StreamOutputFormatter_ReturnsAppropriateContentAndContentType(string actionName, string contentType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs index 2b452d7168..fe6490e7b9 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs @@ -7,6 +7,7 @@ using System.IO; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Xunit; @@ -38,12 +39,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private readonly ILoggerFactory _loggerFactory = new TestLoggerFactory(); private readonly Action _app = new TagHelperSample.Web.Startup().Configure; + private readonly Action _configureServices = new TagHelperSample.Web.Startup().ConfigureServices; [Fact] public async Task Home_Pages_ReturnSuccess() { // Arrange - var server = TestHelper.CreateServer(app => _app(app, _loggerFactory), SiteName, SamplesFolder); + var server = TestHelper.CreateServer(app => _app(app, _loggerFactory), SiteName, SamplesFolder, _configureServices); var client = server.CreateClient(); for (var index = 0; index < Paths.Count; index++) diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs index 6a30b44eab..fde386477f 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Threading.Tasks; using BasicWebSite; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -18,6 +19,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(TagHelpersWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; // Some tests require comparing the actual response body against an expected response baseline // so they require a reference to the assembly on which the resources are located, in order to @@ -32,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanRenderViewsWithTagHelpers(string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -111,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TagHelpersAreInheritedFromGlobalImportPages(string action, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -125,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewsWithModelMetadataAttributes_CanRenderForm() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/TagHelpersWebSite.Employee.Create.html"); @@ -143,7 +145,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewsWithModelMetadataAttributes_CanRenderPostedValue() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/TagHelpersWebSite.Employee.Details.AfterCreate.html"); @@ -171,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewsWithModelMetadataAttributes_CanHandleInvalidData() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/TagHelpersWebSite.Employee.Create.Invalid.html"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs index 80900bee06..2fd81e6f6b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,12 +16,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(TempDataWebSite); private readonly Action _app = new TempDataWebSite.Startup().Configure; + private readonly Action _configureServices = new TempDataWebSite.Startup().ConfigureServices; [Fact] public async Task ViewRendersTempData() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var nameValueCollection = new List> { diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs index 5afdea682b..0f1a2f6860 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs @@ -5,10 +5,11 @@ using System; using System.IO; using System.Reflection; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Mvc.FunctionalTests { @@ -42,7 +43,38 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests configureServices: configureServices); } - private static TestServer CreateServer( + public static TestServer CreateServer( + Action builder, + string applicationWebSiteName, + string applicationPath, + Func configureServices) + { + return TestServer.Create( + CallContextServiceLocator.Locator.ServiceProvider, + builder, + services => + { + AddTestServices(services, applicationWebSiteName, applicationPath, configureServices: null); + return (configureServices != null) ? configureServices(services) : services.BuildServiceProvider(); + }); + } + + public static TestServer CreateServer( + Action builder, + string applicationWebSiteName, + Func configureServices) + { + return TestServer.Create( + CallContextServiceLocator.Locator.ServiceProvider, + builder, + services => + { + AddTestServices(services, applicationWebSiteName, applicationPath: null, configureServices: null); + return configureServices(services); + }); + } + + public static TestServer CreateServer( Action builder, string applicationWebSiteName, string applicationPath, @@ -50,10 +82,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { return TestServer.Create( builder, - services => AddServices(services, applicationWebSiteName, applicationPath, configureServices)); + services => AddTestServices(services, applicationWebSiteName, applicationPath, configureServices)); } - private static void AddServices( + private static void AddTestServices( IServiceCollection services, string applicationWebSiteName, string applicationPath, @@ -81,10 +113,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests applicationBasePath, applicationWebSiteName); services.AddInstance(environment); + services.AddInstance(new HostingEnvironment(environment)); // Injecting a custom assembly provider. Overrides AddMvc() because that uses TryAdd(). var assemblyProvider = CreateAssemblyProvider(applicationWebSiteName); - services.AddInstance(assemblyProvider); + services.AddInstance(assemblyProvider); if (configureServices != null) { diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs index e60ed11c6a..bada3c6be5 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs @@ -8,6 +8,7 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ValidationWebSite); private readonly Action _app = new ValidationWebSite.Startup().Configure; + private readonly Action _configureServices = new ValidationWebSite.Startup().ConfigureServices; [Fact] public async Task TryValidateModel_ClearParameterValidationError_ReturnsErrorsForInvalidProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "{ \"Price\": 2, \"Contact\": \"acvrdzersaererererfdsfdsfdsfsdf\", "+ "\"ProductDetails\": {\"Detail1\": \"d1\", \"Detail2\": \"d2\", \"Detail3\": \"d3\"}}"; @@ -54,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryValidateModel_InvalidTypeOnDerivedModel_ReturnsErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ModelMetadataTypeValidation/TryValidateModelSoftwareViewModelWithPrefix"; @@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryValidateModel_ValidDerivedModel_ReturnsEmptyResponseBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/ModelMetadataTypeValidation/TryValidateModelValidModelNoPrefix"; @@ -91,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryValidateModel_CollectionsModel_ReturnsErrorsForInvalidProperties() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "[ { \"Price\": 2, \"Contact\": \"acvrdzersaererererfdsfdsfdsfsdf\", " + "\"ProductDetails\": {\"Detail1\": \"d1\", \"Detail2\": \"d2\", \"Detail3\": \"d3\"} }," + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs index dcc1061aad..e557a2c6bb 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ValueProvidersWebSite; using Xunit; @@ -13,12 +14,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ValueProvidersWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; [Fact] public async Task ValueProviderFactories_AreVisitedInSequentialOrder_ForValueProviders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -32,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValueProviderFactories_ReturnsValuesFromQueryValueProvider() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValueProviderFactories_ReturnsValuesFromRouteValueProvider() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -66,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValueProvider_DeserializesEnumsWithFlags(string url, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs index 4b1d9a3a3a..d287996158 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(VersioningWebSite); readonly Action _app = new VersioningWebSite.Startup().Configure; + private readonly Action _configureServices = new VersioningWebSite.Startup().ConfigureServices; [Theory] [InlineData("1")] @@ -23,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_WithVersionedRoutes_IsNotAmbiguous(string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -48,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_WithAmbiguousVersionedRoutes_CanBeDisambiguatedUsingOrder(string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var query = "?version=" + version; var message = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/Addresses/All" + query); @@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheSameController_WithNoVersionSpecified() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -96,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheSameController_WithVersionSpecified() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -117,7 +119,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheSameController() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -138,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheSameController_WithVersionSpecified() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -167,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachOtherVersionOperations_OnTheSameController(string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -193,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanNotReachOtherVersionOperations_OnTheSameController_WithNoVersionSpecified() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -220,7 +222,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -248,7 +250,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanNotReachOtherVersionOperationsWithParameters_OnTheSameController_WithNoVersionSpecified(string method) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -269,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanUseOrderToDisambiguate_OverlappingVersionRanges(string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -293,7 +295,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_OverlappingVersionRanges_FallsBackToLowerOrderAction(string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -317,7 +319,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheOriginalController_WithNoVersionSpecified(string method, string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -340,7 +342,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheOriginalController_WithVersionSpecified(string method, string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -364,7 +366,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheOriginalController(string method, string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -387,7 +389,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheOriginalController_WithVersionSpecified(string method, string action) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -408,7 +410,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachOtherVersionOperationsWithParameters_OnTheV2Controller() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -432,7 +434,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanHaveTwoRoutesWithVersionOnTheUrl_OnTheSameAction(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -455,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanHaveTwoRoutesWithVersionOnTheUrl_OnDifferentActions(string url, string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -478,7 +480,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanHaveTwoRoutesWithVersionOnTheUrl_OnDifferentActions_WithInlineConstraint(string url, string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -504,7 +506,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanProvideVersioningInformation_UsingPlainActionConstraint(string url, string query, string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -525,7 +527,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_ConstraintOrder_IsRespected() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -546,7 +548,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanUseConstraintOrder_ToChangeSelectedAction() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -569,7 +571,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_MultipleVersionsUsingAttributeRouting_OnTheSameMethod(string version) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var path = "/" + version + "/Vouchers?version=" + version; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs index a59f2b2995..3db89d8039 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using ViewComponentWebSite; using Xunit; @@ -14,6 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(ViewComponentWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; public static IEnumerable ViewViewComponents_AreRenderedCorrectlyData { @@ -41,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [MemberData(nameof(ViewViewComponents_AreRenderedCorrectlyData))] public async Task ViewViewComponents_AreRenderedCorrectly(string actionName, string expected) { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -54,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ViewComponents_SupportsValueType() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingUnion", "Union")] public async Task ViewComponents_SupportsEnumerableModel(string url, string linqQueryType) { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -92,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("ViewComponentWebSite.Namespace2.SameName")] public async Task ViewComponents_FullName(string name) { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -105,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ViewComponents_ShortNameUsedForViewLookup() { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var name = "ViewComponentWebSite.Integer"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs index 55e827b8be..8bba0943bc 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using RazorWebSite; using Xunit; @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; public static IEnumerable RazorView_ExecutesPageAndLayoutData { @@ -62,7 +64,7 @@ ViewWithNestedLayout-Content [MemberData(nameof(RazorView_ExecutesPageAndLayoutData))] public async Task RazorView_ExecutesPageAndLayout(string actionName, string expected) { - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -83,7 +85,7 @@ ViewWithNestedLayout-Content "", "", "test-value"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -98,7 +100,7 @@ ViewWithNestedLayout-Content { // Arrange var expected = "HelloWorld"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -117,7 +119,7 @@ ViewWithNestedLayout-Content partial-content component-content"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -153,7 +155,7 @@ component-content"; public async Task RazorViewEngine_UsesViewExpandersForViewsAndPartials(string value, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -181,7 +183,7 @@ component-content"; public async Task ViewLocationExpanders_PassesInIsPartialToViewLocationExpanderContext(string action, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -246,7 +248,7 @@ ViewWithNestedLayout-Content public async Task RazorViewEngine_RendersPartialViews(string actionName, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -265,7 +267,7 @@ ViewWithNestedLayout-Content "", "~/Views/NestedViewStarts/NestedViewStarts/Layout.cshtml", "index-content"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -301,7 +303,7 @@ View With Layout public async Task RazorViewEngine_UsesExpandersForLayouts(string value, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -319,7 +321,7 @@ View With Layout var expected = @"Hello Controller-Person Hello Controller-Person"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var target = "http://localhost/NestedGlobalImports"; @@ -341,7 +343,7 @@ Page Content ViewComponent With Title Component With Layout"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -356,7 +358,7 @@ Component With Layout"; { // Arrange var expected = @"ViewComponent With ViewStart"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -371,7 +373,7 @@ Component With Layout"; { // Arrange var expected = "Partial that does not specify Layout"; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -390,7 +392,7 @@ Component With Layout"; Partial that specifies Layout Partial that does not specify Layout "; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -410,7 +412,7 @@ Partial that specifies Layout Partial that does not specify Layout "; - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -426,7 +428,7 @@ Partial that does not specify Layout // Arrange var expected = await GetType().GetTypeInfo().Assembly .ReadResourceAsStringAsync("compiler/resources/ViewEngineController.ViewWithPaths.txt"); - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs index 0a24e7cdd7..d8031aa277 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -13,12 +14,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; + private readonly Action _configureServices = new WebApiCompatShimWebSite.Startup().ConfigureServices; [Fact] public async Task ApiController_BadRequest() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -32,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_BadRequestMessage() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -48,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_BadRequestModelState() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"product.Name\":[\"Name is required.\"]}}"; @@ -66,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Conflict() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -80,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Content() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -96,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedRelative() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -113,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedAbsolute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -130,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedQualified() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -147,7 +149,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedUri() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -164,7 +166,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedAtRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -181,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_InternalServerError() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -195,7 +197,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_InternalServerErrorException() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -211,7 +213,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Json() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -227,7 +229,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_JsonSettings() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @@ -248,7 +250,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_JsonSettingsEncoding() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @@ -270,7 +272,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_NotFound() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -284,7 +286,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Ok() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -298,7 +300,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_OkContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -314,7 +316,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RedirectString() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -329,7 +331,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RedirectUri() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -344,7 +346,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ResponseMessage() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -359,7 +361,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_StatusCode() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs index 672f0389c2..abb2548eca 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; + private readonly Action _configureServices = new WebApiCompatShimWebSite.Startup().ConfigureServices; [Theory] [InlineData("GET", "GetItems")] @@ -27,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_UnnamedAction(string httpMethod, string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -56,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction(string httpMethod, string actionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -78,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction_MismatchedVerb() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -96,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_UnnamedAction_DefaultVerbIsPost_Success() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -118,7 +120,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction_DefaultVerbIsPost_Success() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -140,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_UnnamedAction_DefaultVerbIsPost_VerbMismatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -158,7 +160,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction_DefaultVerbIsPost_VerbMismatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -176,7 +178,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_UnnamedAction_Success() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -198,7 +200,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_NamedAction_Success() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -220,7 +222,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_UnnamedAction_VerbMismatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -238,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_NamedAction_VerbMismatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -256,7 +258,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_UnnamedAction_Success() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -278,7 +280,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_NamedAction_Success() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -300,7 +302,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_UnnamedAction_VerbMismatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -318,7 +320,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_NamedAction_VerbMismatch() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -367,7 +369,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_OverloadedAction_WithUnnamedAction(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -394,7 +396,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_OverloadedAction_NonIdRouteParameter(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -418,7 +420,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_OverloadedAction_Parameter_Casing(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -445,7 +447,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RouteWithActionName(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -472,7 +474,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RouteWithActionName_Casing(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -497,7 +499,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RouteWithoutActionName(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -525,7 +527,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_ModelBindingParameterAttribute_AreAppliedWhenSelectingActions(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -549,7 +551,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_ActionsThatHaveSubsetOfRouteParameters_AreConsideredForSelection(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -571,7 +573,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RequestToAmbiguousAction_OnDefaultRoute() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod("POST"), "http://localhost/api/Admin/Test?name=mario"); @@ -592,7 +594,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_SelectAction_ReturnsActionDescriptor_ForEnumParameterOverloads(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs index 82c684dd70..65f685293e 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs @@ -11,6 +11,7 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using System.Web.Http; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -20,12 +21,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; + private readonly Action _configureServices = new WebApiCompatShimWebSite.Startup().ConfigureServices; [Fact] public async Task ApiController_Activates_HttpContextAndUser() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -43,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Activates_UrlHelper() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -63,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Options_SetsDefaultFormatters() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = new string[] @@ -90,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_WithStatusCode() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -107,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_WithResponse() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -125,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_EnsureGlobalHttpresponseExceptionActionFilter_IsInvoked() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -143,7 +145,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_EnsureGlobalFilterConvention_IsApplied() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -162,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CanValidateCustomObjectWithPrefix_Fails() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -179,7 +181,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CanValidateCustomObject_IsSuccessFul() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -193,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CanValidateCustomObject_Fails() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -209,7 +211,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RequestProperty() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @@ -231,7 +233,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RequestParameter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @@ -253,7 +255,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ResponseReturned() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @@ -279,7 +281,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ExplicitChunkedEncoding_IsIgnored() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expected = @@ -324,7 +326,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_Conneg(string accept, string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -349,7 +351,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_HardcodedMediaType(string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -374,7 +376,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_Conneg_Error(string accept, string mediaType) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -397,7 +399,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_HardcodedFormatter() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -423,7 +425,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebApiRouting_AccessMvcController(string url, HttpStatusCode expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); @@ -441,7 +443,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebApiRouting_AccessWebApiController(string url, HttpStatusCode expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); @@ -457,7 +459,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_ByteArrayContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedBody = "Hello from ByteArrayContent!!"; @@ -477,7 +479,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_StreamContent() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedBody = "This content is from a file"; @@ -501,7 +503,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_PushStreamContent(string action, string expectedBody) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); // Act @@ -520,7 +522,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_PushStreamContentWithCustomHeaders() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var expectedBody = "Hello from PushStreamContent with custom headers!!"; var multipleValues = new[] { "value1", "value2" }; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs index 065ff8900b..dffa5b494e 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs @@ -8,6 +8,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Xunit; @@ -17,6 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; + private readonly Action _configureServices = new WebApiCompatShimWebSite.Startup().ConfigureServices; [Theory] [InlineData("http://localhost/api/Blog/Employees/PostByIdDefault/5")] @@ -24,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_Default_ReadsFromUrl(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); @@ -42,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_Default_DoesNotReadFormData() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PostByIdDefault"; @@ -67,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_ModelBinder_ReadsFromUrl(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); @@ -85,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_ModelBinder_ReadsFromFormData() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PostByIdModelBinder"; @@ -110,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_FromQuery_ReadsFromQueryNotRouteData(string url, string expected) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); @@ -128,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_FromQuery_DoesNotReadFormData() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PostByIdFromQuery"; @@ -151,7 +153,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ComplexParameter_Default_ReadsFromBody() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PutEmployeeDefault"; @@ -176,7 +178,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ComplexParameter_ModelBinder_ReadsFormAndUrl() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PutEmployeeModelBinder/5"; @@ -200,7 +202,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_TwoParameters_DefaultSources() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PutEmployeeBothDefault?name=Name_Override"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs index 208df85dd3..7cea8c970a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs @@ -8,6 +8,7 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; + private readonly Action _configureServices = new XmlFormattersWebSite.Startup().ConfigureServices; [Theory] [InlineData("http://localhost/IEnumerable/ValueTypes")] @@ -23,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_ValueTypes(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -69,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_Empty(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -91,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_NullInstance(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -113,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -137,7 +139,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_Empty(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -159,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_NullInstance(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -179,7 +181,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_IEnumerableOf_SerializableErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/IEnumerable/SerializableErrors"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs index e05b3e48bd..31a8e8ca92 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs @@ -12,6 +12,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using XmlFormattersWebSite; using Xunit; @@ -21,6 +22,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new Startup().Configure; + private readonly Action _configureServices = new Startup().ConfigureServices; private readonly string errorMessageFormat = string.Format( "{{1}}:{0} does not recognize '{1}', so instead use '{2}' with '{3}' set to '{4}' for value " + "type property '{{0}}' on type '{{1}}'.", @@ -34,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowsOnInvalidInput_AndAddsToModelState() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "Not a valid xml document"; var content = new StringContent(input, Encoding.UTF8, "application/xml-dcs"); @@ -58,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequiredDataIsProvided_AndModelIsBound_AndHasRequiredAttributeValidationErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml-dcs")); var input = " _app = new FormatterWebSite.Startup().Configure; + private readonly Action _configureServices = new FormatterWebSite.Startup().ConfigureServices; [Fact] public async Task XmlDataContractSerializerOutputFormatterIsCalled() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Home/GetDummyClass?sampleInput=10"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8")); @@ -40,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerOutputFormatterIsCalled() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/XmlSerializer/GetDummyClass?sampleInput=10"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8")); @@ -59,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerFailsAndDataContractSerializerIsCalled() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/DataContractSerializer/GetPerson?name=HelloWorld"); @@ -80,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerOutputFormatter_WhenDerivedClassIsReturned() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/XmlSerializer/GetDerivedDummyClass?sampleInput=10"); @@ -101,7 +103,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlDataContractSerializerOutputFormatter_WhenDerivedClassIsReturned() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/Home/GetDerivedDummyClass?sampleInput=10"); @@ -122,7 +124,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerFormatter_DoesNotWriteDictionaryObjects() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/XmlSerializer/GetDictionary"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs index 42c3720747..c034990722 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs @@ -8,6 +8,7 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; + private readonly Action _configureServices = new XmlFormattersWebSite.Startup().ConfigureServices; [Theory] [InlineData("http://localhost/IEnumerable/ValueTypes")] @@ -23,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_ValueTypes(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -69,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_NullInstance(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -91,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_Empty(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -113,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -137,7 +139,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_Empty(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -160,7 +162,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_NullInstance(string url) { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -181,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_IEnumerableOf_SerializableErrors() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/IEnumerable/SerializableErrors"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs index 3e5c827879..3fba04c972 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,12 +16,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; + private readonly Action _configureServices = new XmlFormattersWebSite.Startup().ConfigureServices; [Fact] public async Task CheckIfXmlSerializerInputFormatterIsCalled() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var sampleInputInt = 10; var input = "" + @@ -40,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowsOnInvalidInput_AndAddsToModelState() { // Arrange - var server = TestHelper.CreateServer(_app, SiteName); + var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var input = "Not a valid xml document"; var content = new StringContent(input, Encoding.UTF8, "application/xml-xmlser"); diff --git a/test/WebSites/ActionConstraintsWebSite/Startup.cs b/test/WebSites/ActionConstraintsWebSite/Startup.cs index db03f36eb0..9dc086c41a 100644 --- a/test/WebSites/ActionConstraintsWebSite/Startup.cs +++ b/test/WebSites/ActionConstraintsWebSite/Startup.cs @@ -9,19 +9,20 @@ namespace ActionConstraintsWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.ConfigureMvc(options => + { + options.AddXmlDataContractSerializerFormatter(); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.Configure(options => - { - options.AddXmlDataContractSerializerFormatter(); - }); - }); - app.UseErrorReporter(); app.UseMvc(routes => diff --git a/test/WebSites/ActionResultsWebSite/Startup.cs b/test/WebSites/ActionResultsWebSite/Startup.cs index e8cef5ca62..1831c91441 100644 --- a/test/WebSites/ActionResultsWebSite/Startup.cs +++ b/test/WebSites/ActionResultsWebSite/Startup.cs @@ -9,21 +9,22 @@ namespace ActionResultsWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.AddInstance(new GuidLookupService()); + + services.ConfigureMvc(options => + { + options.AddXmlDataContractSerializerFormatter(); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.AddInstance(new GuidLookupService()); - - services.Configure(options => - { - options.AddXmlDataContractSerializerFormatter(); - }); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/ActivatorWebSite/Startup.cs b/test/WebSites/ActivatorWebSite/Startup.cs index 08d4ca4346..aea7e32804 100644 --- a/test/WebSites/ActivatorWebSite/Startup.cs +++ b/test/WebSites/ActivatorWebSite/Startup.cs @@ -8,19 +8,19 @@ namespace ActivatorWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + services.AddInstance(new MyService()); + services.AddScoped(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - services.AddInstance(new MyService()); - services.AddScoped(); - }); - // Used to report exceptions that MVC doesn't handle app.UseErrorReporter(); diff --git a/test/WebSites/AntiForgeryWebSite/Startup.cs b/test/WebSites/AntiForgeryWebSite/Startup.cs index 0f4d13df80..a50256c979 100644 --- a/test/WebSites/AntiForgeryWebSite/Startup.cs +++ b/test/WebSites/AntiForgeryWebSite/Startup.cs @@ -8,13 +8,15 @@ namespace AntiForgeryWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); app.UseErrorReporter(); diff --git a/test/WebSites/ApiExplorerWebSite/Startup.cs b/test/WebSites/ApiExplorerWebSite/Startup.cs index b80e5e8b51..a35eb07fe9 100644 --- a/test/WebSites/ApiExplorerWebSite/Startup.cs +++ b/test/WebSites/ApiExplorerWebSite/Startup.cs @@ -10,29 +10,31 @@ namespace ApiExplorerWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.AddSingleton(); + + services.ConfigureMvc(options => + { + options.Filters.AddService(typeof(ApiExplorerDataFilter)); + + options.Conventions.Add(new ApiExplorerVisibilityEnabledConvention()); + options.Conventions.Add(new ApiExplorerVisibilityDisabledConvention( + typeof(ApiExplorerVisbilityDisabledByConventionController))); + + options.OutputFormatters.Clear(); + options.OutputFormatters.Add(new JsonOutputFormatter()); + options.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()); + }); + } + + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.AddSingleton(); - - services.Configure(options => - { - options.Filters.AddService(typeof(ApiExplorerDataFilter)); - - options.Conventions.Add(new ApiExplorerVisibilityEnabledConvention()); - options.Conventions.Add(new ApiExplorerVisibilityDisabledConvention( - typeof(ApiExplorerVisbilityDisabledByConventionController))); - - options.OutputFormatters.Clear(); - options.OutputFormatters.Add(new JsonOutputFormatter()); - options.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()); - }); - }); - app.UseMvc(routes => { routes.MapRoute("default", "{controller}/{action}"); diff --git a/test/WebSites/ApplicationModelWebSite/Startup.cs b/test/WebSites/ApplicationModelWebSite/Startup.cs index 4d88c3ce4a..28bf7b5789 100644 --- a/test/WebSites/ApplicationModelWebSite/Startup.cs +++ b/test/WebSites/ApplicationModelWebSite/Startup.cs @@ -9,22 +9,23 @@ namespace ApplicationModelWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.ConfigureMvc(options => + { + options.Conventions.Add(new ApplicationDescription("Common Application Description")); + options.Conventions.Add(new ControllerLicenseConvention()); + options.Conventions.Add(new FromHeaderConvention()); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - - services.Configure(options => - { - options.Conventions.Add(new ApplicationDescription("Common Application Description")); - options.Conventions.Add(new ControllerLicenseConvention()); - options.Conventions.Add(new FromHeaderConvention()); - }); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/AutofacWebSite/Startup.cs b/test/WebSites/AutofacWebSite/Startup.cs index 81806030bd..aef045f7d5 100644 --- a/test/WebSites/AutofacWebSite/Startup.cs +++ b/test/WebSites/AutofacWebSite/Startup.cs @@ -11,24 +11,25 @@ namespace AutofacWebSite { public class Startup { + // Set up application services + public IServiceProvider ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.AddTransient(); + + var builder = new ContainerBuilder(); + AutofacRegistration.Populate(builder, + services); + + var container = builder.Build(); + + return container.Resolve(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.AddTransient(); - - var builder = new ContainerBuilder(); - AutofacRegistration.Populate(builder, - services); - - var container = builder.Build(); - - return container.Resolve(); - }); - app.UseMvc(routes => { // This default route is for running the project directly. diff --git a/test/WebSites/BasicWebSite/Startup.cs b/test/WebSites/BasicWebSite/Startup.cs index bd57528e46..b2829640d2 100644 --- a/test/WebSites/BasicWebSite/Startup.cs +++ b/test/WebSites/BasicWebSite/Startup.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Core; using Microsoft.Framework.DependencyInjection; @@ -10,24 +9,25 @@ namespace BasicWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + + services.AddSingleton(); + + services.ConfigureMvc(options => + { + options.Conventions.Add(new ApplicationDescription("This is a basic website.")); + }); + + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - - services.AddSingleton(); - - services.ConfigureMvc(options => - { - options.Conventions.Add(new ApplicationDescription("This is a basic website.")); - }); - }); - // Add MVC to the request pipeline app.UseMvc(routes => { diff --git a/test/WebSites/BestEffortLinkGenerationWebSite/Startup.cs b/test/WebSites/BestEffortLinkGenerationWebSite/Startup.cs index abe366b254..0e91fbafa2 100644 --- a/test/WebSites/BestEffortLinkGenerationWebSite/Startup.cs +++ b/test/WebSites/BestEffortLinkGenerationWebSite/Startup.cs @@ -9,19 +9,21 @@ namespace BestEffortLinkGenerationWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.Configure((options) => + { + options.UseBestEffortLinkGeneration = true; + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.Configure((options) => - { - options.UseBestEffortLinkGeneration = true; - }); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/CompositeViewEngineWebSite/Startup.cs b/test/WebSites/CompositeViewEngineWebSite/Startup.cs index fcb5d27403..b22550865d 100644 --- a/test/WebSites/CompositeViewEngineWebSite/Startup.cs +++ b/test/WebSites/CompositeViewEngineWebSite/Startup.cs @@ -9,21 +9,21 @@ namespace CompositeViewEngineWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add a view engine as the first one in the list. + services.AddMvc() + .ConfigureMvc(options => + { + options.ViewEngines.Insert(0, typeof(TestViewEngine)); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add a view engine as the first one in the list. - services.AddMvc() - .Configure(options => - { - options.ViewEngines.Insert(0, typeof(TestViewEngine)); - }); - }); - // Add MVC to the request pipeline app.UseMvc(routes => { diff --git a/test/WebSites/ContentNegotiationWebSite/Startup.cs b/test/WebSites/ContentNegotiationWebSite/Startup.cs index 4f87fe0e56..2eb29bd44a 100644 --- a/test/WebSites/ContentNegotiationWebSite/Startup.cs +++ b/test/WebSites/ContentNegotiationWebSite/Startup.cs @@ -9,22 +9,21 @@ namespace ContentNegotiationWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.ConfigureMvc(options => + { + options.AddXmlDataContractSerializerFormatter(); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - - services.Configure(options => - { - options.AddXmlDataContractSerializerFormatter(); - }); - }); - app.UseErrorReporter(); // Add MVC to the request pipeline diff --git a/test/WebSites/ControllerDiscoveryConventionsWebSite/Startup.cs b/test/WebSites/ControllerDiscoveryConventionsWebSite/Startup.cs index ae6f07cf54..8088071840 100644 --- a/test/WebSites/ControllerDiscoveryConventionsWebSite/Startup.cs +++ b/test/WebSites/ControllerDiscoveryConventionsWebSite/Startup.cs @@ -8,15 +8,16 @@ namespace ControllerDiscoveryConventionsWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseMvc(routes => { routes.MapRoute("default", "{controller}/{action}/{id?}"); diff --git a/test/WebSites/ControllersFromServicesWebSite/Startup.cs b/test/WebSites/ControllersFromServicesWebSite/Startup.cs index 47ab0b85d5..e401bbb095 100644 --- a/test/WebSites/ControllersFromServicesWebSite/Startup.cs +++ b/test/WebSites/ControllersFromServicesWebSite/Startup.cs @@ -16,35 +16,38 @@ namespace ControllersFromServicesWebSite { public class Startup { + // Set up application services + public IServiceProvider ConfigureServices(IServiceCollection services) + { + services.AddMvc() + .WithControllersAsServices( + new[] + { + typeof(TimeScheduleController).GetTypeInfo().Assembly + }); + + services.AddTransient(); + +#if DNX451 + // Create the autofac container + var builder = new ContainerBuilder(); + + // Create the container and use the default application services as a fallback + AutofacRegistration.Populate( + builder, + services); + + return builder.Build() + .Resolve(); +#else + return services.BuildServiceProvider(); +#endif + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc() - .WithControllersAsServices( - new[] - { - typeof(TimeScheduleController).GetTypeInfo().Assembly - }); - - services.AddTransient(); - -#if DNX451 - // Create the autofac container - var builder = new ContainerBuilder(); - - // Create the container and use the default application services as a fallback - AutofacRegistration.Populate( - builder, - services); - - return builder.Build() - .Resolve(); -#endif - }); - app.UseMvc(routes => { routes.MapRoute("default", "{controller}/{action}/{id}"); diff --git a/test/WebSites/CorsMiddlewareWebSite/Startup.cs b/test/WebSites/CorsMiddlewareWebSite/Startup.cs index 22ce862ec1..992b42ff67 100644 --- a/test/WebSites/CorsMiddlewareWebSite/Startup.cs +++ b/test/WebSites/CorsMiddlewareWebSite/Startup.cs @@ -2,23 +2,21 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Cors; -using Microsoft.AspNet.Mvc; using Microsoft.Framework.DependencyInjection; namespace CorsMiddlewareWebSite { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseCors(policy => policy.WithOrigins("http://example.com")); app.UseMvc(); } diff --git a/test/WebSites/CorsWebSite/Startup.cs b/test/WebSites/CorsWebSite/Startup.cs index f270455f6d..d1fe200f5b 100644 --- a/test/WebSites/CorsWebSite/Startup.cs +++ b/test/WebSites/CorsWebSite/Startup.cs @@ -2,58 +2,57 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Mvc; using Microsoft.Framework.DependencyInjection; namespace CorsWebSite { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.ConfigureCors(options => + { + options.AddPolicy( + "AllowAnySimpleRequest", + builder => + { + builder.AllowAnyOrigin() + .WithMethods("GET", "POST", "HEAD"); + }); + + options.AddPolicy( + "AllowSpecificOrigin", + builder => + { + builder.WithOrigins("http://example.com"); + }); + + options.AddPolicy( + "WithCredentials", + builder => + { + builder.AllowCredentials() + .WithOrigins("http://example.com"); + }); + + options.AddPolicy( + "WithCredentialsAnyOrigin", + builder => + { + builder.AllowCredentials() + .AllowAnyOrigin() + .AllowAnyHeader() + .WithMethods("PUT", "POST") + .WithExposedHeaders("exposed1", "exposed2"); + }); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.ConfigureCors(options => - { - options.AddPolicy( - "AllowAnySimpleRequest", - builder => - { - builder.AllowAnyOrigin() - .WithMethods("GET", "POST", "HEAD"); - }); - - options.AddPolicy( - "AllowSpecificOrigin", - builder => - { - builder.WithOrigins("http://example.com"); - }); - - options.AddPolicy( - "WithCredentials", - builder => - { - builder.AllowCredentials() - .WithOrigins("http://example.com"); - }); - - options.AddPolicy( - "WithCredentialsAnyOrigin", - builder => - { - builder.AllowCredentials() - .AllowAnyOrigin() - .AllowAnyHeader() - .WithMethods("PUT", "POST") - .WithExposedHeaders("exposed1", "exposed2"); - }); - }); - }); - app.UseMvc(); } } diff --git a/test/WebSites/CustomRouteWebSite/Startup.cs b/test/WebSites/CustomRouteWebSite/Startup.cs index 89482a70ca..745cd52d69 100644 --- a/test/WebSites/CustomRouteWebSite/Startup.cs +++ b/test/WebSites/CustomRouteWebSite/Startup.cs @@ -8,15 +8,16 @@ namespace CustomRouteWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseMvc(routes => { routes.DefaultHandler = new LocalizedRoute(routes.DefaultHandler); diff --git a/test/WebSites/ErrorPageMiddlewareWebSite/Startup.cs b/test/WebSites/ErrorPageMiddlewareWebSite/Startup.cs index a4a66ed94f..4ae731bd57 100644 --- a/test/WebSites/ErrorPageMiddlewareWebSite/Startup.cs +++ b/test/WebSites/ErrorPageMiddlewareWebSite/Startup.cs @@ -8,15 +8,16 @@ namespace ErrorPageMiddlewareWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseErrorPage(); app.UseMvc(); } diff --git a/test/WebSites/FilesWebSite/Startup.cs b/test/WebSites/FilesWebSite/Startup.cs index 3edd621c13..e2ad22d5c4 100644 --- a/test/WebSites/FilesWebSite/Startup.cs +++ b/test/WebSites/FilesWebSite/Startup.cs @@ -8,15 +8,16 @@ namespace FilesWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseMiddleware(); app.UseMvc(routes => diff --git a/test/WebSites/FiltersWebSite/AuthorizeBasicMiddleware.cs b/test/WebSites/FiltersWebSite/AuthorizeBasicMiddleware.cs index 4b4721abf7..91e95080ef 100644 --- a/test/WebSites/FiltersWebSite/AuthorizeBasicMiddleware.cs +++ b/test/WebSites/FiltersWebSite/AuthorizeBasicMiddleware.cs @@ -1,13 +1,8 @@ // Copyright (c) Microsoft Open Technologies, Inc. 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.Security.Claims; -using System.Threading.Tasks; using Microsoft.AspNet.Authentication; -using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http.Authentication; using Microsoft.Framework.OptionsModel; namespace FiltersWebSite @@ -16,10 +11,9 @@ namespace FiltersWebSite { public AuthorizeBasicMiddleware( RequestDelegate next, - IServiceProvider services, IOptions options, string authScheme) : - base(next, services, options, + base(next, options, new ConfigureOptions(o => o.AuthenticationScheme = authScheme) { Name = authScheme }) { } diff --git a/test/WebSites/FiltersWebSite/Startup.cs b/test/WebSites/FiltersWebSite/Startup.cs index e8cccf79ff..1d676396f6 100644 --- a/test/WebSites/FiltersWebSite/Startup.cs +++ b/test/WebSites/FiltersWebSite/Startup.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Security.Claims; -using System.Threading.Tasks; using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc; @@ -12,50 +11,51 @@ namespace FiltersWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.ConfigureAuthorization(options => + { + // This policy cannot succeed since it has no requirements + options.AddPolicy("Impossible", policy => { }); + options.AddPolicy("Api", policy => + { + policy.ActiveAuthenticationSchemes.Add("Api"); + policy.RequireClaim(ClaimTypes.NameIdentifier); + }); + options.AddPolicy("Api-Manager", policy => + { + policy.ActiveAuthenticationSchemes.Add("Api"); + policy.Requirements.Add(Operations.Edit); + }); + options.AddPolicy("Interactive", policy => + { + policy.ActiveAuthenticationSchemes.Add("Interactive"); + policy.RequireClaim(ClaimTypes.NameIdentifier) + .RequireClaim("Permission", "CanViewPage"); + }); + }); + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + services.Configure(o => o.AuthenticationScheme = "Api", "Api"); + services.Configure(o => o.AuthenticationScheme = "Interactive", "Interactive"); + + services.Configure(options => + { + options.Filters.Add(new GlobalExceptionFilter()); + options.Filters.Add(new GlobalActionFilter()); + options.Filters.Add(new GlobalResultFilter()); + options.Filters.Add(new GlobalAuthorizationFilter()); + options.Filters.Add(new TracingResourceFilter("Global Resource Filter")); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.ConfigureAuthorization(options => - { - // This policy cannot succeed since it has no requirements - options.AddPolicy("Impossible", policy => { }); - options.AddPolicy("Api", policy => - { - policy.ActiveAuthenticationSchemes.Add("Api"); - policy.RequireClaim(ClaimTypes.NameIdentifier); - }); - options.AddPolicy("Api-Manager", policy => - { - policy.ActiveAuthenticationSchemes.Add("Api"); - policy.Requirements.Add(Operations.Edit); - }); - options.AddPolicy("Interactive", policy => - { - policy.ActiveAuthenticationSchemes.Add("Interactive"); - policy.RequireClaim(ClaimTypes.NameIdentifier) - .RequireClaim("Permission", "CanViewPage"); - }); - }); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient(); - services.Configure(o => o.AuthenticationScheme = "Api", "Api"); - services.Configure(o => o.AuthenticationScheme = "Interactive", "Interactive"); - - services.Configure(options => - { - options.Filters.Add(new GlobalExceptionFilter()); - options.Filters.Add(new GlobalActionFilter()); - options.Filters.Add(new GlobalResultFilter()); - options.Filters.Add(new GlobalAuthorizationFilter()); - options.Filters.Add(new TracingResourceFilter("Global Resource Filter")); - }); - }); - app.UseErrorReporter(); app.UseMiddleware("Interactive"); diff --git a/test/WebSites/FormatFilterWebSite/Startup.cs b/test/WebSites/FormatFilterWebSite/Startup.cs index 363a75b566..304364b4fc 100644 --- a/test/WebSites/FormatFilterWebSite/Startup.cs +++ b/test/WebSites/FormatFilterWebSite/Startup.cs @@ -11,27 +11,29 @@ namespace FormatFilterWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + services.Configure(options => + { + var formatFilter = new FormatFilterAttribute(); + options.Filters.Add(formatFilter); + + var customFormatter = new CustomFormatter("application/custom"); + options.OutputFormatters.Add(customFormatter); + + options.FormatterMappings.SetMediaTypeMappingForFormat( + "custom", + MediaTypeHeaderValue.Parse("application/custom")); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.Configure(options => - { - var formatFilter = new FormatFilterAttribute(); - options.Filters.Add(formatFilter); - - var customFormatter = new CustomFormatter("application/custom"); - options.OutputFormatters.Add(customFormatter); - - options.FormatterMappings.SetMediaTypeMappingForFormat( - "custom", - MediaTypeHeaderValue.Parse("application/custom")); - }); - }); - app.UseMvc(routes => { routes.MapRoute("formatroute", diff --git a/test/WebSites/FormatterWebSite/Startup.cs b/test/WebSites/FormatterWebSite/Startup.cs index ff4f63e302..08c715a3c2 100644 --- a/test/WebSites/FormatterWebSite/Startup.cs +++ b/test/WebSites/FormatterWebSite/Startup.cs @@ -9,26 +9,27 @@ namespace FormatterWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + + services.Configure(options => + { + options.ValidationExcludeFilters.Add(typeof(Developer)); + options.ValidationExcludeFilters.Add(typeof(Supplier)); + + options.AddXmlDataContractSerializerFormatter(); + options.InputFormatters.Add(new StringInputFormatter()); + }); + } + + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - - services.Configure(options => - { - options.ValidationExcludeFilters.Add(typeof(Developer)); - options.ValidationExcludeFilters.Add(typeof(Supplier)); - - options.AddXmlDataContractSerializerFormatter(); - options.InputFormatters.Add(new StringInputFormatter()); - }); - }); - // Add MVC to the request pipeline app.UseMvc(routes => { diff --git a/test/WebSites/InlineConstraintsWebSite/Startup.cs b/test/WebSites/InlineConstraintsWebSite/Startup.cs index a7516ce93c..b900df5080 100644 --- a/test/WebSites/InlineConstraintsWebSite/Startup.cs +++ b/test/WebSites/InlineConstraintsWebSite/Startup.cs @@ -9,15 +9,17 @@ namespace InlineConstraints { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseErrorReporter(); app.UseMvc(routes => diff --git a/test/WebSites/LoggingWebSite/Startup.cs b/test/WebSites/LoggingWebSite/Startup.cs index 2a955021ea..a6ad5bc08f 100644 --- a/test/WebSites/LoggingWebSite/Startup.cs +++ b/test/WebSites/LoggingWebSite/Startup.cs @@ -8,21 +8,22 @@ namespace LoggingWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddElm(options => + { + // We want to log for all log levels and loggers + options.Filter = (loggerName, logLevel) => true; + }); + + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddElm(options => - { - // We want to log for all log levels and loggers - options.Filter = (loggerName, logLevel) => true; - }); - - services.AddMvc(); - }); - app.Map("/logs", (appBuilder) => { appBuilder.UseMiddleware(); diff --git a/test/WebSites/LowercaseUrlsWebSite/Startup.cs b/test/WebSites/LowercaseUrlsWebSite/Startup.cs index 59577720a9..0dd95a6385 100644 --- a/test/WebSites/LowercaseUrlsWebSite/Startup.cs +++ b/test/WebSites/LowercaseUrlsWebSite/Startup.cs @@ -8,21 +8,19 @@ namespace LowercaseUrlsWebSite { public class Startup { + // Set up application services public void ConfigureServices(IServiceCollection services) { + // Add MVC services to the services container + services.AddMvc(); + + services.Configure(routeOptions => routeOptions.LowercaseUrls = true); } public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - - services.Configure(routeOptions => routeOptions.LowercaseUrls = true); - }); - app.UseMvc(routes => { routes.MapRoute("Default", "{controller}/{action}/{id?}", diff --git a/test/WebSites/ModelBindingWebSite/Startup.cs b/test/WebSites/ModelBindingWebSite/Startup.cs index 40131f94bb..bac64f8e5a 100644 --- a/test/WebSites/ModelBindingWebSite/Startup.cs +++ b/test/WebSites/ModelBindingWebSite/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.Framework.DependencyInjection; using ModelBindingWebSite.Models; using ModelBindingWebSite.Services; @@ -12,33 +11,33 @@ namespace ModelBindingWebSite { public class Startup { - public void Configure(IApplicationBuilder app) + // Set up application services + public void ConfigureServices(IServiceCollection services) { - var configuration = app.GetTestConfiguration(); + // Add MVC services to the services container + services.AddMvc() + .Configure(m => + { + m.MaxModelValidationErrors = 8; + m.ModelBinders.Insert(0, typeof(TestBindingSourceModelBinder)); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc() - .Configure(m => - { - m.MaxModelValidationErrors = 8; - m.ModelBinders.Insert(0, typeof(TestBindingSourceModelBinder)); - - m.AddXmlDataContractSerializerFormatter(); - m.ValidationExcludeFilters.Add(typeof(Address)); + m.AddXmlDataContractSerializerFormatter(); + m.ValidationExcludeFilters.Add(typeof(Address)); // ModelMetadataController relies on additional values AdditionalValuesMetadataProvider provides. m.ModelMetadataDetailsProviders.Add(new AdditionalValuesMetadataProvider()); - }); + }); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - }); + services.AddTransient(); + services.AddTransient(); + } + + public void Configure(IApplicationBuilder app) + { + var configuration = app.GetTestConfiguration(); app.UseErrorReporter(); diff --git a/test/WebSites/MvcTagHelpersWebSite/Startup.cs b/test/WebSites/MvcTagHelpersWebSite/Startup.cs index 0bbbc9ad7f..e1eadfcf63 100644 --- a/test/WebSites/MvcTagHelpersWebSite/Startup.cs +++ b/test/WebSites/MvcTagHelpersWebSite/Startup.cs @@ -8,16 +8,18 @@ namespace MvcTagHelpersWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + services.AddSingleton(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.AddSingleton(); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/PrecompilationWebSite/Startup.cs b/test/WebSites/PrecompilationWebSite/Startup.cs index 21ab942241..7a2df2e9d6 100644 --- a/test/WebSites/PrecompilationWebSite/Startup.cs +++ b/test/WebSites/PrecompilationWebSite/Startup.cs @@ -8,15 +8,17 @@ namespace PrecompilationWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/RazorCompilerCacheWebSite/Startup.cs b/test/WebSites/RazorCompilerCacheWebSite/Startup.cs index 9975f6f5a5..a420f451d9 100644 --- a/test/WebSites/RazorCompilerCacheWebSite/Startup.cs +++ b/test/WebSites/RazorCompilerCacheWebSite/Startup.cs @@ -9,17 +9,19 @@ namespace RazorCompilerCacheWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + services.AddSingleton(); + services.AddSingleton(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.AddSingleton(); - services.AddSingleton(); - }); - app.UseMvc(); } } diff --git a/test/WebSites/RazorEmbeddedViewsWebSite/Startup.cs b/test/WebSites/RazorEmbeddedViewsWebSite/Startup.cs index 08a852ec38..e5d415ebd3 100644 --- a/test/WebSites/RazorEmbeddedViewsWebSite/Startup.cs +++ b/test/WebSites/RazorEmbeddedViewsWebSite/Startup.cs @@ -11,20 +11,22 @@ namespace RazorEmbeddedViewsWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + + services.Configure(options => + { + options.FileProvider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "EmbeddedResources"); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - - services.Configure(options => - { - options.FileProvider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "EmbeddedResources"); - }); - }); - app.UseMvc(routes => { routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}"); diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs b/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs index 02de9f134a..e11771e1a8 100644 --- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs +++ b/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs @@ -12,17 +12,17 @@ namespace RazorPageExecutionInstrumentationWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - }); - app.Use(async (HttpContext context, Func next) => { if (!string.IsNullOrEmpty(context.Request.Headers["ENABLE-RAZOR-INSTRUMENTATION"])) diff --git a/test/WebSites/RazorWebSite/Startup.cs b/test/WebSites/RazorWebSite/Startup.cs index 1f14ca1f7a..116cb1561f 100644 --- a/test/WebSites/RazorWebSite/Startup.cs +++ b/test/WebSites/RazorWebSite/Startup.cs @@ -10,27 +10,27 @@ namespace RazorWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.Configure(options => + { + var expander = new LanguageViewLocationExpander( + context => context.HttpContext.Request.Query["language-expander-value"]); + options.ViewLocationExpanders.Add(expander); + options.ViewLocationExpanders.Add(new CustomPartialDirectoryViewLocationExpander()); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.Configure(options => - { - var expander = new LanguageViewLocationExpander( - context => context.HttpContext.Request.Query["language-expander-value"]); - options.ViewLocationExpanders.Add(expander); - options.ViewLocationExpanders.Add(new CustomPartialDirectoryViewLocationExpander()); - }); - }); - // Add MVC to the request pipeline app.UseMvc(routes => { diff --git a/test/WebSites/RequestServicesWebSite/Startup.cs b/test/WebSites/RequestServicesWebSite/Startup.cs index 7b07abd493..b24472887f 100644 --- a/test/WebSites/RequestServicesWebSite/Startup.cs +++ b/test/WebSites/RequestServicesWebSite/Startup.cs @@ -8,17 +8,18 @@ namespace RequestServicesWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.AddScoped(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - - services.AddScoped(); - }); - // Initializes the RequestId service for each request app.UseMiddleware(); diff --git a/test/WebSites/ResponseCacheWebSite/Startup.cs b/test/WebSites/ResponseCacheWebSite/Startup.cs index 5139dc76d0..8fa670b774 100644 --- a/test/WebSites/ResponseCacheWebSite/Startup.cs +++ b/test/WebSites/ResponseCacheWebSite/Startup.cs @@ -9,38 +9,39 @@ namespace ResponseCacheWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + services.Configure(options => + { + options.CacheProfiles.Add( + "PublicCache30Sec", new CacheProfile + { + Duration = 30, + Location = ResponseCacheLocation.Any + }); + + options.CacheProfiles.Add( + "PrivateCache30Sec", new CacheProfile + { + Duration = 30, + Location = ResponseCacheLocation.Client + }); + + options.CacheProfiles.Add( + "NoCache", new CacheProfile + { + NoStore = true, + Duration = 0, + Location = ResponseCacheLocation.None + }); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.Configure(options => - { - options.CacheProfiles.Add( - "PublicCache30Sec", new CacheProfile - { - Duration = 30, - Location = ResponseCacheLocation.Any - }); - - options.CacheProfiles.Add( - "PrivateCache30Sec", new CacheProfile - { - Duration = 30, - Location = ResponseCacheLocation.Client - }); - - options.CacheProfiles.Add( - "NoCache", new CacheProfile - { - NoStore = true, - Duration = 0, - Location = ResponseCacheLocation.None - }); - }); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/RoutingWebSite/Startup.cs b/test/WebSites/RoutingWebSite/Startup.cs index 13c258e67d..e0fe524b22 100644 --- a/test/WebSites/RoutingWebSite/Startup.cs +++ b/test/WebSites/RoutingWebSite/Startup.cs @@ -8,17 +8,18 @@ namespace RoutingWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.AddScoped(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - - services.AddScoped(); - }); - app.UseErrorReporter(); app.UseMvc(routes => diff --git a/test/WebSites/TagHelpersWebSite/Startup.cs b/test/WebSites/TagHelpersWebSite/Startup.cs index 19a23c05c9..363e456070 100644 --- a/test/WebSites/TagHelpersWebSite/Startup.cs +++ b/test/WebSites/TagHelpersWebSite/Startup.cs @@ -8,15 +8,16 @@ namespace TagHelpersWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/TempDataWebSite/Startup.cs b/test/WebSites/TempDataWebSite/Startup.cs index cac8e04114..ddbf91a8af 100644 --- a/test/WebSites/TempDataWebSite/Startup.cs +++ b/test/WebSites/TempDataWebSite/Startup.cs @@ -8,17 +8,18 @@ namespace TempDataWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.AddCaching(); + services.AddSession(); + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddCaching(); - services.AddSession(); - services.AddMvc(); - }); - app.UseInMemorySession(); app.UseMvc(routes => { diff --git a/test/WebSites/UrlHelperWebSite/Startup.cs b/test/WebSites/UrlHelperWebSite/Startup.cs index f3f64d8d2a..b170fbd982 100644 --- a/test/WebSites/UrlHelperWebSite/Startup.cs +++ b/test/WebSites/UrlHelperWebSite/Startup.cs @@ -9,25 +9,26 @@ namespace UrlHelperWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + services.Configure(optionsSetup => + { + optionsSetup.ServeCDNContent = true; + optionsSetup.CDNServerBaseUrl = "http://cdn.contoso.com"; + optionsSetup.GenerateLowercaseUrls = true; + }); + + // Add MVC services to the services container + services.AddMvc(); + + services.AddScoped(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - services.Configure(optionsSetup => - { - optionsSetup.ServeCDNContent = true; - optionsSetup.CDNServerBaseUrl = "http://cdn.contoso.com"; - optionsSetup.GenerateLowercaseUrls = true; - }); - - // Add MVC services to the services container - services.AddMvc(); - - services.AddScoped(); - }); // Add MVC to the request pipeline app.UseMvc(routes => diff --git a/test/WebSites/ValidationWebSite/Startup.cs b/test/WebSites/ValidationWebSite/Startup.cs index 8f01ecbbcd..cc2e4c09e7 100644 --- a/test/WebSites/ValidationWebSite/Startup.cs +++ b/test/WebSites/ValidationWebSite/Startup.cs @@ -8,6 +8,13 @@ namespace ValidationWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); @@ -15,13 +22,6 @@ namespace ValidationWebSite // Set up file serving for JavaScript files. app.UseFileServer(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - }); - app.UseErrorReporter(); // Add MVC to the request pipeline diff --git a/test/WebSites/ValueProvidersWebSite/Startup.cs b/test/WebSites/ValueProvidersWebSite/Startup.cs index f8ed8a4bb0..58a1cc54dd 100644 --- a/test/WebSites/ValueProvidersWebSite/Startup.cs +++ b/test/WebSites/ValueProvidersWebSite/Startup.cs @@ -9,21 +9,20 @@ namespace ValueProvidersWebSite { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc() + .Configure(options => + { + options.ValueProviderFactories.Insert(1, new CustomValueProviderFactory()); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc() - .Configure(options => - { - options.ValueProviderFactories.Insert(1, new CustomValueProviderFactory()); - }); - }); - // Add MVC to the request pipeline app.UseMvc(routes => { diff --git a/test/WebSites/VersioningWebSite/Startup.cs b/test/WebSites/VersioningWebSite/Startup.cs index 8c88dacdc6..ce62d20d8e 100644 --- a/test/WebSites/VersioningWebSite/Startup.cs +++ b/test/WebSites/VersioningWebSite/Startup.cs @@ -8,17 +8,18 @@ namespace VersioningWebSite { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + + services.AddScoped(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - - services.AddScoped(); - }); - app.UseMvc(routes => { routes.MapRoute( diff --git a/test/WebSites/ViewComponentWebSite/Startup.cs b/test/WebSites/ViewComponentWebSite/Startup.cs index 6ae7ec7944..03155cd33a 100644 --- a/test/WebSites/ViewComponentWebSite/Startup.cs +++ b/test/WebSites/ViewComponentWebSite/Startup.cs @@ -8,13 +8,15 @@ namespace ViewComponentWebSite { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - }); app.UseMvc(routes => { diff --git a/test/WebSites/WebApiCompatShimWebSite/Startup.cs b/test/WebSites/WebApiCompatShimWebSite/Startup.cs index 8b94f30a84..a24e1ec041 100644 --- a/test/WebSites/WebApiCompatShimWebSite/Startup.cs +++ b/test/WebSites/WebApiCompatShimWebSite/Startup.cs @@ -9,16 +9,17 @@ namespace WebApiCompatShimWebSite { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + services.AddWebApiConventions(); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - app.UseServices(services => - { - services.AddMvc(); - services.AddWebApiConventions(); - }); - app.UseErrorReporter(); app.UseMvc(routes => diff --git a/test/WebSites/XmlFormattersWebSite/Startup.cs b/test/WebSites/XmlFormattersWebSite/Startup.cs index 8f6a91db88..2c617752e1 100644 --- a/test/WebSites/XmlFormattersWebSite/Startup.cs +++ b/test/WebSites/XmlFormattersWebSite/Startup.cs @@ -12,63 +12,63 @@ namespace XmlFormattersWebSite { public class Startup { + // Set up application services + public void ConfigureServices(IServiceCollection services) + { + // Add MVC services to the services container + services.AddMvc(); + + services.Configure(options => + { + options.InputFormatters.Clear(); + options.OutputFormatters.Clear(); + + // Since both XmlSerializer and DataContractSerializer based formatters + // have supported media types of 'application/xml' and 'text/xml', it + // would be difficult for a test to choose a particular formatter based on + // request information (Ex: Accept header). + // So here we instead clear out the default supported media types and create new + // ones which are distinguishable between formatters. + var xmlSerializerInputFormatter = new XmlSerializerInputFormatter(); + xmlSerializerInputFormatter.SupportedMediaTypes.Clear(); + xmlSerializerInputFormatter.SupportedMediaTypes.Add( + new MediaTypeHeaderValue("application/xml-xmlser")); + xmlSerializerInputFormatter.SupportedMediaTypes.Add( + new MediaTypeHeaderValue("text/xml-xmlser")); + + var xmlSerializerOutputFormatter = new XmlSerializerOutputFormatter(); + xmlSerializerOutputFormatter.SupportedMediaTypes.Clear(); + xmlSerializerOutputFormatter.SupportedMediaTypes.Add( + new MediaTypeHeaderValue("application/xml-xmlser")); + xmlSerializerOutputFormatter.SupportedMediaTypes.Add( + new MediaTypeHeaderValue("text/xml-xmlser")); + + var dcsInputFormatter = new XmlDataContractSerializerInputFormatter(); + dcsInputFormatter.SupportedMediaTypes.Clear(); + dcsInputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml-dcs")); + dcsInputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml-dcs")); + + var dcsOutputFormatter = new XmlDataContractSerializerOutputFormatter(); + dcsOutputFormatter.SupportedMediaTypes.Clear(); + dcsOutputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml-dcs")); + dcsOutputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml-dcs")); + + options.InputFormatters.Add(dcsInputFormatter); + options.InputFormatters.Add(xmlSerializerInputFormatter); + options.OutputFormatters.Add(dcsOutputFormatter); + options.OutputFormatters.Add(xmlSerializerOutputFormatter); + + xmlSerializerInputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); + xmlSerializerOutputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); + dcsInputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); + dcsOutputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); + }); + } + public void Configure(IApplicationBuilder app) { var configuration = app.GetTestConfiguration(); - // Set up application services - app.UseServices(services => - { - // Add MVC services to the services container - services.AddMvc(); - - services.Configure(options => - { - options.InputFormatters.Clear(); - options.OutputFormatters.Clear(); - - // Since both XmlSerializer and DataContractSerializer based formatters - // have supported media types of 'application/xml' and 'text/xml', it - // would be difficult for a test to choose a particular formatter based on - // request information (Ex: Accept header). - // So here we instead clear out the default supported media types and create new - // ones which are distinguishable between formatters. - var xmlSerializerInputFormatter = new XmlSerializerInputFormatter(); - xmlSerializerInputFormatter.SupportedMediaTypes.Clear(); - xmlSerializerInputFormatter.SupportedMediaTypes.Add( - new MediaTypeHeaderValue("application/xml-xmlser")); - xmlSerializerInputFormatter.SupportedMediaTypes.Add( - new MediaTypeHeaderValue("text/xml-xmlser")); - - var xmlSerializerOutputFormatter = new XmlSerializerOutputFormatter(); - xmlSerializerOutputFormatter.SupportedMediaTypes.Clear(); - xmlSerializerOutputFormatter.SupportedMediaTypes.Add( - new MediaTypeHeaderValue("application/xml-xmlser")); - xmlSerializerOutputFormatter.SupportedMediaTypes.Add( - new MediaTypeHeaderValue("text/xml-xmlser")); - - var dcsInputFormatter = new XmlDataContractSerializerInputFormatter(); - dcsInputFormatter.SupportedMediaTypes.Clear(); - dcsInputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml-dcs")); - dcsInputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml-dcs")); - - var dcsOutputFormatter = new XmlDataContractSerializerOutputFormatter(); - dcsOutputFormatter.SupportedMediaTypes.Clear(); - dcsOutputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml-dcs")); - dcsOutputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml-dcs")); - - options.InputFormatters.Add(dcsInputFormatter); - options.InputFormatters.Add(xmlSerializerInputFormatter); - options.OutputFormatters.Add(dcsOutputFormatter); - options.OutputFormatters.Add(xmlSerializerOutputFormatter); - - xmlSerializerInputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); - xmlSerializerOutputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); - dcsInputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); - dcsOutputFormatter.WrapperProviderFactories.Add(new PersonWrapperProviderFactory()); - }); - }); - app.UseErrorReporter(); // Add MVC to the request pipeline