This repository was archived by the owner on Dec 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +56
-2
lines changed
src/Microsoft.AspNet.Hosting.Interfaces
test/Microsoft.AspNet.Hosting.Tests Expand file tree Collapse file tree 3 files changed +56
-2
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2
+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+ using System ;
5
+ using Microsoft . Framework . Internal ;
6
+
7
+ namespace Microsoft . AspNet . Hosting
8
+ {
9
+ public static class HostingEnvironmentExtensions
10
+ {
11
+ /// <summary>
12
+ /// Compares the current hosting environment name against the specified value.
13
+ /// </summary>
14
+ /// <param name="hostingEnvironment">An instance of <see cref="IHostingEnvironment"/> service.</param>
15
+ /// <param name="environmentName">Environment name to validate against.</param>
16
+ /// <returns>True if the specified name is same as the current environment.</returns>
17
+ public static bool IsEnvironment (
18
+ [ NotNull ] this IHostingEnvironment hostingEnvironment ,
19
+ [ NotNull ] string environmentName )
20
+ {
21
+ return string . Equals (
22
+ hostingEnvironment . EnvironmentName ,
23
+ environmentName ,
24
+ StringComparison . OrdinalIgnoreCase ) ;
25
+ }
26
+ }
27
+ }
Original file line number Diff line number Diff line change 4
4
"Microsoft.AspNet.Http" : " 1.0.0-*" ,
5
5
"Microsoft.AspNet.FeatureModel" : " 1.0.0-*" ,
6
6
"Microsoft.AspNet.FileProviders.Interfaces" : " 1.0.0-*" ,
7
- "Microsoft.Framework.ConfigurationModel" : " 1.0.0-*"
7
+ "Microsoft.Framework.ConfigurationModel" : " 1.0.0-*" ,
8
+ "Microsoft.Framework.NotNullAttribute.Internal" : { "type" : " build" , "version" : " 1.0.0-*" }
8
9
},
9
10
"frameworks" : {
10
11
"dnx451" : {},
11
12
"dnxcore50" : {}
12
13
}
13
- }
14
+ }
Original file line number Diff line number Diff line change @@ -63,6 +63,32 @@ public void WebRootCanBeResolvedFromTheProjectJson()
63
63
Assert . True ( env . WebRootFileProvider . GetFileInfo ( "TextFile.txt" ) . Exists ) ;
64
64
}
65
65
66
+ [ Fact ]
67
+ public void Validate_Environment_Name ( )
68
+ {
69
+ var services = HostingServices . Create ( ) . BuildServiceProvider ( ) ;
70
+ var env = services . GetRequiredService < IHostingEnvironment > ( ) ;
71
+ Assert . Equal ( "Development" , env . EnvironmentName ) ;
72
+
73
+ var config = new Configuration ( )
74
+ . AddCommandLine ( new string [ ] { "--ASPNET_ENV" , "Overridden_Environment" } ) ;
75
+
76
+ services = HostingServices . Create ( fallbackServices : null , configuration : config )
77
+ . BuildServiceProvider ( ) ;
78
+
79
+ env = services . GetRequiredService < IHostingEnvironment > ( ) ;
80
+ Assert . Equal ( "Overridden_Environment" , env . EnvironmentName ) ;
81
+ }
82
+
83
+ [ Fact ]
84
+ public void IsEnvironment_Extension_Is_Case_Insensitive ( )
85
+ {
86
+ var services = HostingServices . Create ( ) . BuildServiceProvider ( ) ;
87
+ var env = services . GetRequiredService < IHostingEnvironment > ( ) ;
88
+ Assert . True ( env . IsEnvironment ( "Development" ) ) ;
89
+ Assert . True ( env . IsEnvironment ( "developMent" ) ) ;
90
+ }
91
+
66
92
public void Initialize ( IApplicationBuilder builder )
67
93
{
68
94
You can’t perform that action at this time.
0 commit comments