From cc7b319cb75a1873850082e7f7b7df206f7afc2b Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 10 Mar 2015 22:25:42 -0700 Subject: [PATCH] Remove use of `ServiceDescriber` in MVC and cleanup related hacks - see issues aspnet/DependencyInjection#193 and #1612 - use `TryAdd()` in `MvcServices` for the `IAssemblyProvider` Move `ApplicationBasePath` handling into `RazorPreCompileModule` - restores view precompilation in functional tests of sample sites - if we need this, others will as well - override `IApplicationEnvironment` but get folder from `ProjectContext` - also remove remaining `IServiceProvider` implementations in this code test fixes: - simplify `IApplicationEnvironment` override - move override logic into `TestHelper.CreateServer()` methods - remove `LoggerFactory` setup - does not seem to require special-casing - remove unused `ITestConfigurationProvider` / `TestConfigurationProvider` - remove `TestAssemblyProvider` classes - no longer required - remove `ReplaceCallContextServiceLocationService` test helper - change MVC sample to fully-qualify config.json path - avoids `ReplaceCallContextServiceLocationService` need in `MvcSampleTests` - no longer required for other tests nit: remove unused `_serviceProvider` and constructor overload in `RazorPreCompiler` --- samples/MvcSample.Web/Startup.cs | 39 ++-- samples/MvcSample.Web/TestAssemblyProvider.cs | 29 --- samples/TagHelperSample.Web/Startup.cs | 5 - .../TestAssemblyProvider.cs | 28 --- .../Razor/PreCompileViews/RazorPreCompiler.cs | 35 ++-- .../MvcServiceCollectionExtensions.cs | 56 +----- src/Microsoft.AspNet.Mvc/MvcServices.cs | 152 ++++++++-------- .../RazorPreCompileModule.cs | 104 +++++++---- .../ActionResultTests.cs | 37 ++-- .../ActivatorTests.cs | 25 ++- .../AntiForgeryTests.cs | 21 ++- .../ApiExplorerTest.cs | 69 ++++--- .../ApplicationModelTest.cs | 21 ++- .../BasicTests.cs | 30 ++-- .../BestEffortLinkGenerationTest.cs | 6 +- .../CompilationOptionsTests.cs | 6 +- .../CompositeViewEngineTests.cs | 7 +- .../ConsumesAttributeTests.cs | 18 +- .../ContentNegotiationTest.cs | 55 +++--- .../ControllerDiscoveryConventionTests.cs | 25 ++- .../ControllerFromServicesTests.cs | 16 +- .../CustomRouteTest.cs | 9 +- .../CustomUrlHelperTests.cs | 66 +++---- .../DefaultOrderTest.cs | 5 +- .../DependencyResolverTests.cs | 13 +- .../DirectivesTest.cs | 7 +- .../ErrorPageTests.cs | 5 +- .../FileResultTests.cs | 15 +- .../FiltersTest.cs | 69 ++++--- .../FlushPointTest.cs | 31 +--- .../FormatFilterTest.cs | 21 ++- .../InlineConstraintTests.cs | 61 ++++--- .../InputFormatterTests.cs | 19 +- .../InputObjectValidationTests.cs | 17 +- .../JsonOutputFormatterTests.cs | 7 +- .../JsonResultTest.cs | 17 +- .../LinkGenerationTests.cs | 7 +- .../Logging/LoggingActionSelectionTest.cs | 12 +- .../Logging/LoggingStartupTest.cs | 7 +- .../ModelBindingFromFormTest.cs | 15 +- .../ModelBindingFromHeaderTest.cs | 29 ++- .../ModelBindingFromQueryTest.cs | 15 +- .../ModelBindingFromRouteTest.cs | 9 +- .../ModelBindingModelBinderAttributeTest.cs | 13 +- .../ModelBindingTest.cs | 169 +++++++++--------- .../ModelMetadataAttributeTest.cs | 18 +- .../MvcSampleTests.cs | 164 ++++++++--------- .../MvcStartupTests.cs | 5 +- .../MvcTagHelpersTest.cs | 29 ++- .../OutputFormatterTest.cs | 13 +- .../PrecompilationTest.cs | 26 +-- .../RazorCompilerCacheTest.cs | 5 +- .../RazorEmbeddedViewsTest.cs | 7 +- .../RazorPageExecutionInstrumentationTest.cs | 43 ++--- .../RazorViewLocationSpecificationTest.cs | 11 +- .../RemoteAttributeValidationTest.cs | 9 +- .../RequestServicesTest.cs | 9 +- .../RespectBrowserAcceptHeaderTests.cs | 13 +- .../ResponseCacheTest.cs | 31 ++-- .../RoundTripTests.cs | 13 +- .../RouteDataTest.cs | 9 +- .../RoutingLowercaseUrlTest.cs | 6 +- .../RoutingTests.cs | 117 ++++++------ .../SerializableErrorTests.cs | 9 +- .../StreamOutputFormatterTest.cs | 5 +- .../TagHelperSampleTest.cs | 48 +++-- .../TagHelpersTest.cs | 13 +- .../TempDataTest.cs | 7 +- .../TestAssemblyProvider.cs | 25 --- .../TestConfigurationProvider.cs | 18 -- .../TestHelper.cs | 169 ++++++++---------- .../TryValidateModelTest.cs | 9 +- .../ValueProviderTest.cs | 11 +- .../VersioningTests.cs | 54 +++--- .../ViewComponentTests.cs | 13 +- .../ViewEngineTests.cs | 35 ++-- .../WebApiCompatShimActionResultTest.cs | 47 +++-- .../WebApiCompatShimActionSelectionTest.cs | 53 +++--- .../WebApiCompatShimBasicTest.cs | 51 +++--- .../WebApiCompatShimParameterBindingTest.cs | 21 ++- ...ontractSerializerFormattersWrappingTest.cs | 20 +-- ...ataContractSerializerInputFormatterTest.cs | 9 +- .../XmlOutputFormatterTests.cs | 20 +-- .../XmlSerializerFormattersWrappingTest.cs | 20 +-- .../XmlSerializerInputFormatterTests.cs | 7 +- .../project.json | 2 +- .../MvcServiceCollectionExtensionsTest.cs | 38 ---- .../BuilderExtensions.cs | 9 +- .../ITestConfigurationProvider.cs | 12 -- .../Preprocess/RazorPreCompilation.cs | 87 +-------- 90 files changed, 1168 insertions(+), 1594 deletions(-) delete mode 100644 samples/MvcSample.Web/TestAssemblyProvider.cs delete mode 100644 samples/TagHelperSample.Web/TestAssemblyProvider.cs delete mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/TestAssemblyProvider.cs delete mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/TestConfigurationProvider.cs delete mode 100644 test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/ITestConfigurationProvider.cs diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs index ab347cd4b8..299d929354 100644 --- a/samples/MvcSample.Web/Startup.cs +++ b/samples/MvcSample.Web/Startup.cs @@ -1,19 +1,25 @@ // 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; +using System.IO; +using Autofac; +#endif using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Razor; +#if DNX451 using Microsoft.Framework.ConfigurationModel; +#endif using Microsoft.Framework.DependencyInjection; +#if DNX451 +using Microsoft.Framework.DependencyInjection.Autofac; +using Microsoft.Framework.Runtime; +#endif using MvcSample.Web.Filters; using MvcSample.Web.Services; -#if DNX451 -using Autofac; -using Microsoft.Framework.DependencyInjection.Autofac; -#endif namespace MvcSample.Web { @@ -22,15 +28,21 @@ namespace MvcSample.Web public void Configure(IApplicationBuilder app) { app.UseStatusCodePages(); - app.UseFileServer(); + #if DNX451 + // Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine + // but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment. + // Functional tests update that service but not in the static provider. + var applicationEnvironment = app.ApplicationServices.GetRequiredService(); + var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json"); + // Set up configuration sources. var configuration = new Configuration() - .AddJsonFile("config.json") - .AddEnvironmentVariables(); - string diSystem; + .AddJsonFile(configurationPath) + .AddEnvironmentVariables(); + string diSystem; if (configuration.TryGet("DependencyInjection", out diSystem) && diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase)) { @@ -46,14 +58,10 @@ namespace MvcSample.Web services.AddSingleton(); services.AddTransient(); - // Setup services with a test AssemblyProvider so that only the - // sample's assemblies are loaded. This prevents loading controllers from other assemblies - // when the sample is used in the Functional Tests. - services.AddTransient>(); services.ConfigureMvcOptions(options => { options.Filters.Add(typeof(PassThroughAttribute), order: 17); - options.AddXmlDataContractSerializerFormatter(); + options.AddXmlDataContractSerializerFormatter(); options.Filters.Add(new FormatFilterAttribute()); }); services.ConfigureRazorViewEngineOptions(options => @@ -90,11 +98,6 @@ namespace MvcSample.Web services.AddSingleton(); services.AddSingleton(); services.AddTransient(); - - // Setup services with a test AssemblyProvider so that only the - // sample's assemblies are loaded. This prevents loading controllers from other assemblies - // when the sample is used in the Functional Tests. - services.AddTransient>(); services.ConfigureMvcOptions(options => { diff --git a/samples/MvcSample.Web/TestAssemblyProvider.cs b/samples/MvcSample.Web/TestAssemblyProvider.cs deleted file mode 100644 index 98b5fd9f7c..0000000000 --- a/samples/MvcSample.Web/TestAssemblyProvider.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Reflection; -using Microsoft.AspNet.Mvc; - -namespace MvcSample.Web -{ - /// - /// Limits MVC to use a single Assembly for controller discovery. - /// This is used by the functional test to limit the Controller discovery to - /// MvcSample.Web Assembly alone. - /// The sample should work in the absense of this file. - /// - /// - /// This is a generic type because it needs to instantiated by a service provider to replace - /// a built-in MVC service. - /// - public class TestAssemblyProvider : IAssemblyProvider - { - public TestAssemblyProvider() - { - CandidateAssemblies = new Assembly[] { typeof(T).GetTypeInfo().Assembly }; - } - - public IEnumerable CandidateAssemblies { get; private set; } - } -} \ No newline at end of file diff --git a/samples/TagHelperSample.Web/Startup.cs b/samples/TagHelperSample.Web/Startup.cs index 8da8ff2024..e69df298f6 100644 --- a/samples/TagHelperSample.Web/Startup.cs +++ b/samples/TagHelperSample.Web/Startup.cs @@ -3,10 +3,8 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Mvc; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using TagHelperSample.Web.Services; namespace TagHelperSample.Web @@ -19,9 +17,6 @@ namespace TagHelperSample.Web { services.AddMvc(); - // Setup services with a test AssemblyProvider so that only the sample's assemblies are loaded. This - // prevents loading controllers from other assemblies when the sample is used in functional tests. - services.AddTransient>(); services.AddSingleton(); }); diff --git a/samples/TagHelperSample.Web/TestAssemblyProvider.cs b/samples/TagHelperSample.Web/TestAssemblyProvider.cs deleted file mode 100644 index d44fbdca47..0000000000 --- a/samples/TagHelperSample.Web/TestAssemblyProvider.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Reflection; -using Microsoft.AspNet.Mvc; - -namespace TagHelperSample.Web -{ - /// - /// Limits MVC to use a single Assembly for controller discovery. This is used by the functional test to limit the - /// Controller discovery to TagHelperSample.Web Assembly alone. The sample should work in the absence of this file - /// when not run from a functional test. - /// - /// - /// This is a generic type because it needs to instantiated by a service provider to replace a built-in MVC - /// service. - /// - public class TestAssemblyProvider : IAssemblyProvider - { - public TestAssemblyProvider() - { - CandidateAssemblies = new Assembly[] { typeof(T).GetTypeInfo().Assembly }; - } - - public IEnumerable CandidateAssemblies { get; private set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs index d6c778fb36..4cf8892920 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs @@ -24,30 +24,29 @@ namespace Microsoft.AspNet.Mvc.Razor { public class RazorPreCompiler { - private readonly IServiceProvider _serviceProvider; private readonly IFileProvider _fileProvider; - public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider, - [NotNull] IBeforeCompileContext compileContext, - [NotNull] IMemoryCache precompilationCache, - [NotNull] CompilationSettings compilationSettings) : - this(designTimeServiceProvider, - compileContext, - designTimeServiceProvider.GetRequiredService(), - designTimeServiceProvider.GetRequiredService>(), - precompilationCache, - compilationSettings) + public RazorPreCompiler( + [NotNull] IServiceProvider designTimeServiceProvider, + [NotNull] IBeforeCompileContext compileContext, + [NotNull] IMemoryCache precompilationCache, + [NotNull] CompilationSettings compilationSettings) + : this( + compileContext, + designTimeServiceProvider.GetRequiredService(), + designTimeServiceProvider.GetRequiredService>(), + precompilationCache, + compilationSettings) { } - public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider, - [NotNull] IBeforeCompileContext compileContext, - [NotNull] IAssemblyLoadContextAccessor loadContextAccessor, - [NotNull] IOptions optionsAccessor, - [NotNull] IMemoryCache precompilationCache, - [NotNull] CompilationSettings compilationSettings) + private RazorPreCompiler( + [NotNull] IBeforeCompileContext compileContext, + [NotNull] IAssemblyLoadContextAccessor loadContextAccessor, + [NotNull] IOptions optionsAccessor, + [NotNull] IMemoryCache precompilationCache, + [NotNull] CompilationSettings compilationSettings) { - _serviceProvider = designTimeServiceProvider; CompileContext = compileContext; LoadContext = loadContextAccessor.GetLoadContext(GetType().GetTypeInfo().Assembly); _fileProvider = optionsAccessor.Options.FileProvider; diff --git a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs index c5df4c49ab..46c48bc64e 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs @@ -25,7 +25,7 @@ namespace Microsoft.Framework.DependencyInjection IConfiguration configuration) { ConfigureDefaultServices(services, configuration); - services.TryAdd(MvcServices.GetDefaultServices(configuration)); + services.TryAdd(MvcServices.GetDefaultServices()); return services; } @@ -46,29 +46,12 @@ namespace Microsoft.Framework.DependencyInjection /// discovery. /// /// The . - /// A sequence of controller s to register in the - /// and used for controller discovery. + /// A sequence of controller s to register in the + /// and used for controller discovery. /// The . public static IServiceCollection WithControllersAsServices( [NotNull] this IServiceCollection services, [NotNull] IEnumerable controllerTypes) - { - return WithControllersAsServices(services, controllerTypes, configuration: null); - } - - /// - /// Register the specified as services and as a source for controller - /// discovery. - /// - /// The . - /// A sequence of controller s to register - /// in the and used for controller discovery. - /// The application's . - /// The . - public static IServiceCollection WithControllersAsServices( - [NotNull] this IServiceCollection services, - [NotNull] IEnumerable controllerTypes, - IConfiguration configuration) { var controllerTypeProvider = new FixedSetControllerTypeProvider(); foreach (var type in controllerTypes) @@ -77,9 +60,8 @@ namespace Microsoft.Framework.DependencyInjection controllerTypeProvider.ControllerTypes.Add(type.GetTypeInfo()); } - var describer = new ServiceDescriber(configuration); - services.Replace(describer.Transient()); - services.Replace(describer.Instance(controllerTypeProvider)); + services.Replace(ServiceDescriptor.Transient()); + services.Replace(ServiceDescriptor.Instance(controllerTypeProvider)); return services; } @@ -94,24 +76,6 @@ namespace Microsoft.Framework.DependencyInjection public static IServiceCollection WithControllersAsServices( [NotNull] this IServiceCollection services, [NotNull] IEnumerable controllerAssemblies) - { - return WithControllersAsServices(services, - controllerAssemblies, - configuration: null); - } - - /// - /// Registers controller types from the specified as services and as a source - /// for controller discovery. - /// - /// The . - /// Assemblies to scan. - /// The application's . - /// The . - public static IServiceCollection WithControllersAsServices( - [NotNull] this IServiceCollection services, - [NotNull] IEnumerable controllerAssemblies, - IConfiguration configuration) { var assemblyProvider = new FixedSetAssemblyProvider(); foreach (var assembly in controllerAssemblies) @@ -123,9 +87,7 @@ namespace Microsoft.Framework.DependencyInjection var controllerTypeProvider = new DefaultControllerTypeProvider(assemblyProvider, loggerFactory); var controllerTypes = controllerTypeProvider.ControllerTypes; - return WithControllersAsServices(services, - controllerTypes.Select(type => type.AsType()), - configuration); + return WithControllersAsServices(services, controllerTypes.Select(type => type.AsType())); } private static void ConfigureDefaultServices(IServiceCollection services, IConfiguration configuration) @@ -135,10 +97,8 @@ namespace Microsoft.Framework.DependencyInjection services.AddRouting(); services.AddAuthorization(configuration); services.AddWebEncoders(); - services.Configure(routeOptions => - routeOptions.ConstraintMap - .Add("exists", - typeof(KnownRouteValueConstraint))); + services.Configure( + routeOptions => routeOptions.ConstraintMap.Add("exists", typeof(KnownRouteValueConstraint))); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs index 5828498774..db5d08c95f 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServices.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.Core; @@ -18,7 +17,6 @@ using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewComponents; using Microsoft.Framework.Cache.Memory; -using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; @@ -26,161 +24,155 @@ namespace Microsoft.AspNet.Mvc { public class MvcServices { - public static IEnumerable GetDefaultServices() + public static IServiceCollection GetDefaultServices() { - return GetDefaultServices(null); - } - - public static IEnumerable GetDefaultServices(IConfiguration configuration) - { - var describe = new ServiceDescriber(configuration); + var services = new ServiceCollection(); // Options and core services. - yield return describe.Transient, MvcOptionsSetup>(); - yield return describe.Transient, RazorViewEngineOptionsSetup>(); - yield return describe.Transient(); + services.AddTransient, MvcOptionsSetup>(); + services.AddTransient, RazorViewEngineOptionsSetup>(); - yield return describe.Transient(); - yield return describe.Singleton(typeof(ITypeActivatorCache), typeof(DefaultTypeActivatorCache)); - yield return describe.Scoped(typeof(IScopedInstance<>), typeof(ScopedInstance<>)); + // TryAdd() so functional tests can override this particular service. Test setup runs before this method. + services.TryAdd(ServiceDescriptor.Transient()); + + services.AddTransient(); + services.AddSingleton(); + services.AddScoped(typeof(IScopedInstance<>), typeof(ScopedInstance<>)); // Core action discovery, filters and action execution. // These are consumed only when creating action descriptors, then they can be de-allocated - yield return describe.Transient(); - yield return describe.Transient(); - yield return describe.Transient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); // This has a cache, so it needs to be a singleton - yield return describe.Singleton(); + services.AddSingleton(); - yield return describe.Transient(); + services.AddTransient(); // This accesses per-reqest services - yield return describe.Transient(); + services.AddTransient(); // This provider needs access to the per-request services, but might be used many times for a given // request. - yield return describe.Transient(); + services.AddTransient(); - yield return describe.Singleton(); - yield return describe.Singleton(); - yield return describe.Transient(); - yield return describe.Transient(); + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + services.AddTransient(); - yield return describe.Transient(); + services.AddTransient(); - yield return describe.Transient(); + services.AddTransient(); - yield return describe.Singleton(); + services.AddSingleton(); // The IGlobalFilterProvider is used to build the action descriptors (likely once) and so should // remain transient to avoid keeping it in memory. - yield return describe.Transient(); - yield return describe.Transient(); + services.AddTransient(); + services.AddTransient(); - yield return describe.Transient(); + services.AddTransient(); // Dataflow - ModelBinding, Validation and Formatting // // The DefaultModelMetadataProvider does significant caching and should be a singleton. - yield return describe.Singleton(); - yield return describe.Transient(services => + services.AddSingleton(); + services.AddTransient(serviceProvider => { - var options = services.GetRequiredService>().Options; + var options = serviceProvider.GetRequiredService>().Options; return new DefaultCompositeMetadataDetailsProvider(options.ModelMetadataDetailsProviders); }); - yield return describe.Transient(); - yield return describe.Scoped(); + services.AddTransient(); + services.AddScoped(); - yield return describe.Transient(); - yield return describe.Transient(); - yield return describe.Transient(); - yield return describe.Instance(new JsonOutputFormatter()); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddInstance(new JsonOutputFormatter()); - yield return describe.Transient(); - yield return describe.Transient(); + services.AddTransient(); + services.AddTransient(); // Razor, Views and runtime compilation // The provider is inexpensive to initialize and provides ViewEngines that may require request // specific services. - yield return describe.Scoped(); - yield return describe.Transient(); + services.AddScoped(); + services.AddTransient(); // Transient since the IViewLocationExpanders returned by the instance is cached by view engines. - yield return describe.Transient(); + services.AddTransient(); // Caches view locations that are valid for the lifetime of the application. - yield return describe.Singleton(); - yield return describe.Singleton(serviceProvider => + services.AddSingleton(); + services.AddSingleton(serviceProvider => { var cachedFileProvider = serviceProvider.GetRequiredService>(); return new DefaultCodeTreeCache(cachedFileProvider.Options.FileProvider); }); // The host is designed to be discarded after consumption and is very inexpensive to initialize. - yield return describe.Transient(); - + services.AddTransient(); + // Caches compilation artifacts across the lifetime of the application. - yield return describe.Singleton(); + services.AddSingleton(); // This caches compilation related details that are valid across the lifetime of the application // and is required to be a singleton. - yield return describe.Singleton(); + services.AddSingleton(); // Both the compiler cache and roslyn compilation service hold on the compilation related // caches. RazorCompilation service is just an adapter service, and it is transient to ensure // the IMvcRazorHost dependency does not maintain state. - yield return describe.Transient(); + services.AddTransient(); // The ViewStartProvider needs to be able to consume scoped instances of IRazorPageFactory - yield return describe.Scoped(); - yield return describe.Transient(); - yield return describe.Singleton(); + services.AddScoped(); + services.AddTransient(); + services.AddSingleton(); // Virtual path view factory needs to stay scoped so views can get get scoped services. - yield return describe.Scoped(); + services.AddScoped(); // View and rendering helpers - yield return describe.Transient(); - yield return describe.Transient(typeof(IHtmlHelper<>), typeof(HtmlHelper<>)); - yield return describe.Scoped(); + services.AddTransient(); + services.AddTransient(typeof(IHtmlHelper<>), typeof(HtmlHelper<>)); + services.AddScoped(); // Only want one ITagHelperActivator so it can cache Type activation information. Types won't conflict. - yield return describe.Singleton(); + services.AddSingleton(); // Consumed by the Cache tag helper to cache results across the lifetime of the application. - yield return describe.Singleton(); + services.AddSingleton(); // DefaultHtmlGenerator is pretty much stateless but depends on Scoped services such as IUrlHelper and // IActionBindingContextProvider. Therefore it too is scoped. - yield return describe.Transient(); + services.AddTransient(); // These do caching so they should stay singleton - yield return describe.Singleton(); - yield return describe.Singleton(); + services.AddSingleton(); + services.AddSingleton(); - yield return describe.Transient(); - yield return describe.Transient(); - yield return describe.Transient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); // Security and Authorization - yield return describe.Singleton(); - yield return describe.Singleton(); - yield return describe.Singleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); // Api Description - yield return describe.Singleton(); - yield return describe.Transient(); + services.AddSingleton(); + services.AddTransient(); // Temp Data - yield return describe.Singleton(); - yield return describe.Scoped(); + services.AddSingleton(); + services.AddScoped(); + + return services; } } } diff --git a/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs b/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs index a42a69f8d5..ab1deeaf5e 100644 --- a/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs +++ b/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs @@ -3,8 +3,10 @@ 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; @@ -16,14 +18,22 @@ using Microsoft.Framework.Runtime.Roslyn; namespace Microsoft.AspNet.Mvc { + /// + /// An implementation that pre-compiles Razor views in the application. + /// public abstract class RazorPreCompileModule : ICompileModule { private readonly IServiceProvider _appServices; private readonly IMemoryCache _memoryCache; + /// + /// Instantiates a new instance. + /// + /// The for the application. public RazorPreCompileModule(IServiceProvider services) { _appServices = services; + // When ListenForMemoryPressure is true, the MemoryCache evicts items at every gen2 collection. // In DTH, gen2 happens frequently enough to make it undesirable for caching precompilation results. We'll // disable listening for memory pressure for the MemoryCache instance used by precompilation. @@ -35,61 +45,95 @@ namespace Microsoft.AspNet.Mvc /// public bool GenerateSymbols { get; protected set; } - protected virtual string FileExtension { get; } = ".cshtml"; - + /// + /// Pre-compiles all Razor views in the application. public virtual void BeforeCompile(IBeforeCompileContext context) { var applicationEnvironment = _appServices.GetRequiredService(); var compilerOptionsProvider = _appServices.GetRequiredService(); var compilationSettings = compilerOptionsProvider.GetCompilationSettings(applicationEnvironment); - var setup = new RazorViewEngineOptionsSetup(applicationEnvironment); - var sc = new ServiceCollection(); - sc.ConfigureOptions(setup); - sc.AddMvc(); + // Create something similar to a HttpContext.RequestServices provider. Necessary because this class is + // instantiated in a lower-level "HttpContext.ApplicationServices" context. One important added service + // is an IOptions but use AddMvc() for simplicity and flexibility. + var serviceCollection = HostingServices.Create(_appServices); + serviceCollection.AddMvc(); - var serviceProvider = BuildFallbackServiceProvider(sc, _appServices); + // 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, + // after everything is compiled. IOptions setup initializes the + // RazorViewEngineOptions based on this IApplicationEnvironment implementation. + var directory = context.ProjectContext.ProjectDirectory; + var precompilationApplicationEnvironment = new PrecompilationApplicationEnvironment( + applicationEnvironment, + context.ProjectContext.ProjectDirectory); + serviceCollection.AddInstance(precompilationApplicationEnvironment); + + var serviceProvider = serviceCollection.BuildServiceProvider(); var viewCompiler = new RazorPreCompiler(serviceProvider, context, _memoryCache, compilationSettings) { GenerateSymbols = GenerateSymbols }; + viewCompiler.CompileViews(); } + /// public void AfterCompile(IAfterCompileContext context) { } - // TODO: KILL THIS - private static IServiceProvider BuildFallbackServiceProvider( - IServiceCollection services, - IServiceProvider fallback) + private class PrecompilationApplicationEnvironment : IApplicationEnvironment { - var sc = HostingServices.Create(fallback); - sc.Add(services); + private readonly IApplicationEnvironment _originalApplicationEnvironment; + private readonly string _applicationBasePath; - // Build the manifest - var manifestTypes = services.Where(t => t.ServiceType.GetTypeInfo().GenericTypeParameters.Length == 0 - && t.ServiceType != typeof(IServiceManifest) - && t.ServiceType != typeof(IServiceProvider)) - .Select(t => t.ServiceType).Distinct(); - sc.AddInstance( - new ServiceManifest(manifestTypes, fallback.GetRequiredService())); - return sc.BuildServiceProvider(); - } - - private class ServiceManifest : IServiceManifest - { - public ServiceManifest(IEnumerable services, IServiceManifest fallback = null) + public PrecompilationApplicationEnvironment(IApplicationEnvironment original, string appBasePath) { - Services = services; - if (fallback != null) + _originalApplicationEnvironment = original; + _applicationBasePath = appBasePath; + } + + public string ApplicationName + { + get { - Services = Services.Concat(fallback.Services).Distinct(); + return _originalApplicationEnvironment.ApplicationName; } } - public IEnumerable Services { get; private set; } + public string Version + { + get + { + return _originalApplicationEnvironment.Version; + } + } + + public string ApplicationBasePath + { + get + { + return _applicationBasePath; + } + } + + public string Configuration + { + get + { + return _originalApplicationEnvironment.Configuration; + } + } + + public FrameworkName RuntimeFramework + { + get + { + return _originalApplicationEnvironment.RuntimeFramework; + } + } } } } diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs index 813e9cd4c0..58cec78c25 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActionResultTests.cs @@ -2,30 +2,27 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; -using System.Xml.Serialization; using ActionResultsWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ActionResultTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("ActionResultsWebSite"); + private const string SiteName = nameof(ActionResultsWebSite); private readonly Action _app = new Startup().Configure; - + [Fact] public async Task BadRequestResult_CanBeReturned() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{\"SampleInt\":10}"; @@ -47,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsRelativePathInLocationHeader() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -67,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsAbsolutePathInLocationHeader() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -87,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsQualifiedPathInLocationHeader() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -109,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedResult_SetsUriInLocationHeader() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -129,7 +126,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedAtActionResult_GeneratesUri_WithActionAndController() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -149,7 +146,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedAtRouteResult_GeneratesUri_WithRouteValues() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -169,7 +166,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CreatedAtRouteResult_GeneratesUri_WithRouteName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -189,7 +186,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SerializableError_CanSerializeNormalObjects() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "" + @@ -212,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ContentResult_WritesContent_SetsDefaultContentTypeAndEncoding() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -232,7 +229,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ContentResult_WritesContent_SetsContentTypeWithDefaultEncoding() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -252,7 +249,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ContentResult_WritesContent_SetsContentTypeAndEncoding() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -272,7 +269,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ObjectResult_WithStatusCodeAndNoContent_SetsSameStatusCode() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Get, @@ -289,7 +286,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HttpNotFoundObjectResult_NoResponseContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -308,7 +305,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HttpNotFoundObjectResult_WithResponseContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{\"SampleInt\":10}"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs index 32298bce09..c8350aafb1 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs @@ -5,21 +5,20 @@ using System; using System.Threading.Tasks; using ActivatorWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ActivatorTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("ActivatorWebSite"); + private const string SiteName = nameof(ActivatorWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task ControllerThatCannotBeActivated_ThrowsWhenAttemptedToBeInvoked() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMessage = "The property 'Service' on controller 'ActivatorWebSite.CannotBeActivatedController' " + @@ -37,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesForPocoControllersAreInitialized() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "4|some-text"; @@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesForTypesDerivingFromControllerAreInitialized() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "Hello world"; @@ -70,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewActivator_ActivatesDefaultInjectedProperties() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @" world! /View/ConsumeServicesFromBaseType"; @@ -85,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewActivator_ActivatesAndContextualizesInjectedServices() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "4 test-value"; @@ -100,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewActivator_ActivatesServicesFromBaseType() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @"/content/scripts/test.js"; @@ -115,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentActivator_ActivatesProperties() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @"Random Number:4"; @@ -130,7 +129,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentActivator_ActivatesPropertiesAndContextualizesThem() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "test-value"; @@ -145,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentActivator_ActivatesPropertiesAndContextualizesThem_WhenMultiplePropertiesArePresent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "Random Number:4 test-value"; @@ -160,7 +159,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewComponentThatCannotBeActivated_ThrowsWhenAttemptedToBeInvoked() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMessage = "No service for type 'ActivatorWebSite.CannotBeActivatedComponent+FakeType' " + "has been registered."; @@ -177,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TagHelperActivation_ActivateHtmlHelper_RendersProperly() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "

