React to hosting changes

This commit is contained in:
Hao Kung 2015-03-19 11:07:25 -07:00
parent 015edefa96
commit 4b5dd199ca
127 changed files with 1611 additions and 1334 deletions

View File

@ -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<PassThroughAttribute>();
services.AddSingleton<UserNameService>();
services.AddTransient<ITestService, TestService>();
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<IApplicationEnvironment>();
var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>();
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<MonitoringMiddlware>();
app.UseServices(services =>
_autoFac = true;
services.ConfigureRazorViewEngine(options =>
{
services.AddCaching();
services.AddSession();
services.AddMvc();
services.AddSingleton<PassThroughAttribute>();
services.AddSingleton<UserNameService>();
services.AddTransient<ITestService, TestService>();
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<MonitoringModule>();
IContainer container = builder.Build();
return container.Resolve<IServiceProvider>();
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<MonitoringModule>();
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
else
#endif
{
app.UseServices(services =>
{
services.AddCaching();
services.AddSession();
services.AddMvc();
services.AddSingleton<PassThroughAttribute>();
services.AddSingleton<UserNameService>();
services.AddTransient<ITestService, TestService>();
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<MonitoringMiddlware>();
}
#endif
app.UseInMemorySession();
app.UseMvc(routes =>

View File

@ -11,15 +11,16 @@ namespace TagHelperSample.Web
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton<MoviesService>();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseServices(services =>
{
services.AddMvc();
services.AddSingleton<MoviesService>();
});
loggerFactory.AddConsole((name, logLevel) =>
name.StartsWith("Microsoft.AspNet.Mvc.TagHelpers", StringComparison.OrdinalIgnoreCase)
|| (name.StartsWith("Microsoft.Net.Http.Server.WebListener", StringComparison.OrdinalIgnoreCase)

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.Internal
{
throw new InvalidOperationException(Resources.FormatUnableToFindServices(
"IServiceCollection.AddMvc()",
"IApplicationBuilder.UseServices(...)",
"IApplicationBuilder.ConfigureServices(...)",
"IApplicationBuilder.UseMvc(...)"));
}
}

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc
= new ResourceManager("Microsoft.AspNet.Mvc.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary>
/// 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.
/// </summary>
internal static string UnableToFindServices
{
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc
}
/// <summary>
/// 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.
/// </summary>
internal static string FormatUnableToFindServices()
{

View File

@ -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<RazorViewEngineOptions> 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<IApplicationEnvironment>(precompilationApplicationEnvironment);
var serviceProvider = serviceCollection.BuildServiceProvider();
var viewCompiler = new RazorPreCompiler(serviceProvider, context, _memoryCache, compilationSettings)
var replacedServices = new ServiceCollection();
replacedServices.AddMvc();
replacedServices.AddInstance<IApplicationEnvironment>(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;

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc
services.Setup(o => o.GetService(typeof(IEnumerable<MvcMarkerService>)))
.Returns(new List<MvcMarkerService>());
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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
@ -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<KeyValuePair<string, string>>
{

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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 = @"<label for=""Hello"">Hello</label> 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 = "<body><h2>Activation Test</h2>" +
Environment.NewLine +

View File

@ -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<IApplicationBuilder> _app = new AntiForgeryWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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.

View File

@ -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<IApplicationBuilder> _app = new ApiExplorerWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new ApplicationModelWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new BestEffortLinkGenerationWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new BestEffortLinkGenerationWebSite.Startup().ConfigureServices;
private const string ExpectedOutput = @"<html>
<body>
@ -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";

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new CompositeViewEngineWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<Product xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using ContentNegotiationWebSite;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc.Xml;
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(ContentNegotiationWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -18,12 +18,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
private const string SiteName = nameof(ControllerDiscoveryConventionsWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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<IAssemblyProvider, FilteredDefaultAssemblyProvider>());
services =>
{
_configureServices(services);
services.AddTransient<IAssemblyProvider, FilteredDefaultAssemblyProvider>();
});
var client = server.CreateClient();
client.BaseAddress = new Uri("http://localhost/");

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Func<IServiceCollection, IServiceProvider> _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

View File

@ -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<IApplicationBuilder> _app = new CorsMiddlewareWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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.

View File

@ -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<IApplicationBuilder> _app = new CorsWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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.

View File

@ -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<IApplicationBuilder> _app = new CustomRouteWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new UrlHelperWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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;

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Func<IServiceCollection, IServiceProvider> _configureServices = new Startup().ConfigureServices;
[Theory]
[InlineData("http://localhost/di", "<p>Builder Output: Hello from builder.</p>")]
@ -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);

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new FilesWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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.";

View File

@ -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<IApplicationBuilder> _app = new FiltersWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -16,12 +16,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
private const string SiteName = nameof(RazorWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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.";

View File

@ -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<IApplicationBuilder> _app = new FormatFilterWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new FormatterWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
@ -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);

View File

@ -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<IApplicationBuilder> _app = new FormatterWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new FormatterWebSite.Startup().ConfigureServices;
// Parameters: Request Content, Expected status code, Expected model state error message
public static IEnumerable<object[]> 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<KeyValuePair<string, string>>();
kvps.Add(new KeyValuePair<string, string>("Alias", "xyz"));

View File

@ -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<IApplicationBuilder> _app = new FormatterWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +

View File

@ -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<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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";

View File

@ -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<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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();

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
[Fact]
public async Task AssemblyValues_LoggedAtStartup()
@ -87,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
private async Task<IEnumerable<LogInfoDto>> GetLogsByDataTypeAsync<T>()
{
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");

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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";

View File

@ -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<IApplicationBuilder> _app = new ModelBindingWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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(

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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 =

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new ModelBindingWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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 =

View File

@ -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<IApplicationBuilder> _app = new ModelBindingWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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<Func<User, object>> 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<string, string>
@ -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<string, string>
@ -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<string, string>
@ -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<KeyValuePair<string, string>>
@ -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<KeyValuePair<string, string>>
@ -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<string> 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<string, string>
{
@ -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<string, string>
{
@ -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<string, string>
{
@ -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<string, string>
{
@ -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<string, string>
{
@ -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<KeyValuePair<string, string>>
{
@ -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<KeyValuePair<string, string>>
{
@ -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";

View File

@ -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<IApplicationBuilder> _app = new ValidationWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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\"," +

View File

@ -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<IApplicationBuilder> _app = new MvcSample.Web.Startup().Configure;
private readonly Func<IServiceCollection, IServiceProvider> _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

View File

@ -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

View File

@ -21,6 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
private const string SiteName = nameof(MvcTagHelpersWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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<FormTagHelper>((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");

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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 = @"<root data-root=""true""><input class=""form-control"" type=""number"" data-val=""true""" +
@" data-val-range=""The field Age must be between 10 and 100."" data-val-range-max=""100"" "+
@"data-val-range-min=""10"" id=""Age"" name=""Age"" value="""" /><a href="""">Back to List</a></root>";
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>root-content</root>";
var server = TestHelper.CreateServer(_app, SiteName);
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient();
// Act

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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";

View File

@ -15,6 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
private const string SiteName = nameof(RazorPageExecutionInstrumentationWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
public static IEnumerable<object[]> 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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
[Theory]
[InlineData("LayoutSpecifiedWithPartialPathInViewStart")]
@ -26,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
@"<layout>
_ViewStart that specifies partial Layout
</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
@"<non-shared>
Layout specified in page
</non-shared>";
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
@"<non-shared>
Page With Non Partial Layout
</non-shared>";
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
</layout>";
var server = TestHelper.CreateServer(_app, SiteName);
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient();
// Act

View File

@ -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<IApplicationBuilder> _app = new ValidationWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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<string, string>

View File

@ -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<IApplicationBuilder> _app = new RequestServicesWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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";

View File

@ -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<IApplicationBuilder> _app = new FormatterWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<RespectBrowserAcceptHeaderController.Employee xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"" +
@ -70,7 +72,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
public async Task AllMediaRangeAcceptHeader_WithContentTypeHeader_ContentTypeIsHonored(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 requestData = "<RespectBrowserAcceptHeaderController.Employee xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"" +

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
using ResponseCacheWebSite;
using Xunit;
@ -14,12 +15,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
private const string SiteName = nameof(ResponseCacheWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new LowercaseUrlsWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new RoutingWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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);

View File

@ -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<IApplicationBuilder> _app = new XmlFormattersWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<Error><key1>key1-error</key1><key2>The input was not valid.</key2></Error>";
@ -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 = "<Error><key1>key1-error</key1><key2>The input was not valid.</key2></Error>";
@ -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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Employee xmlns=\"http://schemas.datacontract.org/2004/07/XmlFormattersWebSite.Models\">" +

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder, ILoggerFactory> _app = new TagHelperSample.Web.Startup().Configure;
private readonly Action<IServiceCollection> _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++)

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new TempDataWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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<KeyValuePair<string, string>>
{

View File

@ -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<IApplicationBuilder> builder,
string applicationWebSiteName,
string applicationPath,
Func<IServiceCollection, IServiceProvider> 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<IApplicationBuilder> builder,
string applicationWebSiteName,
Func<IServiceCollection, IServiceProvider> configureServices)
{
return TestServer.Create(
CallContextServiceLocator.Locator.ServiceProvider,
builder,
services =>
{
AddTestServices(services, applicationWebSiteName, applicationPath: null, configureServices: null);
return configureServices(services);
});
}
public static TestServer CreateServer(
Action<IApplicationBuilder> builder,
string applicationWebSiteName,
string applicationPath,
@ -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<IApplicationEnvironment>(environment);
services.AddInstance<IHostingEnvironment>(new HostingEnvironment(environment));
// Injecting a custom assembly provider. Overrides AddMvc() because that uses TryAdd().
var assemblyProvider = CreateAssemblyProvider(applicationWebSiteName);
services.AddInstance<IAssemblyProvider>(assemblyProvider);
services.AddInstance(assemblyProvider);
if (configureServices != null)
{

View File

@ -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<IApplicationBuilder> _app = new ValidationWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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\"} }," +

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new VersioningWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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;

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
public static IEnumerable<object[]> 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";

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
public static IEnumerable<object[]> 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
"",
"</partial2>",
"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 =
@"<view-start>Hello Controller-Person</view-start>
<page>Hello Controller-Person</page>";
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
<component-title>ViewComponent With Title</component-title>
<component-body>
Component With Layout</component-body>";
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</component-body>";
{
// Arrange
var expected = @"<page-content>ViewComponent With ViewStart</page-content>";
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</component-body>";
{
// 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</component-body>";
Partial that specifies Layout
</layout-for-viewstart-with-layout>Partial that does not specify Layout
</layout-for-viewstart-with-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
</layout-for-viewstart-with-layout>
Partial that does not specify Layout
</layout-for-viewstart-with-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

View File

@ -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<IApplicationBuilder> _app = new WebApiCompatShimWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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

View File

@ -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<IApplicationBuilder> _app = new WebApiCompatShimWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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);

View File

@ -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<IApplicationBuilder> _app = new WebApiCompatShimWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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" };

View File

@ -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<IApplicationBuilder> _app = new WebApiCompatShimWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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";

View File

@ -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<IApplicationBuilder> _app = new XmlFormattersWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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"));

View File

@ -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<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<Store xmlns=\"http://schemas.datacontract.org/2004/07/XmlFormattersWebSite\" " +
@ -102,7 +104,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
public async Task DataMissingForReferneceTypeProperties_AndModelIsBound_AndHasMixedValidationErrors()
{
// 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 = "<Store xmlns=\"http://schemas.datacontract.org/2004/07/XmlFormattersWebSite\"" +

View File

@ -7,6 +7,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
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(FormatterWebSite);
private readonly Action<IApplicationBuilder> _app = new FormatterWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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");

View File

@ -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<IApplicationBuilder> _app = new XmlFormattersWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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"));

View File

@ -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<IApplicationBuilder> _app = new XmlFormattersWebSite.Startup().Configure;
private readonly Action<IServiceCollection> _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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
@ -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");

View File

@ -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<MvcOptions>(options =>
{
options.AddXmlDataContractSerializerFormatter();
});
});
app.UseErrorReporter();
app.UseMvc(routes =>

View File

@ -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<MvcOptions>(options =>
{
options.AddXmlDataContractSerializerFormatter();
});
});
app.UseMvc(routes =>
{
routes.MapRoute(

View File

@ -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<ViewService, ViewService>();
}
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<ViewService, ViewService>();
});
// Used to report exceptions that MVC doesn't handle
app.UseErrorReporter();

View File

@ -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();

View File

@ -10,29 +10,31 @@ namespace ApiExplorerWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton<ApiExplorerDataFilter>();
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<ApiExplorerDataFilter>();
services.Configure<MvcOptions>(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}");

View File

@ -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<MvcOptions>(options =>
{
options.Conventions.Add(new ApplicationDescription("Common Application Description"));
options.Conventions.Add(new ControllerLicenseConvention());
options.Conventions.Add(new FromHeaderConvention());
});
});
app.UseMvc(routes =>
{
routes.MapRoute(

View File

@ -11,24 +11,25 @@ namespace AutofacWebSite
{
public class Startup
{
// Set up application services
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddTransient<HelloWorldBuilder>();
var builder = new ContainerBuilder();
AutofacRegistration.Populate(builder,
services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
public void Configure(IApplicationBuilder app)
{
var configuration = app.GetTestConfiguration();
app.UseServices(services =>
{
services.AddMvc();
services.AddTransient<HelloWorldBuilder>();
var builder = new ContainerBuilder();
AutofacRegistration.Populate(builder,
services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
});
app.UseMvc(routes =>
{
// This default route is for running the project directly.

View File

@ -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<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
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<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
services.ConfigureMvc(options =>
{
options.Conventions.Add(new ApplicationDescription("This is a basic website."));
});
});
// Add MVC to the request pipeline
app.UseMvc(routes =>
{

View File

@ -9,19 +9,21 @@ namespace BestEffortLinkGenerationWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<RouteOptions>((options) =>
{
options.UseBestEffortLinkGeneration = true;
});
}
public void Configure(IApplicationBuilder app)
{
var configuration = app.GetTestConfiguration();
app.UseServices(services =>
{
services.AddMvc();
services.Configure<RouteOptions>((options) =>
{
options.UseBestEffortLinkGeneration = true;
});
});
app.UseMvc(routes =>
{
routes.MapRoute(

View File

@ -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<MvcOptions>(options =>
{
options.ViewEngines.Insert(0, typeof(TestViewEngine));
});
});
// Add MVC to the request pipeline
app.UseMvc(routes =>
{

View File

@ -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<MvcOptions>(options =>
{
options.AddXmlDataContractSerializerFormatter();
});
});
app.UseErrorReporter();
// Add MVC to the request pipeline

View File

@ -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?}");

View File

@ -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<QueryValueService>();
#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<IServiceProvider>();
#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<QueryValueService>();
#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<IServiceProvider>();
#endif
});
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller}/{action}/{id}");

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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();
}

Some files were not shown because too many files have changed in this diff Show More