diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs index 0f0207564a..272e747446 100644 --- a/samples/SampleStartups/StartupFullControl.cs +++ b/samples/SampleStartups/StartupFullControl.cs @@ -26,7 +26,7 @@ namespace SampleStartups .UseFakeServer() .UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory .UseUrls("http://*:1000", "https://*:902") - .UseEnvironment("Development") + .UseEnvironment(EnvironmentName.Development) .UseWebRoot("public") .ConfigureServices(services => { diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs index ab20880160..ad3269859d 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -12,10 +12,10 @@ namespace Microsoft.AspNetCore.Hosting public static class HostingEnvironmentExtensions { /// - /// Checks if the current hosting environment name is "Development". + /// Checks if the current hosting environment name is . /// /// An instance of . - /// True if the environment name is "Development", otherwise false. + /// True if the environment name is , otherwise false. public static bool IsDevelopment(this IHostingEnvironment hostingEnvironment) { if (hostingEnvironment == null) @@ -27,10 +27,10 @@ namespace Microsoft.AspNetCore.Hosting } /// - /// Checks if the current hosting environment name is "Staging". + /// Checks if the current hosting environment name is . /// /// An instance of . - /// True if the environment name is "Staging", otherwise false. + /// True if the environment name is , otherwise false. public static bool IsStaging(this IHostingEnvironment hostingEnvironment) { if (hostingEnvironment == null) @@ -42,10 +42,10 @@ namespace Microsoft.AspNetCore.Hosting } /// - /// Checks if the current hosting environment name is "Production". + /// Checks if the current hosting environment name is . /// /// An instance of . - /// True if the environment name is "Production", otherwise false. + /// True if the environment name is , otherwise false. public static bool IsProduction(this IHostingEnvironment hostingEnvironment) { if (hostingEnvironment == null) diff --git a/src/Microsoft.AspNetCore.TestHost/TestServer.cs b/src/Microsoft.AspNetCore.TestHost/TestServer.cs index 7ae6066eb5..af65de3556 100644 --- a/src/Microsoft.AspNetCore.TestHost/TestServer.cs +++ b/src/Microsoft.AspNetCore.TestHost/TestServer.cs @@ -15,7 +15,6 @@ namespace Microsoft.AspNetCore.TestHost { public class TestServer : IServer { - private const string DefaultEnvironmentName = "Development"; private const string ServerName = nameof(TestServer); private IWebHost _hostInstance; private bool _disposed = false; diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs index 974e5ffaa2..62e8f5bda9 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs @@ -195,7 +195,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests serviceCollection.AddSingleton, MyContainerFactory>(); var services = serviceCollection.BuildServiceProvider(); - var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), "Development"); + var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), EnvironmentName.Development); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -211,7 +211,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests serviceCollection.AddSingleton, MyContainerFactory>(); var services = serviceCollection.BuildServiceProvider(); - var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartupBaseClass), "Development"); + var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartupBaseClass), EnvironmentName.Development); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -227,13 +227,13 @@ namespace Microsoft.AspNetCore.Hosting.Tests serviceCollection.AddSingleton, MyContainerFactory>(); var services = serviceCollection.BuildServiceProvider(); - var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartupEnvironmentBased), "Production"); + var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartupEnvironmentBased), EnvironmentName.Production); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); Assert.IsType(typeof(MyContainer), app.ApplicationServices); - Assert.Equal(((MyContainer)app.ApplicationServices).Environment, "Production"); + Assert.Equal(((MyContainer)app.ApplicationServices).Environment, EnvironmentName.Production); } [Fact] @@ -242,7 +242,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests var serviceCollection = new ServiceCollection(); var services = serviceCollection.BuildServiceProvider(); - var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), "Development"); + var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), EnvironmentName.Development); Assert.Throws(() => startup.ConfigureServicesDelegate(serviceCollection)); } @@ -253,7 +253,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests var serviceCollection = new ServiceCollection(); var services = serviceCollection.BuildServiceProvider(); - Assert.Throws(() => StartupLoader.LoadMethods(services, typeof(MyContainerStartupBaseClass), "Development")); + Assert.Throws(() => StartupLoader.LoadMethods(services, typeof(MyContainerStartupBaseClass), EnvironmentName.Development)); } [Fact] @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests serviceCollection.AddSingleton, MyContainerFactory>(); var services = serviceCollection.BuildServiceProvider(); - Assert.Throws(() => StartupLoader.LoadMethods(services, typeof(MyContainerStartupWithOverloads), "Development")); + Assert.Throws(() => StartupLoader.LoadMethods(services, typeof(MyContainerStartupWithOverloads), EnvironmentName.Development)); } [Fact] @@ -273,7 +273,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests serviceCollection.AddSingleton, MyBadContainerFactory>(); var services = serviceCollection.BuildServiceProvider(); - var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), "Development"); + var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), EnvironmentName.Development); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -314,12 +314,12 @@ namespace Microsoft.AspNetCore.Hosting.Tests public void ConfigureDevelopmentContainer(MyContainer container) { - container.Environment = "Development"; + container.Environment = EnvironmentName.Development; } public void ConfigureProductionContainer(MyContainer container) { - container.Environment = "Production"; + container.Environment = EnvironmentName.Production; } public void Configure(IApplicationBuilder app) diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs index 5f4291d75e..b678501370 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests { "webroot", "wwwroot"}, { "applicationName", "MyProjectReference"}, { "startupAssembly", "MyProjectReference" }, - { "environment", "Development"}, + { "environment", EnvironmentName.Development}, { "detailederrors", "true"}, { "captureStartupErrors", "true" } }; @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests Assert.Equal("wwwroot", config.WebRoot); Assert.Equal("MyProjectReference", config.ApplicationName); Assert.Equal("MyProjectReference", config.StartupAssembly); - Assert.Equal("Development", config.Environment); + Assert.Equal(EnvironmentName.Development, config.Environment); Assert.True(config.CaptureStartupErrors); Assert.True(config.DetailedErrors); } @@ -36,10 +36,10 @@ namespace Microsoft.AspNetCore.Hosting.Tests [Fact] public void ReadsOldEnvKey() { - var parameters = new Dictionary() { { "ENVIRONMENT", "Development" } }; + var parameters = new Dictionary() { { "ENVIRONMENT", EnvironmentName.Development } }; var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); - Assert.Equal("Development", config.Environment); + Assert.Equal(EnvironmentName.Development, config.Environment); } [Theory] diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs index 10c3f8dabf..66f751aac4 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs @@ -662,7 +662,7 @@ namespace Microsoft.AspNetCore.Hosting { var vals = new Dictionary { - { "Environment", "Staging" } + { "Environment", EnvironmentName.Staging } }; var builder = new ConfigurationBuilder() @@ -672,7 +672,7 @@ namespace Microsoft.AspNetCore.Hosting using (var host = CreateBuilder(config).UseFakeServer().Build()) { var env = host.Services.GetService(); - Assert.Equal("Staging", env.EnvironmentName); + Assert.Equal(EnvironmentName.Staging, env.EnvironmentName); } }