Activation Test

" + Environment.NewLine + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs index ff735002c8..24c3fc3203 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/AntiForgeryTests.cs @@ -8,21 +8,20 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class AntiForgeryTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("AntiForgeryWebSite"); + private const string SiteName = nameof(AntiForgeryWebSite); private readonly Action _app = new AntiForgeryWebSite.Startup().Configure; [Fact] public async Task MultipleAFTokensWithinTheSamePage_GeneratesASingleCookieToken() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -45,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleFormPostWithingASingleView_AreAllowed() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // do a get response. @@ -80,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task InvalidCookieToken_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var getResponse = await client.GetAsync("http://localhost/Account/Login"); @@ -112,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task InvalidFormToken_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var getResponse = await client.GetAsync("http://localhost/Account/Login"); @@ -142,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task IncompatibleCookieToken_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // do a get response. @@ -180,7 +179,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MissingCookieToken_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // do a get response. @@ -210,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MissingAFToken_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var getResponse = await client.GetAsync("http://localhost/Account/Login"); var resposneBody = await getResponse.Content.ReadAsStringAsync(); @@ -239,7 +238,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetCookieAndHeaderBeforeFlushAsync_GeneratesCookieTokenAndHeader() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -259,7 +258,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetCookieAndHeaderBeforeFlushAsync_PostToForm() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // do a get response. diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs index 7b5a102bc1..a17e6dd3b7 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApiExplorerTest.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -16,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ApiExplorerTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices("ApiExplorerWebSite"); + private const string SiteName = nameof(ApiExplorerWebSite); private readonly Action _app = new ApiExplorerWebSite.Startup().Configure; [Fact] public async Task ApiExplorer_IsVisible_EnabledWithConvention() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -40,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_IsVisible_DisabledWithConvention() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -57,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_IsVisible_DisabledWithAttribute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -74,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_IsVisible_EnabledWithAttribute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -91,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_GroupName_SetByConvention() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -109,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_GroupName_SetByAttributeOnController() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -127,7 +126,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_GroupName_SetByAttributeOnAction() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -145,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_DisplaysFixedRoute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -163,7 +162,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_DisplaysRouteWithParameters() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -187,7 +186,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_StripsInlineConstraintsFromThePath() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/Constraint/5"; @@ -212,7 +211,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_StripsCatchAllsFromThePath() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/CatchAll/5"; @@ -236,7 +235,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_StripsCatchAllsWithConstraintsFromThePath() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/CatchAllAndConstraint/5"; @@ -263,7 +262,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplateStripsMultipleConstraints_OnTheSamePathSegment() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/" @@ -302,7 +301,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplateStripsMultipleConstraints_InMultipleSegments() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/" + "MultipleParametersInMultipleSegments/12/01/1987"; @@ -340,7 +339,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_DescribeParameters_FromAllSources() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ApiExplorerRouteAndPathParametersInformation/MultipleTypesOfParameters/1/2/3"; @@ -371,7 +370,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_RouteTemplate_MakesParametersOptional() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -393,7 +392,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_HttpMethod_All() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -411,7 +410,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_HttpMethod_Single() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -433,7 +432,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_HttpMethod_Single(string httpMethod) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -459,7 +458,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_VoidWithoutAttribute(string action) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -484,7 +483,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_UnknownWithoutAttribute(string action) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -507,7 +506,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_KnownWithoutAttribute(string action, string type) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -531,7 +530,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_KnownWithAttribute(string action, string type) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -552,7 +551,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseType_OverrideOnAction(string action, string type) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -571,7 +570,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseContentType_Unset() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -601,7 +600,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseContentType_Specific() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -627,7 +626,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ResponseContentType_NoMatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -652,7 +651,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string formatterType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -674,7 +673,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_Default() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -702,7 +701,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_BinderMetadataOnParameters() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -730,7 +729,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_ParametersSimpleModel() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -754,7 +753,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_SimpleModel_FromBody() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -782,7 +781,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiExplorer_Parameters_SimpleTypes_ComplexModel() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs index 232dfc9c6c..54b6429c57 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ApplicationModelTest.cs @@ -6,21 +6,20 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ApplicationModelTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ApplicationModelWebSite)); + private const string SiteName = nameof(ApplicationModelWebSite); private readonly Action _app = new ApplicationModelWebSite.Startup().Configure; [Fact] public async Task ControllerModel_CustomizedWithAttribute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -37,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionModel_CustomizedWithAttribute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -54,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParameterModel_CustomizedWithAttribute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -71,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModel_AddPropertyToActionDescriptor_FromApplicationModel() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -88,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModel_AddPropertyToActionDescriptor_ControllerModelOverwritesCommonApplicationProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -105,7 +104,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModel_ProvidesMetadataToActionDescriptor_ActionModelOverwritesControllerModelProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -122,7 +121,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModelExtensions_AddsConventionToAllControllers() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -141,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApplicationModelExtensions_AddsConventionToAllActions() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Home/GetHelloWorld"); @@ -149,7 +148,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Act var response = await client.SendAsync(request); - + // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs index 907c67cc97..f411f2d134 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/BasicTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -11,7 +10,6 @@ using System.Reflection; using System.Threading.Tasks; using BasicWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -19,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class BasicTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(BasicWebSite)); + private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new Startup().Configure; // Some tests require comparing the actual response body against an expected response baseline @@ -35,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanRender_ViewsWithLayout(string url) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -59,7 +57,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanRender_SimpleViews() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync("compiler/resources/BasicWebSite.Home.PlainView.html"); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -79,7 +77,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanReturn_ResultsWithoutContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -97,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ReturningTaskFromAction_ProducesNoContentResult() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -112,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionDescriptors_CreatedOncePerRequest() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = "1"; @@ -132,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionWithRequireHttps_RedirectsToSecureUrl_ForNonHttpsGetRequests() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -152,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionWithRequireHttps_ReturnsBadRequestResponse_ForNonHttpsNonGetRequests() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -174,7 +172,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionWithRequireHttps_AllowsHttpsRequests(string method) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -190,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonViewComponent_RendersJson() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = new HttpClient(server.CreateHandler(), false); var expectedBody = JsonConvert.SerializeObject(new BasicWebSite.Models.Person() { @@ -249,7 +247,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HtmlHelperLinkGeneration(string viewName, string expectedLink) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -265,7 +263,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConfigureMvcOptionsAddsOptionsProperly() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -281,7 +279,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesWithoutControllerSuffix_DerivingFromTypesWithControllerSuffix_CanBeAccessed() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = new HttpClient(server.CreateHandler(), false); // Act @@ -295,7 +293,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesMarkedAsNonAction_AreInaccessible() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = new HttpClient(server.CreateHandler(), false); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs index e6c7795516..7f993adac8 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/BestEffortLinkGenerationTest.cs @@ -6,7 +6,6 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -14,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public class BestEffortLinkGenerationTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(BestEffortLinkGenerationWebSite)); + private const string SiteName = nameof(BestEffortLinkGenerationWebSite); private readonly Action _app = new BestEffortLinkGenerationWebSite.Startup().Configure; private const string ExpectedOutput = @" @@ -27,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GenerateLink_NonExistentAction() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/Home/Index"; @@ -39,6 +38,5 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(ExpectedOutput, content); } - } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs index d0a107341f..b9d0079b84 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompilationOptionsTests.cs @@ -2,10 +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.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using RazorWebSite; using Xunit; @@ -15,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // precompiled and dynamically compiled views. public class CompilationOptionsTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(RazorWebSite)); + private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; [Fact] @@ -33,7 +31,7 @@ This method is only defined in DNX451"; This method is only defined in DNXCORE50"; #endif - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs index 82cd75a224..fa02027309 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CompositeViewEngineTests.cs @@ -4,21 +4,20 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class CompositeViewEngineTests { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(CompositeViewEngineWebSite)); + private const string SiteName = nameof(CompositeViewEngineWebSite); private readonly Action _app = new CompositeViewEngineWebSite.Startup().Configure; [Fact] public async Task CompositeViewEngine_FindsPartialViewsAcrossAllEngines() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -32,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CompositeViewEngine_FindsViewsAcrossAllEngines() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs index c1739bb4d7..061510af52 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ConsumesAttributeTests.cs @@ -2,16 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; -using System.Xml.Serialization; using ActionConstraintsWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -19,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ConsumesAttributeTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("ActionConstraintsWebSite"); + private const string SiteName = nameof(ActionConstraintsWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task NoRequestContentType_SelectsActionWithoutConstraint() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -45,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoRequestContentType_Throws_IfMultipleActionsWithConstraints() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, @@ -69,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -91,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Selects_Action_BasedOnRequestContentType(string requestContentType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{SampleString:\""+requestContentType+"\"}"; @@ -114,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionLevelAttribute_OveridesClassLevel(string requestContentType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{SampleString:\"" + requestContentType + "\"}"; @@ -137,7 +133,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task DerivedClassLevelAttribute_OveridesBaseClassLevel() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = " _app = new Startup().Configure; [Fact] public async Task ProducesAttribute_SingleContentType_PicksTheFirstSupportedFormatter() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Selects custom even though it is last in the list. @@ -48,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_MultipleContentTypes_RunsConnegToSelectFormatter() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); 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}"; @@ -66,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoProducesAttribute_ActionReturningString_RunsUsingTextFormatter() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("text/plain;charset=utf-8"); var expectedBody = "NormalController"; @@ -84,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoProducesAttribute_ActionReturningAnyObject_RunsUsingDefaultFormatters() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -99,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttributeWithTypeOnly_RunsRegularContentNegotiation() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -119,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_WithTypeAndContentType_UsesContentType() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); var expectedContentType = MediaTypeHeaderValue.Parse("application/xml;charset=utf-8"); @@ -141,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchingFormatter_ForTheGivenContentType_Returns406() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -160,7 +155,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedResponseBody) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); expectedResponseBody = expectedResponseBody.Replace("#", Environment.NewLine); @@ -181,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnAction_OverridesTheValueOnClass() { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Value on the class is application/json. @@ -201,7 +196,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnDerivedClass_OverridesTheValueOnBaseClass() { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_ProducesContentOnClassController;charset=utf-8"); @@ -220,7 +215,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnDerivedAction_OverridesTheValueOnBaseClass() { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_NoProducesContentOnClassController_Action;charset=utf-8"); @@ -238,7 +233,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ProducesAttribute_OnDerivedAction_OverridesTheValueOnBaseAction() { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_NoProducesContentOnClassController_Action;charset=utf-8"); @@ -257,7 +252,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_OnDerivedClassAndAction_OverridesTheValueOnBaseClass() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse( "application/custom_ProducesContentOnClassController_Action;charset=utf-8"); @@ -276,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_IsNotHonored_ForJsonResult() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"Produces_WithNonObjectResult\"}"; @@ -294,7 +289,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_UsesDefaultContentTypes_IfNoneAreAddedExplicitly() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"ReturnJsonResult\"}"; @@ -312,7 +307,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_UsesExplicitContentTypeAndFormatter_IfAdded() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/custom-json;charset=utf-8"); var expectedBody = "{ MethodName = ReturnJsonResult_WithCustomMediaType }"; @@ -330,7 +325,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_UsesDefaultJsonFormatter_IfNoMatchingFormatterIsFound() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"ReturnJsonResult_WithCustomMediaType_NoFormatter\"}"; @@ -348,7 +343,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonFormatter_SupportedMediaType_DoesNotChangeAcrossRequests() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "{\"MethodName\":\"ReturnJsonResult\"}"; @@ -368,7 +363,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlFormatter_SupportedMediaType_DoesNotChangeAcrossRequests() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); @@ -394,7 +389,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchOn_RequestContentType_FallsBackOnTypeBasedMatch_MatchFound(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); var expectedBody = "1234"; @@ -419,7 +414,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchOn_RequestContentType_SkipTypeMatchByAddingACustomFormatter(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var targetUri = "http://localhost/FallbackOnTypeBasedMatch/" + actionName + "/?input=1234"; var content = new StringContent("1234", Encoding.UTF8, "application/custom"); @@ -438,7 +433,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoMatchOn_RequestContentType_FallsBackOnTypeBasedMatch_NoMatchFound_Returns406() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var targetUri = "http://localhost/FallbackOnTypeBasedMatch/FallbackGivesNoMatch/?input=1234"; var content = new StringContent("1234", Encoding.UTF8, "application/custom"); @@ -457,7 +452,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_And_FormatFilterAttribute_Conflicting() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json"); @@ -472,7 +467,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ProducesAttribute_And_FormatFilterAttribute_Collaborating() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs index 53481f4a3e..6ae8e62a22 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerDiscoveryConventionTests.cs @@ -8,8 +8,6 @@ using System.Net; using System.Threading.Tasks; using ControllerDiscoveryConventionsWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime; using Xunit; @@ -18,15 +16,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ControllerDiscoveryConventionTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices( - nameof(ControllerDiscoveryConventionsWebSite)); + private const string SiteName = nameof(ControllerDiscoveryConventionsWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task AbstractControllers_AreSkipped() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -41,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesDerivingFromControllerBaseTypesThatDoNotReferenceMvc_AreSkipped() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -56,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesMarkedWithNonController_AreSkipped() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -71,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PocoTypesWithControllerSuffix_AreDiscovered() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -87,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesDerivingFromTypesWithControllerSuffix_AreDiscovered() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); @@ -103,13 +100,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypesDerivingFromApiController_AreDiscovered() { // Arrange - // TestHelper.CreateServices replaces the DefaultAssemblyProvider with a provider that + // TestHelper.CreateServer normally replaces the DefaultAssemblyProvider with a provider that // limits the set of candidate assemblies to the executing application. For this test, // we'll switch it back to using a filtered default assembly provider. - var services = HostingServices.Create(); - services.AddTransient(); - var serviceProvider = TestHelper.CreateServices(nameof(ControllerDiscoveryConventionsWebSite), services); - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer( + _app, + SiteName, + services => services.AddTransient()); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost/"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs index f7e94fa191..7439403599 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ControllerFromServicesTests.cs @@ -7,15 +7,13 @@ using System.Net.Http; using System.Threading.Tasks; using ControllersFromServicesWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ControllerFromServicesTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices( - nameof(ControllersFromServicesWebSite)); + private const string SiteName = nameof(ControllersFromServicesWebSite); private readonly Action _app = new Startup().Configure; [Fact] @@ -23,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "/constructorinjection 14 test-header-value"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Test-Header", "test-header-value"); @@ -39,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "No schedules available for 23"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -54,7 +52,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "4"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -69,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "Updated record employee303"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -86,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "Saved record employee #211"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -106,7 +104,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AddControllersFromServices_UsesControllerDiscoveryContentions(string action) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs index 95a0b35d5c..f989a9d70d 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomRouteTest.cs @@ -2,20 +2,17 @@ // 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.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; -using Newtonsoft.Json; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class CustomRouteTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(CustomRouteWebSite)); + private const string SiteName = nameof(CustomRouteWebSite); private readonly Action _app = new CustomRouteWebSite.Startup().Configure; [Theory] @@ -25,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteToLocale_ConventionalRoute_BasedOnUser(string user, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/CustomRoute_Products/Index"); @@ -47,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteWithAttributeRoute_IncludesLocale_BasedOnUser(string user, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/CustomRoute_Orders/5"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs index 18710a3326..57d4f3e208 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/CustomUrlHelperTests.cs @@ -5,7 +5,6 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -19,46 +18,40 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests /// public class CustomUrlHelperTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("UrlHelperWebSite"); + private const string SiteName = nameof(UrlHelperWebSite); private readonly Action _app = new UrlHelperWebSite.Startup().Configure; private const string _cdnServerBaseUrl = "http://cdn.contoso.com"; [Fact] public async Task CustomUrlHelper_GeneratesUrlFromController() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync("http://localhost/Home/UrlContent"); - var responseData = await response.Content.ReadAsStringAsync(); + // Act + var response = await client.GetAsync("http://localhost/Home/UrlContent"); + var responseData = await response.Content.ReadAsStringAsync(); - //Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(_cdnServerBaseUrl + "/bootstrap.min.css", responseData); - } + //Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(_cdnServerBaseUrl + "/bootstrap.min.css", responseData); } [Fact] public async Task CustomUrlHelper_GeneratesUrlFromView() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync("http://localhost/Home/Index"); - var responseData = await response.Content.ReadAsStringAsync(); + // Act + var response = await client.GetAsync("http://localhost/Home/Index"); + var responseData = await response.Content.ReadAsStringAsync(); - //Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Contains(_cdnServerBaseUrl + "/bootstrap.min.css", responseData); - } + //Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Contains(_cdnServerBaseUrl + "/bootstrap.min.css", responseData); } [Theory] @@ -66,20 +59,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("http://localhost/Home/LinkByUrlAction", "/home/urlcontent")] public async Task LowercaseUrls_LinkGeneration(string url, string expectedLink) { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync(url); - var responseData = await response.Content.ReadAsStringAsync(); + // Act + var response = await client.GetAsync(url); + var responseData = await response.Content.ReadAsStringAsync(); - //Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(expectedLink, responseData, ignoreCase: false); - } + //Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(expectedLink, responseData, ignoreCase: false); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs index 19c890ea85..e2e3ccd0b8 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DefaultOrderTest.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Description; using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.ViewComponents; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.OptionsModel; using Xunit; @@ -19,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Tests that various MVC services have the correct order. public class DefaultOrderTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(BasicWebSite)); + private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; [Theory] @@ -34,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ServiceOrder_GetOrder(Type serviceType, Type actualType, int order) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/Order/GetServiceOrder?serviceType=" + serviceType.AssemblyQualifiedName; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs index 9470d62db8..c9f03fe6d6 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DependencyResolverTests.cs @@ -3,29 +3,26 @@ #if DNX451 using System; -using System.Net.Http; using System.Threading.Tasks; using AutofacWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class DependencyResolverTests { + private const string SiteName = nameof(AutofacWebSite); + private readonly Action _app = new Startup().Configure; + [Theory] [InlineData("http://localhost/di", "

