Minor clean up related to formatting

This commit is contained in:
Kiran Challa 2015-09-23 14:30:17 -07:00
parent 21c043d788
commit d89747927e
6 changed files with 123 additions and 70 deletions

View File

@ -27,16 +27,17 @@ namespace MusicStore
{
_runtimeEnvironment = runtimeEnvironment;
}
public bool IsRunningOnWindows
{
get
{
if (_isWindows == null)
{
_isWindows = _runtimeEnvironment.OperatingSystem.Equals("Windows", StringComparison.OrdinalIgnoreCase);
_isWindows = _runtimeEnvironment.OperatingSystem.Equals(
"Windows", StringComparison.OrdinalIgnoreCase);
}
return _isWindows.Value;
}
}
@ -65,7 +66,7 @@ namespace MusicStore
try
{
int productType;
if (GetProductInfo(osVersion.Major, osVersion.Minor, 0,0, out productType))
if (GetProductInfo(osVersion.Major, osVersion.Minor, 0, 0, out productType))
{
_isNano = productType == PRODUCT_NANO_SERVER;
}
@ -76,7 +77,7 @@ namespace MusicStore
}
catch
{
// If the API call fails, the API set is not there which means
// If the API call fails, the API set is not there which means
// that we are definetely not running on Nano
_isNano = false;
}

View File

