This repository was archived by the owner on Dec 19, 2018. It is now read-only.
File tree 3 files changed +56
-2
lines changed
src/Microsoft.AspNet.Hosting.Interfaces
test/Microsoft.AspNet.Hosting.Tests 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 @@ -116,6 +116,32 @@ public void WebRootCanBeResolvedFromTheProjectJson()
116
116
Assert . True ( env . WebRootFileProvider . GetFileInfo ( "TextFile.txt" ) . Exists ) ;
117
117
}
118
118
119
+ [ Fact ]
120
+ public void Validate_Environment_Name ( )
121
+ {
122
+ var services = HostingServices . Create ( ) . BuildServiceProvider ( ) ;
123
+ var env = services . GetRequiredService < IHostingEnvironment > ( ) ;
124
+ Assert . Equal ( "Development" , env . EnvironmentName ) ;
125
+
126
+ var config = new Configuration ( )
127
+ . AddCommandLine ( new string [ ] { "--ASPNET_ENV" , "Overridden_Environment" } ) ;
128
+
129
+ services = HostingServices . Create ( fallbackServices : null , configuration : config )
130
+ . BuildServiceProvider ( ) ;
131
+
132
+ env = services . GetRequiredService < IHostingEnvironment > ( ) ;
133
+ Assert . Equal ( "Overridden_Environment" , env . EnvironmentName ) ;
134
+ }
135
+
136
+ [ Fact ]
137
+ public void IsEnvironment_Extension_Is_Case_Insensitive ( )
138
+ {
139
+ var services = HostingServices . Create ( ) . BuildServiceProvider ( ) ;
140
+ var env = services . GetRequiredService < IHostingEnvironment > ( ) ;
141
+ Assert . True ( env . IsEnvironment ( "Development" ) ) ;
142
+ Assert . True ( env . IsEnvironment ( "developMent" ) ) ;
143
+ }
144
+
119
145
public void Initialize ( IApplicationBuilder builder )
120
146
{
121
147
You can’t perform that action at this time.
0 commit comments