Builder Output: Hello from builder.

")] [InlineData("http://localhost/basic", "

Hello From Basic View

")] public async Task AutofacDIContainerCanUseMvc(string url, string expectedResponseBody) { - // Arrange - var provider = TestHelper.CreateServices("AutofacWebSite"); - Action app = new Startup().Configure; - - // Act & Assert (does not throw) + // Arrange & Act & Assert (does not throw) // This essentially calls into the Startup.Configuration method - var server = TestServer.Create(provider, app); + var server = TestHelper.CreateServer(_app, SiteName); // Make a request to start resolving DI pieces var response = await server.CreateClient().GetAsync(url); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs index b52f59b3c6..25b24c3482 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/DirectivesTest.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using RazorWebSite; using Xunit; @@ -12,14 +11,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class DirectivesTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices("RazorWebSite"); + private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task ViewsInheritsUsingsAndInjectDirectivesFromViewStarts() { var expected = @"Hello Person1"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -33,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ViewInheritsBasePageFromViewStarts() { var expected = @"WriteLiteral says:layout:Write says:Write says:Hello Person2"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs index fccca52160..a2152480cd 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ErrorPageTests.cs @@ -8,7 +8,6 @@ using System.Reflection; using System.Threading.Tasks; using ErrorPageMiddlewareWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -18,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests /// public class ErrorPageTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(ErrorPageMiddlewareWebSite)); + private const string SiteName = nameof(ErrorPageMiddlewareWebSite); private readonly Action _app = new Startup().Configure; private readonly Assembly _resourcesAssembly = typeof(ErrorPageTests).GetTypeInfo().Assembly; @@ -32,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CompilationFailuresAreListedByErrorPageMiddleware(string action, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs index dd7904efe3..09bf80ed31 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FileResultTests.cs @@ -5,21 +5,20 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class FileResultTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("FilesWebSite"); + private const string SiteName = nameof(FilesWebSite); private readonly Action _app = new FilesWebSite.Startup().Configure; [Fact] public async Task FileFromDisk_CanBeEnabled_WithMiddleware() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -40,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromDisk_ReturnsFileWithFileName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -65,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromStream_ReturnsFile() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -86,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromStream_ReturnsFileWithFileName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -111,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromBinaryData_ReturnsFile() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -132,7 +131,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FileFromBinaryData_ReturnsFileWithFileName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs index d2d7008427..34b0b1aff4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FiltersTest.cs @@ -9,14 +9,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class FiltersTest { - private readonly IServiceProvider _services = TestHelper.CreateServices("FiltersWebSite"); + private const string SiteName = nameof(FiltersWebSite); private readonly Action _app = new FiltersWebSite.Startup().Configure; // A controller can only be an action filter and result filter, so we don't have entries @@ -25,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ListAllFilters() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = new string[] @@ -81,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AnonymousUsersAreBlocked() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -95,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllowsAnonymousUsersToAccessController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -114,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanAuthorize(string testAction) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -130,7 +129,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllowAnonymousOverridesAuthorize() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -146,7 +145,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ImpossiblePolicyFailsAuthorize() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -161,7 +160,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ServiceFilterUsesRegisteredServicesAsFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -176,7 +175,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ServiceFilterThrowsIfServiceIsNotRegistered() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/RandomNumber/GetAuthorizedRandomNumber"; @@ -192,7 +191,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypeFilterInitializesArguments() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/RandomNumber/GetModifiedRandomNumber?randomNumber=10"; @@ -208,7 +207,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TypeFilterThrowsIfServicesAreNotRegistered() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/RandomNumber/GetHalfOfModifiedRandomNumber?randomNumber=3"; @@ -224,7 +223,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFilterOverridesActionExecuted() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -241,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilterOverridesOnResultExecuting() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -258,7 +257,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilterOverridesOnResultExecuted() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -275,7 +274,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task OrderOfExecutionOfFilters_WhenOrderAttribute_IsNotMentioned() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -293,7 +292,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionsHandledInActionFilters_WillNotShortCircuitResultFilters() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -310,7 +309,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionFilter_OnAction_ShortCircuitsResultFilters() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -329,7 +328,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GlobalExceptionFilter_HandlesAnException() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -346,7 +345,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionFilter_Scope() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -367,7 +366,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFilter_Scope() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -394,7 +393,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilter_Scope() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -417,7 +416,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FiltersWithOrder() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -434,7 +433,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFiltersWithOrder() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -455,7 +454,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFiltersWithOrder() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -474,7 +473,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionFilterShortCircuitsAction() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -491,7 +490,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResultFilterShortCircuitsResult() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -508,7 +507,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ExceptionFilterShortCircuitsAnotherExceptionFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -525,7 +524,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingFilters_ResultFilter_NotHandledByGlobalExceptionFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -542,7 +541,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingFilters_ActionFilter_HandledByGlobalExceptionFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -559,7 +558,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingFilters_AuthFilter_NotHandledByGlobalExceptionFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -576,7 +575,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowingExceptionFilter_ExceptionFilter_NotHandledByGlobalExceptionFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -593,7 +592,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var input = "{ sampleInt: 10 }"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Json"); @@ -601,7 +600,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Act var response = await client.SendAsync(request); - + // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("10", await response.Content.ReadAsStringAsync()); @@ -618,7 +617,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // There's nothing that can deserialize the body, so the result contains the default // value. - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Json"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs index 0adaa3fb08..c611bd3d35 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FlushPointTest.cs @@ -6,7 +6,6 @@ using System.IO; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using RazorWebSite; using Xunit; @@ -15,15 +14,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class FlushPointTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices("RazorWebSite"); + private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task FlushPointsAreExecutedForPagesWithLayouts() { var waitService = new WaitService(); - var serviceProvider = GetServiceProvider(waitService); - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); var client = server.CreateClient(); // Act @@ -46,9 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FlushPointsAreExecutedForPagesWithoutLayouts() { var waitService = new WaitService(); - var serviceProvider = GetServiceProvider(waitService); - - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); var client = server.CreateClient(); // Act @@ -65,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Assert - 3 Assert.Equal("Inside partial", GetTrimmedString(stream)); waitService.WaitForServer(); - + // Assert - 4 Assert.Equal(@"After flush inside partial
", @@ -83,9 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FlushPointsAreExecutedForPagesWithComponentsPartialsAndSections(string action, string title) { var waitService = new WaitService(); - var serviceProvider = GetServiceProvider(waitService); - - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); var client = server.CreateClient(); // Act @@ -121,9 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var waitService = new WaitService(); - var serviceProvider = GetServiceProvider(waitService); - - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); var client = server.CreateClient(); // Act @@ -144,9 +136,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FlushBeforeCallingLayout() { var waitService = new WaitService(); - var serviceProvider = GetServiceProvider(waitService); - - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(waitService)); var client = server.CreateClient(); var expectedMessage = "A layout page cannot be rendered after 'FlushAsync' has been invoked."; @@ -169,13 +159,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests } } - private IServiceProvider GetServiceProvider(WaitService waitService) - { - var services = new ServiceCollection(); - services.AddInstance(waitService); - return TestHelper.CreateServices("RazorWebSite", services); - } - private string GetTrimmedString(Stream stream) { var buffer = new byte[1024]; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs index 895d15ae72..d608387a4f 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/FormatFilterTest.cs @@ -5,21 +5,20 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class FormatFilterTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(FormatFilterWebSite)); + private const string SiteName = nameof(FormatFilterWebSite); private readonly Action _app = new FormatFilterWebSite.Startup().Configure; [Fact] public async Task FormatFilter_NoExtensionInRequest() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -34,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_Default() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_Optional() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -64,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_Custom() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -79,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_CaseInsensitivity() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -94,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_ExtensionInRequest_NonExistant() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -108,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_And_ProducesFilter_Match() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -123,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_And_ProducesFilter_Conflict() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -137,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormatFilter_And_OverrideProducesFilter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs index 62969e6838..01772713d1 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs @@ -8,7 +8,6 @@ using System.Net.Http; using System.Threading.Tasks; using InlineConstraints; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -16,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class InlineConstraintTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("InlineConstraintsWebSite"); + private const string SiteName = nameof(InlineConstraintsWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -39,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -57,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductById_IntConstraintForOptionalId_IdPresent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -76,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductById_IntConstraintForOptionalId_NoId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -93,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductById_IntConstraintForOptionalId_NotIntId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -107,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByName_AlphaContraintForMandatoryName_ValidName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -125,7 +124,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByName_AlphaContraintForMandatoryName_NonAlphaName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -139,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByName_AlphaContraintForMandatoryName_NoName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -153,7 +152,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByManufacturingDate_DateTimeConstraintForMandatoryDateTime_ValidDateTime() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -173,7 +172,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryName_StringLengthConstraint_ForOptionalCategoryName_ValidCatName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -191,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryName_StringLengthConstraint_ForOptionalCategoryName_InvalidCatName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -206,7 +205,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryName_StringLength1To20Constraint_ForOptionalCategoryName_NoCatName() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -223,7 +222,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryId_Int10To100Constraint_ForMandatoryCatId_ValidId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -241,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryId_Int10To100Constraint_ForMandatoryCatId_InvalidId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -255,7 +254,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByCategoryId_Int10To100Constraint_ForMandatoryCatId_NotIntId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -269,7 +268,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByPrice_FloatContraintForOptionalPrice_Valid() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -287,7 +286,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByPrice_FloatContraintForOptionalPrice_NoPrice() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -304,7 +303,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByManufacturerId_IntMin10Constraint_ForOptionalManufacturerId_Valid() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -322,7 +321,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetProductByManufacturerId_IntMin10Cinstraint_ForOptionalManufacturerId_NoId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -339,7 +338,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetUserByName_RegExConstraint_ForMandatoryName_Valid() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -357,7 +356,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetUserByName_RegExConstraint_ForMandatoryName_InValid() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -371,7 +370,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreById_GuidConstraintForOptionalId_Valid() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -390,7 +389,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreById_GuidConstraintForOptionalId_NoId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -407,7 +406,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreById_GuidConstraintForOptionalId_NotGuidId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -421,7 +420,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_Valid() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -439,7 +438,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_MoreLength() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -453,7 +452,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_LessLength() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -467,7 +466,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GetStoreByLocation_StringLengthConstraint_AlphaConstraint_ForMandatoryLocation_NoAlpha() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -624,7 +623,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedLink) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs index 95060df7d2..63b102eba7 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputFormatterTests.cs @@ -8,7 +8,6 @@ using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -16,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class InputFormatterTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("FormatterWebSite"); + private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; [Fact] public async Task CheckIfXmlInputFormatterIsBeingCalled() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var sampleInputInt = 10; var input = "" + @@ -48,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsSelectedForJsonRequest(string requestContentType) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var sampleInputInt = 10; var input = "{\"SampleInt\":10}"; @@ -80,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var actionName = filterHandlesModelStateError ? "ActionFilterHandlesError" : "ActionHandlesError"; var expectedSource = filterHandlesModelStateError ? "filter" : "action"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{\"SampleInt\":10}"; var content = new StringContent(input); @@ -111,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsModelStateValid_ForValidContentType(string requestContentType, string jsonInput, int expectedSampleIntValue) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent(jsonInput, Encoding.UTF8, requestContentType); @@ -131,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsModelStateInvalid_ForEmptyContentType(string jsonInput) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent(jsonInput, Encoding.UTF8, "application/json"); content.Headers.Clear(); @@ -150,7 +149,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonInputFormatter_IsModelStateValid_ForTransferEncodingChunk(string requestContentType, string jsonInput, int expectedSampleIntValue) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent(jsonInput, Encoding.UTF8, requestContentType); client.DefaultRequestHeaders.TransferEncodingChunked = true; @@ -170,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CustomFormatter_IsSelected_ForSupportedContentTypeAndEncoding(string encoding) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent("Test Content", Encoding.GetEncoding(encoding), "text/plain"); @@ -189,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CustomFormatter_NotSelected_ForUnsupportedContentType(string contentType) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent("Test Content", Encoding.UTF8, contentType); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs index d7d07b961f..33b10d785a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InputObjectValidationTests.cs @@ -9,7 +9,6 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Microsoft.AspNet.WebUtilities; using Newtonsoft.Json; using Xunit; @@ -18,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class InputObjectValidationTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("FormatterWebSite"); + private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; // Parameters: Request Content, Expected status code, Expected model state error message @@ -47,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfObjectIsDeserializedWithoutErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var sampleId = 2; var sampleName = "SampleUser"; @@ -74,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfObjectIsDeserialized_WithErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var sampleId = 0; var sampleName = "user"; @@ -101,7 +100,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfExcludedFieldsAreNotValidated() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent("{\"Alias\":\"xyz\"}", Encoding.UTF8, "application/json"); @@ -118,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ShallowValidation_HappensOnExcluded_ComplexTypeProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var requestData = "{\"Name\":\"Library Manager\", \"Suppliers\": [{\"Name\":\"Contoso Corp\"}]}"; var content = new StringContent(requestData, Encoding.UTF8, "application/json"); @@ -151,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedModelStateErrorMessage) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent(requestContent, Encoding.UTF8, "application/json"); @@ -173,12 +172,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CheckIfExcludedField_IsValidatedForNonBodyBoundModels() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var kvps = new List>(); kvps.Add(new KeyValuePair("Alias", "xyz")); var content = new FormUrlEncodedContent(kvps); - + // Act var response = await client.PostAsync("http://localhost/Validation/GetDeveloperAlias", content); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs index b1ef1e218b..1162e80259 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs @@ -8,7 +8,6 @@ using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -16,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class JsonOutputFormatterTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("FormatterWebSite"); + private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; [Fact] @@ -36,7 +35,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests serializerSettings.Formatting = Formatting.Indented; var expectedBody = JsonConvert.SerializeObject(user, serializerSettings); - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -51,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SerializableErrorIsReturnedInExpectedFormat() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "" + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs index 64e6b527c5..12cf32f9c5 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonResultTest.cs @@ -6,14 +6,13 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class JsonResultTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(BasicWebSite)); + private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; [Theory] @@ -22,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_Conneg(string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/Plain"; @@ -48,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_Conneg_Fails(string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/Plain"; @@ -71,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_Null() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/Null"; @@ -93,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_String() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/String"; @@ -116,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_CustomFormatter_Conneg(string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/CustomFormatter"; @@ -142,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_CustomFormatter_Conneg_Fails(string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/CustomFormatter"; @@ -164,7 +163,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonResult_CustomContentType() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/JsonResult/CustomContentType"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs index 49320dc7de..28f1d6a246 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/LinkGenerationTests.cs @@ -7,14 +7,13 @@ using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class LinkGenerationTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("BasicWebSite"); + private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; // Some tests require comparing the actual response body against an expected response baseline @@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GeneratedLinksWithActionResults_AreRelativeLinks_WhenSetOnLocationHeader(string url) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -48,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GeneratedLinks_AreNotPunyEncoded_WhenGeneratedOnViews() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs index ff19ee4217..c312dd32d8 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingActionSelectionTest.cs @@ -11,7 +11,6 @@ using System.Threading.Tasks; using LoggingWebSite; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Logging; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -19,14 +18,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class LoggingActionSelectionTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(LoggingWebSite)); - private readonly Action _app = new LoggingWebSite.Startup().Configure; - + private const string SiteName = nameof(LoggingWebSite); + private readonly Action _app = new Startup().Configure; + [Fact] public async Task Successful_ActionSelection_Logged() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var requestTraceId = Guid.NewGuid().ToString(); @@ -61,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Failed_ActionSelection_Logged() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var requestTraceId = Guid.NewGuid().ToString(); @@ -95,7 +94,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var logActivities = JsonConvert.DeserializeObject>(responseData); return logActivities.FilterByRequestTraceId(requestTraceId); } - } } #endif diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs index 0fda855a6d..a589c3deb8 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/Logging/LoggingStartupTest.cs @@ -11,7 +11,6 @@ using LoggingWebSite.Controllers; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Logging; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -19,8 +18,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class LoggingStartupTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(LoggingWebSite)); - private readonly Action _app = new LoggingWebSite.Startup().Configure; + private const string SiteName = nameof(LoggingWebSite); + private readonly Action _app = new Startup().Configure; [Fact] public async Task AssemblyValues_LoggedAtStartup() @@ -88,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private async Task> GetLogsByDataTypeAsync() { - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var response = await client.GetStringAsync("http://localhost/logs"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs index 1c3dc5105f..2ca0a68ea4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromFormTest.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ModelBindingWebSite; using ModelBindingWebSite.Controllers; using ModelBindingWebSite.Models; @@ -17,14 +16,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelBindingFromFormTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ModelBindingWebSite)); - private readonly Action _app = new ModelBindingWebSite.Startup().Configure; + private const string SiteName = nameof(ModelBindingWebSite); + private readonly Action _app = new Startup().Configure; [Fact] public async Task FromForm_CustomModelPrefix_ForParameter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateCompany"; @@ -52,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_CustomModelPrefix_ForCollectionParameter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateCompanyFromEmployees"; @@ -78,7 +77,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_CustomModelPrefix_ForProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateCompany"; @@ -104,7 +103,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_CustomModelPrefix_ForCollectionProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/CreateDepartment"; @@ -131,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromForm_NonExistingValueAddsValidationErrors_OnProperty_UsingCustomModelPrefix() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FromFormAttribute_Company/ValidateDepartment"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs index 19db618f5c..9336702ad2 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromHeaderTest.cs @@ -6,15 +6,14 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; -using Xunit; using Newtonsoft.Json; +using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelBindingFromHeaderTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ModelBindingWebSite)); + private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new ModelBindingWebSite.Startup().Configure; // The action that this test hits will echo back the model-bound value @@ -27,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = headerValue; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringParameter"); @@ -51,7 +50,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var title = "How to make really really good soup."; var tags = new string[] { "Cooking", "Recipes", "Awesome" }; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToProperty/CustomName"); @@ -77,7 +76,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var tags = new string[] { "Cooking", "Recipes", "Awesome" }; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToProperty/CustomName"); @@ -100,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_NonExistingHeaderAddsValidationErrors_OnCollectionProperty_CustomName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToProperty/CustomName"); @@ -126,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = "1e331f25-0869-4c87-8a94-64e6e40cb5a0"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringParameter/CustomName"); @@ -154,7 +153,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = headerValue; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringParameter"); @@ -182,7 +181,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string headerValue) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -213,7 +212,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expected = headerValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToStringArrayParameter"); @@ -241,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var title = "How to make really really good soup."; var tags = new string[] { "Cooking", "Recipes", "Awesome" }; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToModel?author=Marvin"); @@ -269,7 +268,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_BindHeader_ToModel_NoValues_ValidationError() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Blog/BindToModel?author=Marvin"); @@ -299,7 +298,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_BindHeader_ToModel_NoValues_InitializedValue_ValidationError() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -331,7 +330,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromHeader_BindHeader_ToModel_NoValues_DefaultValue_NoValidationError() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs index 882234ac6b..9fd6f78fee 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs @@ -4,25 +4,24 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ModelBindingWebSite; +using ModelBindingWebSite.Controllers; using ModelBindingWebSite.Models; using Newtonsoft.Json; using Xunit; -using ModelBindingWebSite.Controllers; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelBindingFromQueryTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ModelBindingWebSite)); + private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task FromQuery_CustomModelPrefix_ForParameter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [FromQuery(Name = "customPrefix")] is used to apply a prefix @@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_CustomModelPrefix_ForCollectionParameter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = @@ -65,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_CustomModelPrefix_ForProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [FromQuery(Name = "EmployeeId")] is used to apply a prefix @@ -88,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_CustomModelPrefix_ForCollectionProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = @@ -111,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromQuery_NonExistingValueAddsValidationErrors_OnProperty_UsingCustomModelPrefix() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs index 9defb1a114..31e02e28b9 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromRouteTest.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ModelBindingWebSite; using ModelBindingWebSite.Models; using Newtonsoft.Json; @@ -16,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelBindingFromRouteTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ModelBindingWebSite)); + private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task FromRoute_CustomModelPrefix_ForParameter() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [FromRoute(Name = "customPrefix")] is used to apply a prefix @@ -43,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromRoute_CustomModelPrefix_ForProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [FromRoute(Name = "EmployeeId")] is used to apply a prefix @@ -64,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FromRoute_NonExistingValueAddsValidationErrors_OnProperty_UsingCustomModelPrefix() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [FromRoute(Name = "TestEmployees")] is used to apply a prefix diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs index 911bc78ae0..57d3d54bb7 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingModelBinderAttributeTest.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ModelBindingWebSite.Models; using Newtonsoft.Json; using Xunit; @@ -13,14 +12,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelBindingModelBinderAttributeTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ModelBindingWebSite)); + private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new ModelBindingWebSite.Startup().Configure; [Fact] public async Task ModelBinderAttribute_CustomModelPrefix() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [ModelBinder(Name = "customPrefix")] is used to apply a prefix @@ -42,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_CustomModelPrefix_OnProperty() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = @@ -65,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_WithPrefixOnParameter(string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // [ModelBinder(Name = "customPrefix")] is used to apply a prefix @@ -90,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_WithBinderOnParameter(string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = @@ -112,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinderAttribute_WithBinderOnEnum() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs index d334f2812d..18d9bf2a49 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs @@ -11,7 +11,6 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ModelBindingWebSite.Models; using ModelBindingWebSite.ViewModels; using Newtonsoft.Json; @@ -21,14 +20,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelBindingTest { - private readonly IServiceProvider _services = TestHelper.CreateServices("ModelBindingWebSite"); + private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new ModelBindingWebSite.Startup().Configure; [Fact] public async Task TypeBasedExclusion_ForBodyAndNonBodyBoundModels() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Make sure the body object gets created with an invalid zip. @@ -50,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelValidation_DoesNotValidate_AnAlreadyValidatedObject() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -70,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CompositeModelBinder_Restricts_ValueProviders(string actionName, string expectedValue) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -95,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_WithAPropertyFromBody() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // the name would be of customer.Department.Name @@ -121,7 +120,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanModelBindServiceToAnArgument() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -135,7 +134,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task CanModelBindServiceToAProperty() { - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -150,7 +149,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task CanModelBindServiceToAProperty_OnBaseType() { - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -166,7 +165,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParametersMarkedWithFromBody_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -184,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParameterAndPropertiesMarkedWithFromBody_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -202,7 +201,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParametersMarkedWith_FromFormAndFromBody_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -220,7 +219,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MultipleParameterAndPropertiesMarkedWith_FromFormAndFromBody_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -238,7 +237,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_MultipleParameters_UsingFromForm() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, @@ -276,7 +275,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_MultipleProperties_UsingFromForm() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, @@ -314,7 +313,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_OnParameters_UsingFromAttributes() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -358,7 +357,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_OnProperties_UsingFromAttributes() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -402,7 +401,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_OnProperties_UsingFromAttributes_WithBody() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Provide all three values, it should bind based on the attribute on the action method. @@ -442,7 +441,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NonExistingModelBinder_ForABinderMetadata_DoesNotRecurseInfinitely() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act & Assert @@ -460,7 +459,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersWithNoValueProviderMetadataUseTheAvailableValueProviders() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -482,7 +481,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersAreAlwaysCreated_IfValuesAreProvidedWithoutModelName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -504,7 +503,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersAreAlwaysCreated_IfValueIsProvidedForModelName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -525,7 +524,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ParametersAreAlwaysCreated_IfNoValuesAreProvided() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -546,7 +545,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreBound_IfTheyAreProvidedByValueProviders() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -568,7 +567,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreBound_IfTheyAreMarkedExplicitly() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -589,7 +588,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreBound_IfTheyArePocoMetadataMarkedTypes() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -614,7 +613,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PropertiesAreNotBound_ByDefault() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -636,7 +635,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanBind_ComplexData_FromRouteData(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -659,7 +658,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindCancellationTokenParameteres() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -674,7 +673,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindCancellationToken_ForProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -690,7 +689,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindingBindsBase64StringsToByteArrays() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -705,7 +704,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBindingBindsEmptyStringsToByteArrays() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -720,7 +719,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinding_LimitsErrorsToMaxErrorCount() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var queryString = string.Join("=&", Enumerable.Range(0, 10).Select(i => "field" + i)); @@ -745,7 +744,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelBinding_ValidatesAllPropertiesInModel() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -763,7 +762,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_Filters_UsingDefaultPropertyFilterProvider_WithExpressions() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -786,7 +785,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_Filters_UsingPropertyFilterProvider_UsingServices() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -809,7 +808,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_Filters_UsingDefaultPropertyFilterProvider_WithPredicate() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -828,7 +827,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_AppliesAtBothParameterAndTypeLevelTogether_BlacklistedAtEitherLevelIsNotBound() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -847,7 +846,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_AppliesAtBothParameterAndTypeLevelTogether_IncludedAtBothLevelsIsBound() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -865,7 +864,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_AppliesAtBothParameterAndTypeLevelTogether_IncludingAtOneLevelIsNotBound() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -884,7 +883,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_BindsUsingParameterPrefix() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -900,7 +899,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_DoesNotUseTypePrefix() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -916,7 +915,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_FallsBackOnEmptyPrefixIfNoParameterPrefixIsProvided() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -932,7 +931,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindAttribute_DoesNotFallBackOnEmptyPrefixIfParameterPrefixIsProvided() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -949,7 +948,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_IncludeTopLevelProperty_IncludesAllSubProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -978,7 +977,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_ChainedPropertyExpression_Throws() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); Expression> expression = model => model.Address.Country; @@ -1000,7 +999,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_FailsToUpdateProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1019,7 +1018,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_IncludeExpression_WorksOnlyAtTopLevel() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1042,7 +1041,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_Validates_ForTopLevelNotIncludedProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1059,7 +1058,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelExcludeSpecific_Properties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1082,7 +1081,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelIncludeSpecific_Properties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1105,7 +1104,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelIncludesAllProperties_ByDefault() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1128,7 +1127,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithJson_ProducesModelStateErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new { @@ -1164,7 +1163,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithJson_DoesPropertyValidationPriorToValidationAtType() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new { @@ -1198,7 +1197,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithJson_BindsBodyAndServices() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var trackingId = Guid.NewGuid().ToString(); var postedContent = new @@ -1235,7 +1234,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task UpdateVehicle_WithXml_BindsBodyServicesAndHeaders() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var trackingId = Guid.NewGuid().ToString(); var postedContent = new VehicleViewModel @@ -1275,7 +1274,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/UpdateDealerVehicle_PopulatesPropertyErrorsInViews.txt"); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var postedContent = new { @@ -1306,7 +1305,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/UpdateDealerVehicle_PopulatesValidationSummary.txt"); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var postedContent = new { @@ -1337,7 +1336,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/UpdateDealerVehicle_UpdateSuccessful.txt"); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var postedContent = new { @@ -1366,7 +1365,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_SingleFile() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadSingle"; var formData = new MultipartFormDataContent("Upload----"); @@ -1387,7 +1386,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_MultipleFiles() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadMultiple"; var formData = new MultipartFormDataContent("Upload----"); @@ -1412,7 +1411,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_MultipleListOfFiles() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadMultipleList"; var formData = new MultipartFormDataContent("Upload----"); @@ -1447,7 +1446,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormFileModelBinder_CanBind_FileInsideModel() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FileUpload/UploadModelWithFile"; var formData = new MultipartFormDataContent("Upload----"); @@ -1472,7 +1471,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModel_ReturnDerivedAndBaseProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1495,7 +1494,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/ModelBindingWebSite.Vehicle.Details.html"); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/vehicles/42"; @@ -1515,7 +1514,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/ModelBindingWebSite.Vehicle.Edit.html"); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/vehicles/42/edit"; @@ -1535,7 +1534,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var expectedContent = await GetType().GetTypeInfo().Assembly.ReadResourceAsStringAsync( "compiler/resources/ModelBindingWebSite.Vehicle.Edit.Invalid.html"); - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/vehicles/42/edit"; var contentDictionary = new Dictionary @@ -1573,7 +1572,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/Home/GetErrorMessage"; @@ -1596,7 +1595,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task OverriddenMetadataProvider_CanChangeAdditionalValues() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/AdditionalValues"; var expectedDictionary = new Dictionary @@ -1619,7 +1618,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task OverriddenMetadataProvider_CanUseAttributesToChangeAdditionalValues() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/GroupNames"; var expectedDictionary = new Dictionary @@ -1646,7 +1645,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelNonGeneric_IncludesAllProperties_CanBind() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1669,7 +1668,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CanBind_FormValues() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnValuesAsList"; var nameValueCollection = new List> @@ -1693,7 +1692,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CanBind_FormValuesWithDuplicateKeys() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnValuesAsList"; var nameValueCollection = new List> @@ -1718,7 +1717,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CannotBind_NonFormValues() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnCollectionCount"; var data = new StringContent("Non form content"); @@ -1737,7 +1736,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task FormCollectionModelBinder_CanBind_FormWithFile() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/FormCollection/ReturnFileContent"; var expectedContent = "Test Content"; @@ -1757,7 +1756,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryUpdateModelNonGenericIncludesAllProperties_ByDefault() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1823,7 +1822,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests IEnumerable expectedModelStateErrorMessages) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new StringContent(input, Encoding.UTF8, "text/json"); @@ -1849,7 +1848,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithCollection() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new Dictionary { @@ -1875,7 +1874,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithCollection_SpecifyingIndex() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new[] { @@ -1901,7 +1900,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithNestedCollection() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new Dictionary { @@ -1936,7 +1935,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithIncorrectlyFormattedNestedCollectionValue() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new Dictionary { @@ -1959,7 +1958,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithNestedCollectionContainingRecursiveRelation() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new Dictionary { @@ -1997,7 +1996,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_WithNestedCollectionContainingRecursiveRelation_WithMalformedValue() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new Dictionary { @@ -2024,7 +2023,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests bool expectedResult) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new List> { @@ -2046,7 +2045,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task BindModelAsync_CheckBoxesList_BindSuccessful() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var content = new List> { diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs index d6defd2631..ee3878dd0f 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelMetadataAttributeTest.cs @@ -7,7 +7,6 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -15,14 +14,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ModelMetadataAttributeTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ValidationWebSite)); + private const string SiteName = nameof(ValidationWebSite); private readonly Action _app = new ValidationWebSite.Startup().Configure; [Fact] public async Task ModelMetaDataTypeAttribute_ValidBaseClass_EmptyResponseBody() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Name\": \"MVC\", \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\",\"Price\": 21, \"ProductDetails\": {\"Detail1\": \"d1\"," + @@ -43,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidPropertiesAndSubPropertiesOnBaseClass_ReturnsErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Price\": 2, \"ProductDetails\": {\"Detail1\": \"d1\"}}"; var content = new StringContent(input, Encoding.UTF8, "application/json"); @@ -69,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidComplexTypePropertyOnBaseClass_ReturnsErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Contact\":\"4255678765\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\",\"Price\": 21 }"; @@ -91,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidClassAttributeOnBaseClass_ReturnsErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"UK\",\"Price\": 21, \"ProductDetails\": {\"Detail1\": \"d1\"," + @@ -115,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_ValidDerivedClass_EmptyResponseBody() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Name\": \"MVC\", \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\", \"Version\":\"2\"," + @@ -136,7 +135,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidPropertiesOnDerivedClass_ReturnsErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Name\": \"MVC\", \"Contact\":\"425-895-9019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"USA\",\"Price\": 2}"; @@ -159,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelMetaDataTypeAttribute_InvalidClassAttributeOnBaseClassProduct_ReturnsErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Contact\":\"4258959019\", \"Category\":\"Technology\"," + "\"CompanyName\":\"Microsoft\", \"Country\":\"UK\",\"Version\":\"2\"," + @@ -177,6 +176,5 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests Assert.Equal(1, json.Count); Assert.Equal("Product must be made in the USA if it is not named.", json["software"]); } - } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs index d0c1b1476c..639ce67d8b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcSampleTests.cs @@ -10,16 +10,17 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class MvcSampleTests { + private const string SiteName = nameof(MvcSample) + "." + nameof(MvcSample.Web); + // Path relative to Mvc\\test\Microsoft.AspNet.Mvc.FunctionalTests - private readonly IServiceProvider _services = - TestHelper.CreateServices("MvcSample.Web", Path.Combine("..", "..", "samples")); + private readonly static string SamplesFolder = Path.Combine("..", "..", "samples"); + private readonly Action _app = new MvcSample.Web.Startup().Configure; [Theory] @@ -37,19 +38,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("/Home/ValidationSummary")] // Home/ValidationSummary.cshtml public async Task Home_Pages_ReturnSuccess(string path) { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync("http://localhost" + path); + // Act + var response = await client.GetAsync("http://localhost" + path); - // Assert - Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - } + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } [Theory] @@ -67,84 +65,72 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("Name=SamplePerson", "false")] public async Task FormUrlEncoded_ReturnsAppropriateResults(string input, string expectedOutput) { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/FormUrlEncoded/IsValidPerson"); - request.Content = new StringContent(input, Encoding.UTF8, "application/x-www-form-urlencoded"); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var client = server.CreateClient(); + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/FormUrlEncoded/IsValidPerson"); + request.Content = new StringContent(input, Encoding.UTF8, "application/x-www-form-urlencoded"); - // Act - var response = await client.SendAsync(request); + // Act + var response = await client.SendAsync(request); - // Assert - Assert.Equal(expectedOutput, await response.Content.ReadAsStringAsync()); - } + // Assert + Assert.Equal(expectedOutput, await response.Content.ReadAsStringAsync()); } [Fact] public async Task FormUrlEncoded_Index_ReturnSuccess() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync("http://localhost/FormUrlEncoded"); + // Act + var response = await client.GetAsync("http://localhost/FormUrlEncoded"); - // Assert - Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - } + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } [Fact] public async Task Home_NotFoundAction_Returns404() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync("http://localhost/Home/NotFound"); + // Act + var response = await client.GetAsync("http://localhost/Home/NotFound"); - // Assert - Assert.NotNull(response); - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); - } + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } [Fact] public async Task Home_CreateUser_ReturnsXmlBasedOnAcceptHeader() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - 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")); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + 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")); - // Act - var response = await client.SendAsync(request); + // Act + var response = await client.SendAsync(request); - // Assert - Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - XmlAssert.Equal("I like playing Football" + - "
My address
13true" + - "
Dependents address
0false" + - "0Dependents name" + - "13.37" + - "My nameSecure stringSoftware Engineer
", - await response.Content.ReadAsStringAsync()); - } + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + XmlAssert.Equal("I like playing Football" + + "
My address
13true" + + "
Dependents address
0false" + + "0Dependents name" + + "13.37" + + "My nameSecure stringSoftware Engineer
", + await response.Content.ReadAsStringAsync()); } [Theory] @@ -153,38 +139,32 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("http://localhost/Filters/NotGrantedClaim", HttpStatusCode.Unauthorized)] public async Task FiltersController_Tests(string url, HttpStatusCode statusCode) { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync(url); + // Act + var response = await client.GetAsync(url); - // Assert - Assert.NotNull(response); - Assert.Equal(statusCode, response.StatusCode); - } + // Assert + Assert.NotNull(response); + Assert.Equal(statusCode, response.StatusCode); } [Fact] public async Task FiltersController_Crash_ThrowsException() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) - { - // Arrange - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); + // Arrange + var server = TestHelper.CreateServer(_app, SiteName, SamplesFolder); + var client = server.CreateClient(); - // Act - var response = await client.GetAsync("http://localhost/Filters/Crash?message=HelloWorld"); + // Act + var response = await client.GetAsync("http://localhost/Filters/Crash?message=HelloWorld"); - // Assert - Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal("Boom HelloWorld", await response.Content.ReadAsStringAsync()); - } + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("Boom HelloWorld", await response.Content.ReadAsStringAsync()); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs index deb39e1839..96ef8f72bb 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs @@ -3,14 +3,13 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class MvcStartupTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("AddServicesWebSite"); + private const string SiteName = nameof(AddServicesWebSite); private readonly Action _app = new AddServicesWebSite.Startup().Configure; [Fact] @@ -22,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests "or 'IApplicationBuilder.UseMvc(...)' in the application startup code."; // Act & Assert - var ex = Assert.Throws(() => TestServer.Create(_provider, _app)); + var ex = Assert.Throws(() => TestHelper.CreateServer(_app, SiteName)); Assert.Equal(expectedMessage, ex.Message); } } diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs index f9b0a81ea8..8636620c3a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcTagHelpersTest.cs @@ -10,11 +10,7 @@ using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using MvcTagHelpersWebSite; using Xunit; @@ -22,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class MvcTagHelpersTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices("MvcTagHelpersWebSite"); + private const string SiteName = nameof(MvcTagHelpersWebSite); private readonly Action _app = new Startup().Configure; private static readonly Assembly _resourcesAssembly = typeof(MvcTagHelpersTest).GetTypeInfo().Assembly; @@ -51,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task MvcTagHelpers_GeneratesExpectedResults(string action, string antiForgeryPath) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -82,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValidationTagHelpers_GeneratesExpectedSpansAndDivs() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Customer.Index.html"); @@ -116,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var assertFile = "compiler/resources/CacheTagHelper_CanCachePortionsOfViewsPartialViewsAndViewComponents.Assert"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); client.DefaultRequestHeaders.Add("Locale", "North"); @@ -165,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_ExpiresContent_BasedOnExpiresParameter() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -189,7 +185,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_UsesVaryByCookie_ToVaryContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -221,7 +217,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_VariesByRoute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -277,7 +273,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_VariesByUserId() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -304,7 +300,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CacheTagHelper_BubblesExpirationOfNestedTagHelpers() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); @@ -349,8 +345,7 @@ Products: Laptops (3)"; // Arrange var newServices = new ServiceCollection(); newServices.ConfigureTagHelpers().ConfigureForm(options => options.GenerateAntiForgeryToken = optionsAntiForgery); - var serviceProvider = TestHelper.CreateServices("MvcTagHelpersWebSite", newServices); - var server = TestServer.Create(serviceProvider, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.Add(newServices)); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -366,10 +361,10 @@ Products: Laptops (3)"; // The host is not important as everything runs in memory and tests are isolated from each other. var response = await client.GetAsync("http://localhost/MvcTagHelper_Home/Form"); var responseContent = await response.Content.ReadAsStringAsync(); - + var forgeryTokens = AntiForgeryTestHelper.RetrieveAntiForgeryTokens(responseContent); expectedContent = string.Format(expectedContent, forgeryTokens.ToArray()); - + // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(expectedMediaType, response.Content.Headers.ContentType); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs index 1523e53045..0001fa51bb 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/OutputFormatterTest.cs @@ -7,14 +7,13 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using ContentNegotiationWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class OutputFormatterTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(ContentNegotiationWebSite)); + private const string SiteName = nameof(ContentNegotiationWebSite); private readonly Action _app = new Startup().Configure; [Theory] @@ -25,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task StringOutputFormatter_ForStringValues_GetsSelectedReturnsTextPlainContentType(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("text/plain;charset=utf-8"); var expectedBody = actionName; @@ -45,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task JsonOutputFormatter_ForNonStringValue_GetsSelected(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8"); @@ -62,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoContentFormatter_ForVoidAndTaskReturnType_GetsSelectedAndWritesResponse(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -84,7 +83,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task NoContentFormatter_ForNullValue_ByDefault_GetsSelectedAndWritesResponse(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -107,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests NoContentFormatter_ForNullValue_AndTreatNullAsNoContentFlagSetToFalse_DoesNotGetSelected(string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs index 41c948f4af..cc00f9753f 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs @@ -9,7 +9,6 @@ using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Razor; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime; using PrecompilationWebSite; @@ -19,15 +18,20 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class PrecompilationTest { + private const string SiteName = nameof(PrecompilationWebSite); private static readonly TimeSpan _cacheDelayInterval = TimeSpan.FromSeconds(1); - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(PrecompilationWebSite)); private readonly Action _app = new Startup().Configure; [Fact] public async Task PrecompiledView_RendersCorrectly() { // Arrange - var applicationEnvironment = _services.GetRequiredService(); + IServiceCollection serviceCollection = null; + var server = TestHelper.CreateServer(_app, SiteName, services => serviceCollection = services); + var client = server.CreateClient(); + + var serviceProvider = serviceCollection.BuildServiceProvider(); + var applicationEnvironment = serviceProvider.GetRequiredService(); var viewsDirectory = Path.Combine(applicationEnvironment.ApplicationBasePath, "Views", "Home"); var layoutContent = File.ReadAllText(Path.Combine(viewsDirectory, "Layout.cshtml")); @@ -35,9 +39,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var viewstartContent = File.ReadAllText(Path.Combine(viewsDirectory, "_ViewStart.cshtml")); var globalContent = File.ReadAllText(Path.Combine(viewsDirectory, "_GlobalImport.cshtml")); - var server = TestServer.Create(_services, _app); - var client = server.CreateClient(); - // We will render a view that writes the fully qualified name of the Assembly containing the type of // the view. If the view is precompiled, this assembly will be PrecompilationWebsite. var assemblyNamePrefix = GetAssemblyNamePrefix(); @@ -169,7 +170,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests @"Value set inside DNXCORE50 " + assemblyNamePrefix; #endif - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -185,10 +186,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = GetAssemblyNamePrefix(); - var server = TestServer.Create(_services, _app); + IServiceCollection serviceCollection = null; + var server = TestHelper.CreateServer(_app, SiteName, services => serviceCollection = services); var client = server.CreateClient(); - var applicationEnvironment = _services.GetRequiredService(); + var serviceProvider = serviceCollection.BuildServiceProvider(); + var applicationEnvironment = serviceProvider.GetRequiredService(); var viewsDirectory = Path.Combine(applicationEnvironment.ApplicationBasePath, "Views", @@ -226,7 +229,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var expected = @"Back to List"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -244,7 +247,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Arrange var assemblyNamePrefix = GetAssemblyNamePrefix(); var expected = @"root-content"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -297,6 +300,5 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public string Index { get; } } - } } diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs index c7aa0c0159..3b2c24c308 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorCompilerCacheTest.cs @@ -5,7 +5,6 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using RazorCompilerCacheWebSite; using Xunit; @@ -13,14 +12,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RazorCompilerCacheTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(RazorCompilerCacheWebSite)); + private const string SiteName = nameof(RazorCompilerCacheWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task CompilerCache_IsNotInitializedUntilFirstViewRequest() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.BaseAddress = new Uri("http://localhost"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs index 7fbd6dbac5..f8ccc14b22 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorEmbeddedViewsTest.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using RazorEmbeddedViewsWebSite; using Xunit; @@ -12,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RazorEmbeddedViewsTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(RazorEmbeddedViewsWebSite)); + private const string SiteName = nameof(RazorEmbeddedViewsWebSite); private readonly Action _app = new Startup().Configure; [Fact] @@ -20,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expectedMessage = "Hello test-user, this is /RazorEmbeddedViews_Home"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -35,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expectedMessage = "Hello admin-user, this is /Restricted/RazorEmbeddedViews_Admin/Login"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var target = "http://localhost/Restricted/RazorEmbeddedViews_Admin/Login?AdminUser=admin-user"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs index 124109e286..e362e3c8a6 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorPageExecutionInstrumentationTest.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using RazorPageExecutionInstrumentationWebSite; using Xunit; @@ -14,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RazorPageExecutionInstrumentationTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(RazorPageExecutionInstrumentationWebSite)); + private const string SiteName = nameof(RazorPageExecutionInstrumentationWebSite); private readonly Action _app = new Startup().Configure; public static IEnumerable InstrumentationData @@ -94,14 +93,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Theory] [MemberData(nameof(InstrumentationData))] - public async Task ViewsAreServedWithoutInstrumentationByDefault(string actionName, - string expected, - IEnumerable> expectedLineMappings) + public async Task ViewsAreServedWithoutInstrumentationByDefault( + string actionName, + string expected, + IEnumerable> expectedLineMappings) { // Arrange var context = new TestPageExecutionContext(); - var services = GetServiceProvider(context); - var server = TestServer.Create(services, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); var client = server.CreateClient(); // Act @@ -114,14 +113,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Theory] [MemberData(nameof(InstrumentationData))] - public async Task ViewsAreInstrumentedWhenPageExecutionListenerFeatureIsEnabled(string actionName, - string expected, - IEnumerable> expectedLineMappings) + public async Task ViewsAreInstrumentedWhenPageExecutionListenerFeatureIsEnabled( + string actionName, + string expected, + IEnumerable> expectedLineMappings) { // Arrange var context = new TestPageExecutionContext(); - var services = GetServiceProvider(context); - var server = TestServer.Create(services, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); var client = server.CreateClient(); client.DefaultRequestHeaders.Add("ENABLE-RAZOR-INSTRUMENTATION", "true"); @@ -135,14 +134,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Theory] [MemberData(nameof(InstrumentationData))] - public async Task ViewsCanSwitchFromRegularToInstrumented(string actionName, - string expected, - IEnumerable> expectedLineMappings) + public async Task ViewsCanSwitchFromRegularToInstrumented( + string actionName, + string expected, + IEnumerable> expectedLineMappings) { // Arrange - 1 var context = new TestPageExecutionContext(); - var services = GetServiceProvider(context); - var server = TestServer.Create(services, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); var client = server.CreateClient(); // Act - 1 @@ -184,8 +183,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests Tuple.Create(35, 8, true), }; var context = new TestPageExecutionContext(); - var services = GetServiceProvider(context); - var server = TestServer.Create(services, _app); + var server = TestHelper.CreateServer(_app, SiteName, services => services.AddInstance(context)); var client = server.CreateClient(); // Act - 1 @@ -203,12 +201,5 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Assert - 2 Assert.Equal(expectedLineMappings, context.Values); } - - private IServiceProvider GetServiceProvider(TestPageExecutionContext pageExecutionContext) - { - var services = new ServiceCollection(); - services.AddInstance(pageExecutionContext); - return TestHelper.CreateServices(nameof(RazorPageExecutionInstrumentationWebSite), services); - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs index 2672907d13..e9161e485b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using RazorWebSite; using Xunit; @@ -13,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public class RazorViewLocationSpecificationTest { private const string BaseUrl = "http://localhost/ViewNameSpecification_Home/"; - private readonly IServiceProvider _provider = TestHelper.CreateServices("RazorWebSite"); + private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; [Theory] @@ -27,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests @" _ViewStart that specifies partial Layout "; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -48,7 +47,7 @@ _ViewStart that specifies partial Layout @" Layout specified in page "; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -67,7 +66,7 @@ Layout specified in page @" Page With Non Partial Layout "; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -89,7 +88,7 @@ Page With Non Partial Layout Non Shared Partial "; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs index 478f2beb85..5f3fbe59b4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RemoteAttributeValidationTest.cs @@ -8,16 +8,15 @@ using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RemoteAttributeValidationTest { + private const string SiteName = nameof(ValidationWebSite); private static readonly Assembly _resourcesAssembly = typeof(RemoteAttributeValidationTest).GetTypeInfo().Assembly; - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(ValidationWebSite)); private readonly Action _app = new ValidationWebSite.Startup().Configure; [Theory] @@ -26,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RemoteAttribute_LeadsToExpectedValidationAttributes(string areaName, string pathSegment) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/ValidationWebSite." + areaName + ".RemoteAttribute_Home.Create.html"); @@ -53,7 +52,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedContent) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost" + pathSegment + "/RemoteAttribute_Verify/IsIdAvailable?UserId1=Joe1&UserId2=Joe2&UserId3=Joe3&UserId4=Joe4"; @@ -77,7 +76,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string expectedContent) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost" + pathSegment + "/RemoteAttribute_Verify/IsIdAvailable"; var contentDictionary = new Dictionary diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs index e52b7ae6fb..d0091b8a73 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs @@ -6,7 +6,6 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -15,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // PER-REQUEST and does not linger around to impact the next request. public class RequestServicesTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(RequestServicesWebSite)); + private const string SiteName = nameof(RequestServicesWebSite); private readonly Action _app = new RequestServicesWebSite.Startup().Configure; [Theory] @@ -28,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequestServices(string url) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act & Assert @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequestServices_TagHelper() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/Other/FromTagHelper"; @@ -74,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequestServices_ActionConstraint() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/Other/FromActionConstraint"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs index ccfcee0155..3dc45c45e4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs @@ -8,14 +8,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RespectBrowserAcceptHeaderTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(FormatterWebSite)); + private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new FormatterWebSite.Startup().Configure; [Theory] @@ -24,10 +23,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllMediaRangeAcceptHeader_FirstFormatterInListWritesResponse(string acceptHeader) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Add("Accept", acceptHeader); - + // Act var response = await client.GetAsync("http://localhost/RespectBrowserAcceptHeader/EmployeeInfo"); @@ -46,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AllMediaRangeAcceptHeader_ProducesAttributeIsHonored(string acceptHeader) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Add("Accept", acceptHeader); var expectedResponseData = "35Jimmy" + ""; - + // Act var response = await client.PostAsync("http://localhost/RespectBrowserAcceptHeader/CreateEmployee", new StringContent(requestData, Encoding.UTF8, "application/xml")); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ResponseCacheTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ResponseCacheTest.cs index 663474aba5..4614fcf1f0 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ResponseCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ResponseCacheTest.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ResponseCacheWebSite; using Xunit; @@ -13,14 +12,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ResponseCacheTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices("ResponseCacheWebSite"); + private const string SiteName = nameof(ResponseCacheWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task ResponseCache_SetsAllHeaders() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsDifferentCacheControlHeaders(string url, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -64,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetsHeadersForAllActionsOfClass() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -87,7 +86,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HeadersSetInActionOverridesTheOnesInClass() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -102,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task HeadersToNotCacheAParticularAction() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -117,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ClassLevelHeadersAreUnsetByActionLevelHeaders() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -137,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task SetsCacheControlPublicByDefault() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -152,7 +151,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowsWhenDurationIsNotSet() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act & Assert @@ -168,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsAllHeaders_FromCacheProfile() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -183,7 +182,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsAllHeaders_ChosesTheRightProfile() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -198,7 +197,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_SetsNoCacheHeaders() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -215,7 +214,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_AddsHeaders() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -232,7 +231,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCache_ModifiesHeaders() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -247,7 +246,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ResponseCacheAttribute_OnAction_OverridesTheValuesOnClass() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs index 18c7112dfc..15ae9f62d3 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoundTripTests.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ModelBindingWebSite; using ModelBindingWebSite.Models; using Newtonsoft.Json; @@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests /// public class RoundTripTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("ModelBindingWebSite"); + private const string SiteName = nameof(ModelBindingWebSite); private readonly Action _app = new Startup().Configure; // Uses the expression p => p.Name @@ -33,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "test-name"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = 40; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -77,7 +76,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = 12; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -98,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RoundTrippedValues_GetsModelBound_ForStringIndexedProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -115,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var expected = "test-nested-name"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs index 63314dd20f..6117b0dcd4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RouteDataTest.cs @@ -9,7 +9,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing.Template; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -17,14 +16,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RouteDataTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(BasicWebSite)); + private const string SiteName = nameof(BasicWebSite); private readonly Action _app = new BasicWebSite.Startup().Configure; [Fact] public async Task RouteData_Routers_ConventionalRoute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteData_Routers_AttributeRoute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -79,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RouteData_DataTokens_FilterCanSetDataTokens() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var response = await client.GetAsync("http://localhost/Routing/DataTokens"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs index a3e8e14f20..1753eb8c18 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs @@ -5,15 +5,15 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RoutingLowercaseUrlTest { + private const string SiteName = nameof(LowercaseUrlsWebSite); + // This website sets the generation of lowercase URLs to true - private readonly IServiceProvider _services = TestHelper.CreateServices("LowercaseUrlsWebSite"); private readonly Action _app = new LowercaseUrlsWebSite.Startup().Configure; [Theory] @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task GenerateLowerCaseUrlsTests(string path, string expectedUrl) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs index 8160aff7cb..a3e15d3761 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingTests.cs @@ -9,7 +9,6 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Routing; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -17,14 +16,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class RoutingTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("RoutingWebSite"); + private const string SiteName = nameof(RoutingWebSite); private readonly Action _app = new RoutingWebSite.Startup().Configure; [Fact] public async Task ConventionRoutedController_ActionIsReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -52,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_ActionIsReachable_WithDefaults() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -80,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_NonActionIsNotReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -94,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_InArea_ActionIsReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -123,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionRoutedController_InArea_ActionBlockedByHttpMethod() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -137,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_IsReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -168,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_MultipleRouteAttributes_WorksWithNameAndOrder(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -197,7 +196,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var url = "http://localhost/api/v2/Maps"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -225,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { // Arrange var url = "http://localhost/api/v1/Maps"; - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -245,7 +244,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string method) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -274,7 +273,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_MultipleHttpAttributesAndTokenReplacement(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedUrl = new Uri(url).AbsolutePath; @@ -308,7 +307,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string method) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedUrl = new Uri(url).AbsolutePath; @@ -324,7 +323,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_IsNotReachableWithTraditionalRoute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -340,7 +339,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_TriedBeforeConventionRouting() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -361,7 +360,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_WithActionParameter_IsReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -395,7 +394,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_IsReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -424,7 +423,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_RouteAttributeOnAction_IsReachable(string method) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var message = new HttpRequestMessage(new HttpMethod(method), "http://localhost/Store/Shop/Orders"); @@ -451,7 +450,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_RouteAttributeOnActionAndController_IsReachable(string method) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var message = new HttpRequestMessage(new HttpMethod(method), "http://localhost/api/Employee/5/Salary"); @@ -473,7 +472,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_RouteAttributeOnActionAndHttpGetOnDifferentAction_ReachesHttpGetAction() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var message = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Store/Shop/Orders"); @@ -498,7 +497,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_WithAcceptVerbs_IsReachable(string verb) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -522,7 +521,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_WithAcceptVerbsAndRouteTemplate_IsReachable(string verb) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -548,7 +547,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_AcceptVerbsAndRouteTemplate_IsReachable(string verb, string path) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedUrl = "/Bank"; @@ -571,7 +570,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_WithCustomHttpAttributes_IsReachable() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -597,7 +596,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ControllerLevelRoute_CombinedWithActionRoute_IsReachable(string verb, string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -623,7 +622,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ActionLevelRouteWithTildeSlash_OverridesControllerLevelRoute() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -648,7 +647,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_OverrideActionOverridesOrderOnController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -673,7 +672,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_OrderOnActionOverridesOrderOnController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -694,7 +693,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkGeneration_OverrideActionOverridesOrderOnController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -709,7 +708,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkGeneration_OrderOnActionOverridesOrderOnController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -724,7 +723,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToSelf() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -747,7 +746,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithAmbientController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -770,7 +769,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToAttributeRoutedController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -794,7 +793,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToConventionalController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -819,7 +818,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithName_WithNameInheritedFromControllerRoute(string method, string actionName) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -843,7 +842,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithName_WithNameOverrridenFromController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -866,7 +865,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_Link_WithNonEmptyActionRouteTemplateAndNoActionRouteName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = LinkFrom("http://localhost") @@ -892,7 +891,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkWithName_WithNonEmptyActionRouteTemplateAndActionRouteName() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -919,7 +918,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_ThowsIfConventionalRouteWithTheSameName(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMessage = "The supplied route name 'DuplicateRoute' is ambiguous and matched more than one route."; @@ -936,7 +935,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_LinkToArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -960,7 +959,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_ImplicitLinkToArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -983,7 +982,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_ExplicitLeaveArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1006,7 +1005,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_ImplicitLeaveArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1029,7 +1028,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_LinkToArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1053,7 +1052,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_ImplicitLinkToArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1076,7 +1075,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_ExplicitLeaveArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1100,7 +1099,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_ImplicitLeaveArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1124,7 +1123,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_LinkToConventionalRoutedActionInArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1149,7 +1148,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_LinkToAttributeRoutedActionInArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1174,7 +1173,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ConventionalRoutedAction_InArea_LinkToAnotherArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1199,7 +1198,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_InArea_LinkToAnotherArea() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1224,7 +1223,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_CanReachSpecificCountry() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1254,7 +1253,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_CannotReachWithoutCountry() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1268,7 +1267,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_GenerateLinkForSpecificCountry() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1288,7 +1287,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_GenerateLinkForFallback() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1308,7 +1307,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ControllerWithCatchAll_GenerateLink_FailsWithoutCountry() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -1333,7 +1332,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRouting_MixedAcceptVerbsAndRoute_Reachable(string path, string verb, string actionName) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(verb), "http://localhost" + path); @@ -1360,7 +1359,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRouting_MixedAcceptVerbsAndRoute_Unreachable(string path, string verb) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(verb), "http://localhost" + path); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs index ec2a387946..e4d8285058 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/SerializableErrorTests.cs @@ -9,14 +9,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class SerializableErrorTests { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite)); + private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; [Theory] @@ -27,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ModelStateErrors_AreSerialized(string acceptHeader) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader)); var expectedXml = "key1-errorThe input was not valid."; @@ -52,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task PostedSerializableError_IsBound(string acceptHeader) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader)); var expectedXml = "key1-errorThe input was not valid."; @@ -76,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task IsReturnedInExpectedFormat(string acceptHeader) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "" + "" + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs index 4614323dfb..d31a865c8f 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/StreamOutputFormatterTest.cs @@ -5,14 +5,13 @@ using System; using System.Threading.Tasks; using FormatterWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class StreamOutputFormatterTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(FormatterWebSite)); + private const string SiteName = nameof(FormatterWebSite); private readonly Action _app = new Startup().Configure; [Theory] @@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task StreamOutputFormatter_ReturnsAppropriateContentAndContentType(string actionName, string contentType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs index 7cc39cd022..2b452d7168 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelperSampleTest.cs @@ -7,7 +7,6 @@ using System.IO; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Microsoft.Framework.Logging; using Xunit; @@ -15,6 +14,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class TagHelperSampleTest { + private const string SiteName = nameof(TagHelperSample) + "." + nameof(TagHelperSample.Web); + + // Path relative to Mvc\\test\Microsoft.AspNet.Mvc.FunctionalTests + private readonly static string SamplesFolder = Path.Combine("..", "..", "samples"); + private static readonly List Paths = new List { string.Empty, @@ -33,33 +37,27 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests }; private readonly ILoggerFactory _loggerFactory = new TestLoggerFactory(); - // Path relative to Mvc\\test\Microsoft.AspNet.Mvc.FunctionalTests - private readonly IServiceProvider _services = - TestHelper.CreateServices("TagHelperSample.Web", Path.Combine("..", "..", "samples")); private readonly Action _app = new TagHelperSample.Web.Startup().Configure; [Fact] public async Task Home_Pages_ReturnSuccess() { - using (TestHelper.ReplaceCallContextServiceLocationService(_services)) + // Arrange + var server = TestHelper.CreateServer(app => _app(app, _loggerFactory), SiteName, SamplesFolder); + var client = server.CreateClient(); + + for (var index = 0; index < Paths.Count; index++) { - // Arrange - var server = TestServer.Create(_services, app => _app(app, _loggerFactory)); - var client = server.CreateClient(); + // Act + var path = Paths[index]; + var response = await client.GetAsync("http://localhost" + path); - for (var index = 0; index < Paths.Count; index++) - { - // Act - var path = Paths[index]; - var response = await client.GetAsync("http://localhost" + path); - - // Assert - Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - } + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } } - + private class TestLoggerFactory : ILoggerFactory { public LogLevel MinimumLevel { get; set; } @@ -68,36 +66,34 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { } - + public ILogger CreateLogger(string name) { return new TestLogger(); } } - + private class TestLogger : ILogger { public bool IsEnabled(LogLevel level) { return false; } - + public IDisposable BeginScope(object scope) { return new TestDisposable(); } - + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) { - } } - + private class TestDisposable : IDisposable { public void Dispose() { - } } } diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs index 8fca5826d5..d3e752ec66 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TagHelpersTest.cs @@ -10,14 +10,13 @@ using System.Reflection; using System.Threading.Tasks; using BasicWebSite; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class TagHelpersTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("TagHelpersWebSite"); + private const string SiteName = nameof(TagHelpersWebSite); private readonly Action _app = new Startup().Configure; // Some tests require comparing the actual response body against an expected response baseline @@ -33,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanRenderViewsWithTagHelpers(string action) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); @@ -88,7 +87,7 @@ page: public async Task TagHelpersAreInheritedFromViewStartPages(string action, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -102,7 +101,7 @@ page: public async Task ViewsWithModelMetadataAttributes_CanRenderForm() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/TagHelpersWebSite.Employee.Create.html"); @@ -120,7 +119,7 @@ page: public async Task ViewsWithModelMetadataAttributes_CanRenderPostedValue() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/TagHelpersWebSite.Employee.Details.AfterCreate.html"); @@ -148,7 +147,7 @@ page: public async Task ViewsWithModelMetadataAttributes_CanHandleInvalidData() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync( "compiler/resources/TagHelpersWebSite.Employee.Create.Invalid.html"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs index 3e491685d1..80900bee06 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs @@ -7,25 +7,24 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class TempDataTest { - private readonly IServiceProvider _services = TestHelper.CreateServices("TempDataWebSite"); + private const string SiteName = nameof(TempDataWebSite); private readonly Action _app = new TempDataWebSite.Startup().Configure; [Fact] public async Task ViewRendersTempData() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var nameValueCollection = new List> { - new KeyValuePair("value", "Foo"), + new KeyValuePair("value", "Foo"), }; var content = new FormUrlEncodedContent(nameValueCollection); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestAssemblyProvider.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TestAssemblyProvider.cs deleted file mode 100644 index cc69db2a66..0000000000 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestAssemblyProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Reflection; - -namespace Microsoft.AspNet.Mvc.FunctionalTests -{ - /// - /// Limits MVC to use a single Assembly for controller discovery. - /// - /// - /// This is a generic type because it needs to instantiated by a service provider to replace - /// a built-in MVC service. - /// - public class TestAssemblyProvider : IAssemblyProvider - { - public TestAssemblyProvider() - { - CandidateAssemblies = new Assembly[] { typeof(T).GetTypeInfo().Assembly }; - } - - public IEnumerable CandidateAssemblies { get; private set; } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestConfigurationProvider.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TestConfigurationProvider.cs deleted file mode 100644 index c5faf9311f..0000000000 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestConfigurationProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Framework.ConfigurationModel; - -namespace Microsoft.AspNet.Mvc.FunctionalTests -{ - public class TestConfigurationProvider : ITestConfigurationProvider - { - public TestConfigurationProvider() - { - Configuration = new Configuration(); - Configuration.Add(new MemoryConfigurationSource()); - } - - public Configuration Configuration { get; set; } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs index e26807a5f5..5afdea682b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TestHelper.cs @@ -2,16 +2,13 @@ // 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 Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.ServiceLookup; using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Mvc.FunctionalTests { @@ -20,128 +17,106 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Path from Mvc\\test\\Microsoft.AspNet.Mvc.FunctionalTests private static readonly string WebsitesDirectoryPath = Path.Combine("..", "WebSites"); - public static IServiceProvider CreateServices(string applicationWebSiteName, IServiceCollection newServices = null) + public static TestServer CreateServer(Action builder, string applicationWebSiteName) { - return CreateServices(applicationWebSiteName, WebsitesDirectoryPath, newServices); + return CreateServer(builder, applicationWebSiteName, applicationPath: null); } - public static IServiceProvider CreateServices(string applicationWebSiteName, string applicationPath, IServiceCollection newServices = null) + public static TestServer CreateServer( + Action builder, + string applicationWebSiteName, + string applicationPath) { - var originalProvider = CallContextServiceLocator.Locator.ServiceProvider; - var appEnvironment = originalProvider.GetRequiredService(); + return CreateServer(builder, applicationWebSiteName, applicationPath, configureServices: null); + } + + public static TestServer CreateServer( + Action builder, + string applicationWebSiteName, + Action configureServices) + { + return CreateServer( + builder, + applicationWebSiteName, + applicationPath: null, + configureServices: configureServices); + } + + private static TestServer CreateServer( + Action builder, + string applicationWebSiteName, + string applicationPath, + Action configureServices) + { + return TestServer.Create( + builder, + services => AddServices(services, applicationWebSiteName, applicationPath, configureServices)); + } + + private static void AddServices( + IServiceCollection services, + string applicationWebSiteName, + string applicationPath, + Action configureServices) + { + applicationPath = applicationPath ?? WebsitesDirectoryPath; + + // Get current IApplicationEnvironment; likely added by the host. + var provider = services.BuildServiceProvider(); + var originalEnvironment = provider.GetRequiredService(); // When an application executes in a regular context, the application base path points to the root // directory where the application is located, for example MvcSample.Web. However, when executing - // an aplication as part of a test, the ApplicationBasePath of the IApplicationEnvironment points + // an application as part of a test, the ApplicationBasePath of the IApplicationEnvironment points // to the root folder of the test project. // To compensate for this, we need to calculate the original path and override the application // environment value so that components like the view engine work properly in the context of the // test. - var appBasePath = CalculateApplicationBasePath(appEnvironment, applicationWebSiteName, applicationPath); + var applicationBasePath = CalculateApplicationBasePath( + originalEnvironment, + applicationWebSiteName, + applicationPath); + var environment = new TestApplicationEnvironment( + originalEnvironment, + applicationBasePath, + applicationWebSiteName); + services.AddInstance(environment); - var services = new ServiceCollection(); - services.AddInstance( - typeof(IApplicationEnvironment), - new TestApplicationEnvironment(appEnvironment, appBasePath, applicationWebSiteName)); + // Injecting a custom assembly provider. Overrides AddMvc() because that uses TryAdd(). + var assemblyProvider = CreateAssemblyProvider(applicationWebSiteName); + services.AddInstance(assemblyProvider); - // Injecting a custom assembly provider via configuration setting. It's not good enough to just - // add the service directly since it's registered by MVC. - var providerType = CreateAssemblyProviderType(applicationWebSiteName); - - var configuration = new TestConfigurationProvider(); - configuration.Configuration.Set( - typeof(IAssemblyProvider).FullName, - providerType.AssemblyQualifiedName); - - services.AddInstance( - typeof(ITestConfigurationProvider), - configuration); - - services.AddInstance( - typeof(ILoggerFactory), - new LoggerFactory()); - - if (newServices != null) + if (configureServices != null) { - services.Add(newServices); + configureServices(services); } - - return BuildFallbackServiceProvider(services, originalProvider); } // Calculate the path relative to the application base path. - public static string CalculateApplicationBasePath(IApplicationEnvironment appEnvironment, - string applicationWebSiteName, string websitePath) + private static string CalculateApplicationBasePath( + IApplicationEnvironment appEnvironment, + string applicationWebSiteName, + string websitePath) { // Mvc/test/WebSites/applicationWebSiteName return Path.GetFullPath( Path.Combine(appEnvironment.ApplicationBasePath, websitePath, applicationWebSiteName)); } - /// - /// Creates a disposable action that replaces the service provider - /// with the passed in service that is switched back on . - /// - /// This is required for config since it uses the static property to get to - /// . - public static IDisposable ReplaceCallContextServiceLocationService(IServiceProvider serviceProvider) - { - return new CallContextProviderAction(serviceProvider); - } - - private static Type CreateAssemblyProviderType(string siteName) + private static IAssemblyProvider CreateAssemblyProvider(string siteName) { // Creates a service type that will limit MVC to only the controllers in the test site. - // We only want this to happen when running in proc. + // We only want this to happen when running in-process. var assembly = Assembly.Load(new AssemblyName(siteName)); - - var providerType = typeof(TestAssemblyProvider<>).MakeGenericType(assembly.GetExportedTypes()[0]); - return providerType; - } - - private sealed class CallContextProviderAction : IDisposable - { - private readonly IServiceProvider _originalProvider; - - public CallContextProviderAction(IServiceProvider provider) + var provider = new FixedSetAssemblyProvider { - _originalProvider = CallContextServiceLocator.Locator.ServiceProvider; - CallContextServiceLocator.Locator.ServiceProvider = provider; - } - - public void Dispose() - { - CallContextServiceLocator.Locator.ServiceProvider = _originalProvider; - } - } - - // TODO: Kill this code - private static IServiceProvider BuildFallbackServiceProvider(IEnumerable services, IServiceProvider fallback) - { - var sc = HostingServices.Create(fallback); - sc.Add(services); - - // Build the manifest - var manifestTypes = services.Where(t => t.ServiceType.GetTypeInfo().GenericTypeParameters.Length == 0 - && t.ServiceType != typeof(IServiceManifest) - && t.ServiceType != typeof(IServiceProvider)) - .Select(t => t.ServiceType).Distinct(); - sc.AddInstance(new ServiceManifest(manifestTypes, fallback.GetRequiredService())); - return sc.BuildServiceProvider(); - } - - private class ServiceManifest : IServiceManifest - { - public ServiceManifest(IEnumerable services, IServiceManifest fallback = null) - { - Services = services; - if (fallback != null) + CandidateAssemblies = { - Services = Services.Concat(fallback.Services).Distinct(); - } - } + assembly, + }, + }; - public IEnumerable Services { get; private set; } + return provider; } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs index da14948530..b048491c34 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/TryValidateModelTest.cs @@ -8,7 +8,6 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -16,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class TryValidateModelTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ValidationWebSite)); + private const string SiteName = nameof(ValidationWebSite); private readonly Action _app = new ValidationWebSite.Startup().Configure; [Fact] public async Task TryValidateModel_ClearParameterValidationError_ReturnsErrorsForInvalidProperties() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "{ \"Price\": 2, \"Contact\": \"acvrdzersaererererfdsfdsfdsfsdf\", "+ "\"ProductDetails\": {\"Detail1\": \"d1\", \"Detail2\": \"d2\", \"Detail3\": \"d3\"}}"; @@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryValidateModel_InvalidTypeOnDerivedModel_ReturnsErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ModelMetadataTypeValidation/TryValidateModelSoftwareViewModelWithPrefix"; @@ -74,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task TryValidateModel_ValidDerivedModel_ReturnsEmptyResponseBody() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/ModelMetadataTypeValidation/TryValidateModelValidModelNoPrefix"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs index 166d49e4ed..dcc1061aad 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ValueProviderTest.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ValueProvidersWebSite; using Xunit; @@ -12,14 +11,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ValueProviderTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(ValueProvidersWebSite)); + private const string SiteName = nameof(ValueProvidersWebSite); private readonly Action _app = new Startup().Configure; [Fact] public async Task ValueProviderFactories_AreVisitedInSequentialOrder_ForValueProviders() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -33,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValueProviderFactories_ReturnsValuesFromQueryValueProvider() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -47,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValueProviderFactories_ReturnsValuesFromRouteValueProvider() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -67,7 +66,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ValueProvider_DeserializesEnumsWithFlags(string url, string expected) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs index 82a371b710..4b1d9a3a3a 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/VersioningTests.cs @@ -7,7 +7,6 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -15,8 +14,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class VersioningTests { - private readonly IServiceProvider _services = TestHelper.CreateServices("VersioningWebSite"); - private readonly Action _app = new VersioningWebSite.Startup().Configure; + private const string SiteName = nameof(VersioningWebSite); + readonly Action _app = new VersioningWebSite.Startup().Configure; [Theory] [InlineData("1")] @@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_WithVersionedRoutes_IsNotAmbiguous(string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task AttributeRoutedAction_WithAmbiguousVersionedRoutes_CanBeDisambiguatedUsingOrder(string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var query = "?version=" + version; var message = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/Addresses/All" + query); @@ -74,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheSameController_WithNoVersionSpecified() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -97,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheSameController_WithVersionSpecified() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -118,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheSameController() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -139,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheSameController_WithVersionSpecified() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -168,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachOtherVersionOperations_OnTheSameController(string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -194,7 +193,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanNotReachOtherVersionOperations_OnTheSameController_WithNoVersionSpecified() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -221,7 +220,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -249,7 +248,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanNotReachOtherVersionOperationsWithParameters_OnTheSameController_WithNoVersionSpecified(string method) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -270,7 +269,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanUseOrderToDisambiguate_OverlappingVersionRanges(string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -294,7 +293,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_OverlappingVersionRanges_FallsBackToLowerOrderAction(string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -318,7 +317,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheOriginalController_WithNoVersionSpecified(string method, string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -341,7 +340,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1Operations_OnTheOriginalController_WithVersionSpecified(string method, string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -365,7 +364,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheOriginalController(string method, string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -388,7 +387,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachV1OperationsWithParameters_OnTheOriginalController_WithVersionSpecified(string method, string action) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -409,7 +408,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanReachOtherVersionOperationsWithParameters_OnTheV2Controller() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -433,7 +432,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanHaveTwoRoutesWithVersionOnTheUrl_OnTheSameAction(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -456,7 +455,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanHaveTwoRoutesWithVersionOnTheUrl_OnDifferentActions(string url, string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -479,7 +478,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanHaveTwoRoutesWithVersionOnTheUrl_OnDifferentActions_WithInlineConstraint(string url, string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -505,7 +504,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanProvideVersioningInformation_UsingPlainActionConstraint(string url, string query, string actionName) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -526,7 +525,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_ConstraintOrder_IsRespected() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -547,7 +546,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_CanUseConstraintOrder_ToChangeSelectedAction() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -570,7 +569,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task VersionedApi_MultipleVersionsUsingAttributeRouting_OnTheSameMethod(string version) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var path = "/" + version + "/Vouchers?version=" + version; @@ -591,7 +590,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests Assert.Equal(path, actualUrl); } - // See TestResponseGenerator in RoutingWebSite for the code that generates this data. private class RoutingResult { public string[] ExpectedUrls { get; set; } diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs index e713f507fb..a59f2b2995 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewComponentTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using ViewComponentWebSite; using Xunit; @@ -13,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ViewComponentTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("ViewComponentWebSite"); + private const string SiteName = nameof(ViewComponentWebSite); private readonly Action _app = new Startup().Configure; public static IEnumerable ViewViewComponents_AreRenderedCorrectlyData @@ -42,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [MemberData(nameof(ViewViewComponents_AreRenderedCorrectlyData))] public async Task ViewViewComponents_AreRenderedCorrectly(string actionName, string expected) { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ViewComponents_SupportsValueType() { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -74,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("http://localhost/Home/ViewComponentWithEnumerableModelUsingUnion", "Union")] public async Task ViewComponents_SupportsEnumerableModel(string url, string linqQueryType) { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -93,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [InlineData("ViewComponentWebSite.Namespace2.SameName")] public async Task ViewComponents_FullName(string name) { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -106,7 +105,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests [Fact] public async Task ViewComponents_ShortNameUsedForViewLookup() { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var name = "ViewComponentWebSite.Integer"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs index 106491c880..55e827b8be 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using RazorWebSite; using Xunit; @@ -14,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ViewEngineTests { - private readonly IServiceProvider _provider = TestHelper.CreateServices("RazorWebSite"); + private const string SiteName = nameof(RazorWebSite); private readonly Action _app = new Startup().Configure; public static IEnumerable RazorView_ExecutesPageAndLayoutData @@ -63,7 +62,7 @@ ViewWithNestedLayout-Content [MemberData(nameof(RazorView_ExecutesPageAndLayoutData))] public async Task RazorView_ExecutesPageAndLayout(string actionName, string expected) { - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -84,7 +83,7 @@ ViewWithNestedLayout-Content "", "", "test-value"); - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -99,7 +98,7 @@ ViewWithNestedLayout-Content { // Arrange var expected = "HelloWorld"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -118,7 +117,7 @@ ViewWithNestedLayout-Content partial-content component-content"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -154,7 +153,7 @@ component-content"; public async Task RazorViewEngine_UsesViewExpandersForViewsAndPartials(string value, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -182,7 +181,7 @@ component-content"; public async Task ViewLocationExpanders_PassesInIsPartialToViewLocationExpanderContext(string action, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -247,7 +246,7 @@ ViewWithNestedLayout-Content public async Task RazorViewEngine_RendersPartialViews(string actionName, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -266,7 +265,7 @@ ViewWithNestedLayout-Content "", "~/Views/NestedViewStarts/NestedViewStarts/Layout.cshtml", "index-content"); - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -302,7 +301,7 @@ View With Layout public async Task RazorViewEngine_UsesExpandersForLayouts(string value, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -320,7 +319,7 @@ View With Layout var expected = @"Hello Controller-Person Hello Controller-Person"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var target = "http://localhost/NestedGlobalImports"; @@ -342,7 +341,7 @@ Page Content ViewComponent With Title Component With Layout"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -357,7 +356,7 @@ Component With Layout"; { // Arrange var expected = @"ViewComponent With ViewStart"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -372,7 +371,7 @@ Component With Layout"; { // Arrange var expected = "Partial that does not specify Layout"; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -391,7 +390,7 @@ Component With Layout"; Partial that specifies Layout Partial that does not specify Layout "; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -411,7 +410,7 @@ Partial that specifies Layout Partial that does not specify Layout "; - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -427,7 +426,7 @@ Partial that does not specify Layout // Arrange var expected = await GetType().GetTypeInfo().Assembly .ReadResourceAsStringAsync("compiler/resources/ViewEngineController.ViewWithPaths.txt"); - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs index 537834aa27..0a24e7cdd7 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionResultTest.cs @@ -5,21 +5,20 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class WebApiCompatShimActionResultTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(WebApiCompatShimWebSite)); + private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; [Fact] public async Task ApiController_BadRequest() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -33,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_BadRequestMessage() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_BadRequestModelState() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"product.Name\":[\"Name is required.\"]}}"; @@ -67,7 +66,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Conflict() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -81,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Content() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -97,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedRelative() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -114,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedAbsolute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -131,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedQualified() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -148,7 +147,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedUri() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -165,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreatedAtRoute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -182,7 +181,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_InternalServerError() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -196,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_InternalServerErrorException() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -212,7 +211,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Json() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -228,7 +227,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_JsonSettings() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @@ -249,7 +248,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_JsonSettingsEncoding() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @@ -271,7 +270,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_NotFound() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -285,7 +284,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Ok() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -299,7 +298,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_OkContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -315,7 +314,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RedirectString() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -330,7 +329,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RedirectUri() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -345,7 +344,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ResponseMessage() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -360,7 +359,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_StatusCode() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs index a0ea027f79..672f0389c2 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimActionSelectionTest.cs @@ -6,7 +6,6 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -14,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class WebApiCompatShimActionSelectionTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(WebApiCompatShimWebSite)); + private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; [Theory] @@ -28,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_UnnamedAction(string httpMethod, string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -57,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction(string httpMethod, string actionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -79,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction_MismatchedVerb() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -97,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_UnnamedAction_DefaultVerbIsPost_Success() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -119,7 +118,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction_DefaultVerbIsPost_Success() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -141,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_UnnamedAction_DefaultVerbIsPost_VerbMismatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -159,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromPrefix_NamedAction_DefaultVerbIsPost_VerbMismatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -177,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_UnnamedAction_Success() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -199,7 +198,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_NamedAction_Success() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -221,7 +220,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_UnnamedAction_VerbMismatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -239,7 +238,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_TakesHttpMethodFromMethodName_NotActionName_NamedAction_VerbMismatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -257,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_UnnamedAction_Success() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -279,7 +278,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_NamedAction_Success() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -301,7 +300,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_UnnamedAction_VerbMismatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -319,7 +318,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebAPIConvention_HttpMethodOverride_NamedAction_VerbMismatch() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -368,7 +367,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_OverloadedAction_WithUnnamedAction(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -395,7 +394,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_OverloadedAction_NonIdRouteParameter(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -419,7 +418,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_OverloadedAction_Parameter_Casing(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -446,7 +445,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RouteWithActionName(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -473,7 +472,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RouteWithActionName_Casing(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -498,7 +497,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RouteWithoutActionName(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -526,7 +525,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_ModelBindingParameterAttribute_AreAppliedWhenSelectingActions(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -550,7 +549,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_ActionsThatHaveSubsetOfRouteParameters_AreConsideredForSelection(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); @@ -572,7 +571,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_RequestToAmbiguousAction_OnDefaultRoute() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod("POST"), "http://localhost/api/Admin/Test?name=mario"); @@ -593,7 +592,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task LegacyActionSelection_SelectAction_ReturnsActionDescriptor_ForEnumParameterOverloads(string httpMethod, string requestUrl, string expectedActionName) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/" + requestUrl); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs index fc33fda938..82c684dd70 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs @@ -11,7 +11,6 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using System.Web.Http; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -19,14 +18,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class WebApiCompatShimBasicTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(WebApiCompatShimWebSite)); + private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; [Fact] public async Task ApiController_Activates_HttpContextAndUser() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Activates_UrlHelper() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -64,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task Options_SetsDefaultFormatters() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = new string[] @@ -91,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_WithStatusCode() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -108,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_WithResponse() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -126,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_EnsureGlobalHttpresponseExceptionActionFilter_IsInvoked() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -144,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ActionThrowsHttpResponseException_EnsureGlobalFilterConvention_IsApplied() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -163,7 +162,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CanValidateCustomObjectWithPrefix_Fails() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -180,7 +179,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CanValidateCustomObject_IsSuccessFul() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -194,7 +193,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CanValidateCustomObject_Fails() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -210,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RequestProperty() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @@ -232,7 +231,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_RequestParameter() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @@ -254,7 +253,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ResponseReturned() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @@ -280,7 +279,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ExplicitChunkedEncoding_IsIgnored() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expected = @@ -325,7 +324,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_Conneg(string accept, string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -350,7 +349,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_HardcodedMediaType(string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -375,7 +374,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_Conneg_Error(string accept, string mediaType) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -398,7 +397,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_CreateResponse_HardcodedFormatter() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( @@ -424,7 +423,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebApiRouting_AccessMvcController(string url, HttpStatusCode expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); @@ -442,7 +441,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task WebApiRouting_AccessWebApiController(string url, HttpStatusCode expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); @@ -458,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_ByteArrayContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedBody = "Hello from ByteArrayContent!!"; @@ -478,7 +477,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_StreamContent() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedBody = "This content is from a file"; @@ -502,7 +501,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_PushStreamContent(string action, string expectedBody) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); // Act @@ -521,7 +520,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_Returns_PushStreamContentWithCustomHeaders() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var expectedBody = "Hello from PushStreamContent with custom headers!!"; var multipleValues = new[] { "value1", "value2" }; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs index 9f00d1d6a9..065ff8900b 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/WebApiCompatShimParameterBindingTest.cs @@ -8,7 +8,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; @@ -16,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class WebApiCompatShimParameterBindingTest { - private readonly IServiceProvider _provider = TestHelper.CreateServices(nameof(WebApiCompatShimWebSite)); + private const string SiteName = nameof(WebApiCompatShimWebSite); private readonly Action _app = new WebApiCompatShimWebSite.Startup().Configure; [Theory] @@ -25,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_Default_ReadsFromUrl(string url) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); @@ -43,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_Default_DoesNotReadFormData() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PostByIdDefault"; @@ -68,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_ModelBinder_ReadsFromUrl(string url) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); @@ -86,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_ModelBinder_ReadsFromFormData() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PostByIdModelBinder"; @@ -111,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_FromQuery_ReadsFromQueryNotRouteData(string url, string expected) { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); @@ -129,7 +128,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_SimpleParameter_FromQuery_DoesNotReadFormData() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PostByIdFromQuery"; @@ -152,7 +151,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ComplexParameter_Default_ReadsFromBody() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PutEmployeeDefault"; @@ -177,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_ComplexParameter_ModelBinder_ReadsFormAndUrl() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PutEmployeeModelBinder/5"; @@ -201,7 +200,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ApiController_TwoParameters_DefaultSources() { // Arrange - var server = TestServer.Create(_provider, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var url = "http://localhost/api/Blog/Employees/PutEmployeeBothDefault?name=Name_Override"; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs index a28f8337a3..208df85dd3 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs @@ -5,18 +5,16 @@ using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; -using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class XmlDataContractSerializerFormattersWrappingTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite)); + private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; [Theory] @@ -25,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_ValueTypes(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -48,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -71,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_Empty(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -93,7 +91,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_NullInstance(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -115,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -139,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_Empty(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -161,7 +159,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_NullInstance(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); @@ -181,7 +179,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_IEnumerableOf_SerializableErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/IEnumerable/SerializableErrors"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs")); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs index c89f682409..e05b3e48bd 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs @@ -12,7 +12,6 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using XmlFormattersWebSite; using Xunit; @@ -20,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class XmlDataContractSerializerInputFormatterTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite)); + private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new Startup().Configure; private readonly string errorMessageFormat = string.Format( "{{1}}:{0} does not recognize '{1}', so instead use '{2}' with '{3}' set to '{4}' for value " + @@ -35,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowsOnInvalidInput_AndAddsToModelState() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "Not a valid xml document"; var content = new StringContent(input, Encoding.UTF8, "application/xml-dcs"); @@ -59,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RequiredDataIsProvided_AndModelIsBound_AndHasRequiredAttributeValidationErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml-dcs")); var input = " _app = new FormatterWebSite.Startup().Configure; - public XmlOutputFormatterTests() - { - _services = TestHelper.CreateServices("FormatterWebSite"); - } - [Fact] public async Task XmlDataContractSerializerOutputFormatterIsCalled() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); 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")); @@ -46,7 +40,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerOutputFormatterIsCalled() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); 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")); @@ -65,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerFailsAndDataContractSerializerIsCalled() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/DataContractSerializer/GetPerson?name=HelloWorld"); @@ -86,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerOutputFormatter_WhenDerivedClassIsReturned() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/XmlSerializer/GetDerivedDummyClass?sampleInput=10"); @@ -107,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlDataContractSerializerOutputFormatter_WhenDerivedClassIsReturned() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/Home/GetDerivedDummyClass?sampleInput=10"); @@ -128,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task XmlSerializerFormatter_DoesNotWriteDictionaryObjects() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/XmlSerializer/GetDictionary"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs index 7ef52a7cf1..42c3720747 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs @@ -5,18 +5,16 @@ using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; -using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Xml; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class XmlSerializerFormattersWrappingTest { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite)); + private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; [Theory] @@ -25,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_ValueTypes(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -48,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -71,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_NullInstance(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -93,7 +91,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_NonWrappedTypes_Empty(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -115,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -139,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_Empty(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -162,7 +160,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_WrappedTypes_NullInstance(string url) { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); @@ -183,7 +181,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task CanWrite_IEnumerableOf_SerializableErrors() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/IEnumerable/SerializableErrors"); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser")); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs index e2d57e16ec..3e5c827879 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs @@ -7,21 +7,20 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class XmlSerializerInputFormatterTests { - private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite)); + private const string SiteName = nameof(XmlFormattersWebSite); private readonly Action _app = new XmlFormattersWebSite.Startup().Configure; [Fact] public async Task CheckIfXmlSerializerInputFormatterIsCalled() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var sampleInputInt = 10; var input = "" + @@ -41,7 +40,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task ThrowsOnInvalidInput_AndAddsToModelState() { // Arrange - var server = TestServer.Create(_services, _app); + var server = TestHelper.CreateServer(_app, SiteName); var client = server.CreateClient(); var input = "Not a valid xml document"; var content = new StringContent(input, Encoding.UTF8, "application/xml-xmlser"); diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json index 7b0f1cc286..cc1ace1e46 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json @@ -27,7 +27,7 @@ "FormatFilterWebSite": "1.0.0-*", "FormatterWebSite": "1.0.0", "InlineConstraintsWebSite": "1.0.0", - "LoggingWebSite": "1.0.0", + "LoggingWebSite": "1.0.0", "LowercaseUrlsWebSite": "1.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0", diff --git a/test/Microsoft.AspNet.Mvc.Test/MvcServiceCollectionExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.Test/MvcServiceCollectionExtensionsTest.cs index 576ae6b74e..42e1fdace5 100644 --- a/test/Microsoft.AspNet.Mvc.Test/MvcServiceCollectionExtensionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.Test/MvcServiceCollectionExtensionsTest.cs @@ -46,44 +46,6 @@ namespace Microsoft.AspNet.Mvc Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime); } - [Fact] - public void WithControllersAsServices_UsesConfigurationIfSpecified() - { - // Arrange - var collection = new ServiceCollection(); - var controllerTypes = new[] { typeof(ControllerTypeA), typeof(TypeBController) }; - var configuration = new Configuration(); - configuration.Add(new MemoryConfigurationSource()); - configuration.Set(typeof(IControllerActivator).FullName, - typeof(CustomActivator).AssemblyQualifiedName); - configuration.Set(typeof(IControllerTypeProvider).FullName, - typeof(CustomTypeProvider).AssemblyQualifiedName); - - // Act - MvcServiceCollectionExtensions.WithControllersAsServices(collection, - controllerTypes, - configuration); - - // Assert - var services = collection.ToList(); - Assert.Equal(4, services.Count); - Assert.Equal(typeof(ControllerTypeA), services[0].ServiceType); - Assert.Equal(typeof(ControllerTypeA), services[0].ImplementationType); - Assert.Equal(ServiceLifetime.Transient, services[0].Lifetime); - - Assert.Equal(typeof(TypeBController), services[1].ServiceType); - Assert.Equal(typeof(TypeBController), services[1].ImplementationType); - Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime); - - Assert.Equal(typeof(IControllerActivator), services[2].ServiceType); - Assert.Equal(typeof(CustomActivator), services[2].ImplementationType); - Assert.Equal(ServiceLifetime.Transient, services[2].Lifetime); - - Assert.Equal(typeof(IControllerTypeProvider), services[3].ServiceType); - Assert.Equal(typeof(CustomTypeProvider), services[3].ImplementationType); - Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime); - } - [Fact] public void WithControllersAsServices_ScansControllersFromSpecifiedAssemblies() { diff --git a/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/BuilderExtensions.cs b/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/BuilderExtensions.cs index 909b8b9a85..b66f98bd9d 100644 --- a/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/BuilderExtensions.cs +++ b/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/BuilderExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.TestConfiguration; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; @@ -10,15 +9,13 @@ namespace Microsoft.AspNet.Builder { public static class BuilderExtensions { - public static Configuration GetTestConfiguration(this IApplicationBuilder app) + public static IConfiguration GetTestConfiguration(this IApplicationBuilder app) { // Unconditionally place CultureReplacerMiddleware as early as possible in the pipeline. app.UseMiddleware(); - var configurationProvider = app.ApplicationServices.GetService(); - var configuration = configurationProvider == null - ? new Configuration() - : configurationProvider.Configuration; + // Until we update all references, return a useful configuration. + var configuration = app.ApplicationServices.GetService() ?? new Configuration(); return configuration; } diff --git a/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/ITestConfigurationProvider.cs b/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/ITestConfigurationProvider.cs deleted file mode 100644 index d11f5de0c8..0000000000 --- a/test/WebSites/Microsoft.AspNet.Mvc.TestConfiguration/ITestConfigurationProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Framework.ConfigurationModel; - -namespace Microsoft.AspNet.Mvc -{ - public interface ITestConfigurationProvider - { - Configuration Configuration { get; } - } -} \ No newline at end of file diff --git a/test/WebSites/PrecompilationWebSite/Compiler/Preprocess/RazorPreCompilation.cs b/test/WebSites/PrecompilationWebSite/Compiler/Preprocess/RazorPreCompilation.cs index b50971c39a..8b7b9d7822 100644 --- a/test/WebSites/PrecompilationWebSite/Compiler/Preprocess/RazorPreCompilation.cs +++ b/test/WebSites/PrecompilationWebSite/Compiler/Preprocess/RazorPreCompilation.cs @@ -2,98 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; -using System.Runtime.Versioning; using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Hosting; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; namespace PrecompilationWebSite { public class RazorPreCompilation : RazorPreCompileModule { - public RazorPreCompilation(IServiceProvider provider) : base(ReplaceProvider(provider)) + public RazorPreCompilation(IServiceProvider provider) + : base(provider) { } - - // We need to construct an IApplicationEnvironment with a base path that that matches this - // website, in order to find the razor files. This is needed because we don't have a guarantee that - // the base path of the current app is this site (ex: functional tests). - public static IServiceProvider ReplaceProvider(IServiceProvider provider) - { - var originalEnvironment = provider.GetService(); - - var libraryManager = provider.GetService(); - var info = libraryManager.GetLibraryInformation("PrecompilationWebSite"); - var directory = Path.GetDirectoryName(info.Path); - - var precompilationApplicationEnvironment = new PrecompilationApplicationEnvironment( - originalEnvironment, - directory); - - var collection = HostingServices.Create(provider); - collection.AddInstance(precompilationApplicationEnvironment); - - return new DelegatingServiceProvider(provider, collection.BuildServiceProvider()); - } - - private class PrecompilationApplicationEnvironment : IApplicationEnvironment - { - private readonly IApplicationEnvironment _originalApplicationEnvironment; - private readonly string _applicationBasePath; - - public PrecompilationApplicationEnvironment(IApplicationEnvironment original, string appBasePath) - { - _originalApplicationEnvironment = original; - _applicationBasePath = appBasePath; - } - - public string ApplicationName - { - get { return _originalApplicationEnvironment.ApplicationName; } - } - - public string Version - { - get { return _originalApplicationEnvironment.Version; } - } - - public string ApplicationBasePath - { - get { return _applicationBasePath; } - } - - public string Configuration - { - get - { - return _originalApplicationEnvironment.Configuration; - } - } - - public FrameworkName RuntimeFramework - { - get { return _originalApplicationEnvironment.RuntimeFramework; } - } - } - - private class DelegatingServiceProvider : IServiceProvider - { - private readonly IServiceProvider _fallback; - private readonly IServiceProvider _services; - - public DelegatingServiceProvider(IServiceProvider fallback, IServiceProvider services) - { - _fallback = fallback; - _services = services; - } - - public object GetService(Type serviceType) - { - return _services.GetService(serviceType) ?? _fallback.GetService(serviceType); - } - } - } } \ No newline at end of file