@ -1,16 +1,15 @@
using System;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Dnx.Runtime;
using MusicStore.Components;
using MusicStore.Models;
@ -20,13 +19,15 @@ namespace MusicStore
{
private readonly Platform _platform;
public Startup(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
public Startup(IApplicationEnvironment applicationEnvironment, IRuntimeEnvironment runtimeEnvironment)
{
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(env.ApplicationBasePath)
// Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1'
// is found in both the registered sources, then the later source will win. By this way a Local config
// can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(applicationEnvironment.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
//All environment variables in the process's context flow in as configuration values.
.AddEnvironmentVariables();
Configuration = builder.Build();
_platform = new Platform(runtimeEnvironment);
@ -38,7 +39,9 @@ namespace MusicStore
{
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
var useInMemoryStore = !_platform.IsRunningOnWindows || _platform.IsRunningOnMono || _platform.IsRunningOnNanoServer;
var useInMemoryStore = !_platform.IsRunningOnWindows
|| _platform.IsRunningOnMono
|| _platform.IsRunningOnNanoServer;
// Add EF services to the services container
if (useInMemoryStore)
@ -64,7 +67,8 @@ namespace MusicStore
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.AddCors(options =>
services.Configure<CorsOptions>(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
@ -88,7 +92,8 @@ namespace MusicStore
// Configure Auth
services.AddAuthorization(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
options.AddPolicy(
"ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}
@ -172,7 +177,8 @@ namespace MusicStore
options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8";
});
// The MicrosoftAccount service has restrictions that prevent the use of http://localhost:5001/ for test applications.
// The MicrosoftAccount service has restrictions that prevent the use of
// http://localhost:5001/ for test applications.
// As such, here is how to change this sample to uses http://ktesting.com:5001/ instead.
// Edit the Project.json file and replace http://localhost:5001/ with http://ktesting.com:5001/.

View File

@ -2,15 +2,15 @@ using System;
using System.Security.Claims;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Http.Features;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Dnx.Runtime;
using Microsoft.Net.Http.Server;
using MusicStore.Components;
using MusicStore.Models;
@ -20,25 +20,31 @@ namespace MusicStore
/// <summary>
/// To make runtime to load an environment based startup class, specify the environment by the following ways:
/// 1. Drop a Microsoft.AspNet.Hosting.ini file in the wwwroot folder
/// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'. For example: To load a Startup class named
/// 'StartupNtlmAuthentication' the value of the env should be 'NtlmAuthentication' (eg. ASPNET_ENV=NtlmAuthentication). Runtime adds a 'Startup' prefix to this and loads 'StartupNtlmAuthentication'.
/// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'.
/// For example: To load a Startup class named 'StartupNtlmAuthentication' the value of the env should be
/// 'NtlmAuthentication' (eg. ASPNET_ENV=NtlmAuthentication). Runtime adds a 'Startup' prefix to this and
/// loads 'StartupNtlmAuthentication'.
/// If no environment name is specified the default startup class loaded is 'Startup'.
///
/// Alternative ways to specify environment are:
/// 1. Set the environment variable named SET ASPNET_ENV=NtlmAuthentication
/// 2. For selfhost based servers pass in a command line variable named --env with this value. Eg:
/// "commands": {
/// "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002 --ASPNET_ENV NtlmAuthentication",
/// "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener
/// --server.urls http://localhost:5002 --ASPNET_ENV NtlmAuthentication",
/// },
/// </summary>
public class StartupNtlmAuthentication
{
public StartupNtlmAuthentication(IApplicationEnvironment env)
public StartupNtlmAuthentication(IApplicationEnvironment applicationEnvironment)
{
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(env.ApplicationBasePath)
// Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1'
// is found in both the registered sources, then the later source will win. By this way a Local config
// can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(applicationEnvironment.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
//All environment variables in the process's context flow in as configuration values.
.AddEnvironmentVariables();
Configuration = builder.Build();
}
@ -54,7 +60,7 @@ namespace MusicStore
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddCors(options =>
services.Configure<CorsOptions>(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
@ -78,7 +84,8 @@ namespace MusicStore
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
options.AddPolicy(
"ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}
@ -88,12 +95,14 @@ namespace MusicStore
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
// Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
// Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the
// request pipeline.
// Note: Not recommended for production.
app.UseDeveloperExceptionPage();
// Set up NTLM authentication for WebListener like below.
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM.
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or
// modify the applicationHost.config to enable NTLM.
var listener = app.ServerFeatures.Get<WebListener>();
if (listener != null)
{
@ -109,10 +118,12 @@ namespace MusicStore
app.Use(async (context, next) =>
{
//Who will get admin access? For demo sake I'm listing the currently logged on user as the application administrator. But this can be changed to suit the needs.
// Who will get admin access? For demo sake I'm listing the currently logged on user as the application
// administrator. But this can be changed to suit the needs.
var identity = (ClaimsIdentity)context.User.Identity;
if (context.User.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" + Environment.GetEnvironmentVariable("USERNAME"))
if (context.User.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\"
+ Environment.GetEnvironmentVariable("USERNAME"))
{
identity.AddClaim(new Claim("ManageStore", "Allowed"));
}

View File

@ -1,15 +1,13 @@
using System;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Dnx.Runtime;
using MusicStore.Components;
using MusicStore.Models;
@ -18,14 +16,18 @@ namespace MusicStore
/// <summary>
/// To make runtime to load an environment based startup class, specify the environment by the following ways:
/// 1. Drop a Microsoft.AspNet.Hosting.ini file in the wwwroot folder
/// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'. For example: To load a Startup class named
/// 'StartupOpenIdConnect' the value of the env should be 'OpenIdConnect' (eg. ASPNET_ENV=OpenIdConnect). Runtime adds a 'Startup' prefix to this and loads 'StartupOpenIdConnect'.
/// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'.
/// For example: To load a Startup class named 'StartupOpenIdConnect' the value of the env should be
/// 'OpenIdConnect' (eg. ASPNET_ENV=OpenIdConnect). Runtime adds a 'Startup' prefix to this
/// and loads 'StartupOpenIdConnect'.
///
/// If no environment name is specified the default startup class loaded is 'Startup'.
/// Alternative ways to specify environment are:
/// 1. Set the environment variable named SET ASPNET_ENV=OpenIdConnect
/// 2. For selfhost based servers pass in a command line variable named --env with this value. Eg:
/// "commands": {
/// "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002 --ASPNET_ENV OpenIdConnect",
/// "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener
/// --server.urls http://localhost:5002 --ASPNET_ENV OpenIdConnect",
/// },
/// </summary>
public class StartupOpenIdConnect
@ -34,11 +36,13 @@ namespace MusicStore
public StartupOpenIdConnect(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
{
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
// Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1'
// is found in both the registered sources, then the later source will win. By this way a Local config can
// be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(env.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
//All environment variables in the process's context flow in as configuration values.
.AddEnvironmentVariables();
Configuration = builder.Build();
_platform = new Platform(runtimeEnvironment);
@ -97,7 +101,8 @@ namespace MusicStore
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
options.AddPolicy(
"ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}

View File

@ -14,57 +14,84 @@ namespace E2ETests
public class PublishAndRunTests_OnX64
{
// https://github.com/aspnet/MusicStore/issues/487
// [ConditionalTheory, Trait("E2Etests", "E2Etests")]
[ConditionalTheory, Trait("E2Etests", "E2Etests")]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5025/", false)]
[InlineData(
ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5025/", false)]
//https://github.com/aspnet/KRuntime/issues/642
//[InlineData(ServerType.Helios, RuntimeFlavor.CoreClr, RuntimeArchitecture.amd64, "http://localhost:5026/")]
public async Task Publish_And_Run_Tests_On_AMD64(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl, bool noSource)
public async Task Publish_And_Run_Tests_On_AMD64(
ServerType serverType,
RuntimeFlavor runtimeFlavor,
RuntimeArchitecture architecture,
string applicationBaseUrl,
bool noSource)
{
var testRunner = new PublishAndRunTests();
await testRunner.Publish_And_Run_Tests(serverType, runtimeFlavor, architecture, applicationBaseUrl, noSource);
await testRunner.Publish_And_Run_Tests(
serverType, runtimeFlavor, architecture, applicationBaseUrl, noSource);
}
}
public class PublishAndRunTests_OnX86
{
// https://github.com/aspnet/MusicStore/issues/487
// [ConditionalTheory, Trait("E2Etests", "E2Etests")]
[ConditionalTheory, Trait("E2Etests", "E2Etests")]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
//[InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5027/", false)]
//[InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5028/", true)]
public async Task Publish_And_Run_Tests_On_X86(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl, bool noSource)
//[InlineData(
// ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5027/", false)]
//[InlineData(
// ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5028/", true)]
public async Task Publish_And_Run_Tests_On_X86(
ServerType serverType,
RuntimeFlavor runtimeFlavor,
RuntimeArchitecture architecture,
string applicationBaseUrl,
bool noSource)
{
var testRunner = new PublishAndRunTests();
await testRunner.Publish_And_Run_Tests(serverType, runtimeFlavor, architecture, applicationBaseUrl, noSource);
await testRunner.Publish_And_Run_Tests(
serverType, runtimeFlavor, architecture, applicationBaseUrl, noSource);
}
// https://github.com/aspnet/MusicStore/issues/487
// [ConditionalTheory, Trait("E2Etests", "E2Etests")]
[ConditionalTheory, Trait("E2Etests", "E2Etests")]
[FrameworkSkipCondition(RuntimeFrameworks.CLR | RuntimeFrameworks.CoreCLR)]
[InlineData(ServerType.Kestrel, RuntimeFlavor.Mono, RuntimeArchitecture.x86, "http://localhost:5029/", false)]
[InlineData(ServerType.Kestrel, RuntimeFlavor.Mono, RuntimeArchitecture.x86, "http://localhost:5030/", true)]
public async Task Publish_And_Run_Tests_On_Mono(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl, bool noSource)
public async Task Publish_And_Run_Tests_On_Mono(
ServerType serverType,
RuntimeFlavor runtimeFlavor,
RuntimeArchitecture architecture,
string applicationBaseUrl,
bool noSource)
{
var testRunner = new PublishAndRunTests();
await testRunner.Publish_And_Run_Tests(serverType, runtimeFlavor, architecture, applicationBaseUrl, noSource);
await testRunner.Publish_And_Run_Tests(
serverType, runtimeFlavor, architecture, applicationBaseUrl, noSource);
}
}
public class PublishAndRunTests
{
public async Task Publish_And_Run_Tests(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl, bool noSource)
public async Task Publish_And_Run_Tests(
ServerType serverType,
RuntimeFlavor runtimeFlavor,
RuntimeArchitecture architecture,
string applicationBaseUrl,
bool noSource)
{
var logger = new LoggerFactory()
.AddConsole()
.CreateLogger(string.Format("Publish:{0}:{1}:{2}:{3}", serverType, runtimeFlavor, architecture, noSource));
.CreateLogger($"Publish:{serverType}:{runtimeFlavor}:{architecture}:{noSource}");
using (logger.BeginScope("Publish_And_Run_Tests"))
{
var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);
var connectionString = string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName);
var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(), serverType, runtimeFlavor, architecture)
var deploymentParameters = new DeploymentParameters(
Helpers.GetApplicationPath(), serverType, runtimeFlavor, architecture)
{
ApplicationBaseUriHint = applicationBaseUrl,
PublishApplicationBeforeDeployment = true,
@ -89,9 +116,11 @@ namespace E2ETests
{
var deploymentResult = deployer.Deploy();
var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
var httpClient = new HttpClient(httpClientHandler);
httpClient.BaseAddress = new Uri(deploymentResult.ApplicationBaseUri);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
// Request to base address and check if various parts of the body are rendered &
// measure the cold startup time.
// Add retry logic since tests are flaky on mono due to connection issues
var response = await RetryHelper.RetryRequest(async () =>
{
@ -106,7 +135,8 @@ namespace E2ETests
if (serverType != ServerType.IISExpress)
{
if (Directory.GetFiles(deploymentParameters.ApplicationPath, "*.cmd", SearchOption.TopDirectoryOnly).Length > 0)
if (Directory.GetFiles(
deploymentParameters.ApplicationPath, "*.cmd", SearchOption.TopDirectoryOnly).Length > 0)
{
throw new Exception("publishExclude parameter values are not honored.");
}

View File

@ -5,15 +5,15 @@
"commands": {
"test": "xunit.runner.aspnet"
},
"dependencies": {
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.Testing": "1.0.0-*",
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
"Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"dependencies": {
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.Testing": "1.0.0-*",
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
"Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {