Shift 'Development' & 'Production' constants into 'EnvironmentName' class

Make 'EnvironmentName' static

Change constants -> static readonly fields

Remove trailing spaces
This commit is contained in:
Hisham Abdullah Bin Ateya 2015-05-18 08:01:00 +03:00
parent b9e930038b
commit 8e39bf4ffb
4 changed files with 16 additions and 10 deletions

View File

@ -0,0 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNet.Hosting
{
public static class EnvironmentName
{
public static readonly string Development = "Development";
public static readonly string Production = "Production";
}
}

View File

@ -9,9 +9,6 @@ namespace Microsoft.AspNet.Hosting
{
public static class HostingEnvironmentExtensions
{
private const string DevelopmentEnvironmentName = "Development";
private const string ProductionEnvironmentName = "Production";
/// <summary>
/// Checks if the current hosting environment name is development.
/// </summary>
@ -19,7 +16,7 @@ namespace Microsoft.AspNet.Hosting
/// <returns>True if the environment name is Development, otherwise false.</returns>
public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment)
{
return hostingEnvironment.IsEnvironment(DevelopmentEnvironmentName);
return hostingEnvironment.IsEnvironment(EnvironmentName.Development);
}
/// <summary>
@ -29,7 +26,7 @@ namespace Microsoft.AspNet.Hosting
/// <returns>True if the environment name is Production, otherwise false.</returns>
public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment)
{
return hostingEnvironment.IsEnvironment(ProductionEnvironmentName);
return hostingEnvironment.IsEnvironment(EnvironmentName.Production);
}
/// <summary>

View File

@ -8,9 +8,7 @@ namespace Microsoft.AspNet.Hosting
{
public class HostingEnvironment : IHostingEnvironment
{
internal const string DefaultEnvironmentName = "Production";
public string EnvironmentName { get; set; } = DefaultEnvironmentName;
public string EnvironmentName { get; set; } = Microsoft.AspNet.Hosting.EnvironmentName.Production;
public string WebRootPath { get; set; }

View File

@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Hosting
{
var engine = CreateBuilder().Build();
var env = engine.ApplicationServices.GetRequiredService<IHostingEnvironment>();
Assert.Equal("Production", env.EnvironmentName);
Assert.Equal(EnvironmentName.Production, env.EnvironmentName);
}
[Fact]
@ -199,7 +199,7 @@ namespace Microsoft.AspNet.Hosting
using (engine.Start())
{
var env = engine.ApplicationServices.GetRequiredService<IHostingEnvironment>();
Assert.True(env.IsEnvironment("Production"));
Assert.True(env.IsEnvironment(EnvironmentName.Production));
Assert.True(env.IsEnvironment("producTion"));
}
}