From 5ae536fe0ad1893603853109079d249cfbcd30be Mon Sep 17 00:00:00 2001 From: Praburaj Date: Thu, 20 Nov 2014 16:04:48 -0800 Subject: [PATCH] Some fixes 1. Updating some startup classes like templates 2. Update a test that runs on mono with right CLR. --- src/MusicStore/Mocks/StartupSocialTesting.cs | 35 +++++++++----------- src/MusicStore/Startup.cs | 23 +++++-------- src/MusicStore/StartupNtlmAuthentication.cs | 29 ++++++++-------- src/MusicStore/config.json | 5 +++ test/E2ETests/PublishAndRunTests.cs | 2 +- test/E2ETests/SmokeTests.cs | 2 ++ 6 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/MusicStore/Mocks/StartupSocialTesting.cs b/src/MusicStore/Mocks/StartupSocialTesting.cs index 8159a7ac97..07db11b13a 100644 --- a/src/MusicStore/Mocks/StartupSocialTesting.cs +++ b/src/MusicStore/Mocks/StartupSocialTesting.cs @@ -4,8 +4,6 @@ using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Http; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Routing; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.Data.Entity; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using MusicStore.Models; @@ -13,7 +11,6 @@ using Microsoft.AspNet.Security.Facebook; using Microsoft.AspNet.Security.Google; using Microsoft.AspNet.Security.Twitter; using Microsoft.AspNet.Security.MicrosoftAccount; -using Microsoft.AspNet.Security; using Microsoft.Framework.Cache.Memory; using MusicStore.Mocks.Common; using MusicStore.Mocks.Facebook; @@ -27,46 +24,44 @@ namespace MusicStore { public class StartupSocialTesting { - public void Configure(IApplicationBuilder app) + public StartupSocialTesting() { - Console.WriteLine("Social Testing mode..."); //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 configuration = new Configuration() + Configuration = new Configuration() .AddJsonFile("config.json") .AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values. + } + public IConfiguration Configuration { get; private set; } + + public void Configure(IApplicationBuilder app) + { //Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline. //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseServices(services => { - //If this type is present - we're on mono - var runningOnMono = Type.GetType("Mono.Runtime") != null; + //Sql client not available on mono + var useInMemoryStore = Type.GetType("Mono.Runtime") != null; // Add EF services to the services container - if (runningOnMono) + if (useInMemoryStore) { - services.AddEntityFramework() + services.AddEntityFramework(Configuration) .AddInMemoryStore() - .AddDbContext(options => - { - options.UseInMemoryStore(); - }); ; + .AddDbContext(); } else { - services.AddEntityFramework() + services.AddEntityFramework(Configuration) .AddSqlServer() - .AddDbContext(options => - { - options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString")); - }); + .AddDbContext(); } // Add Identity services to the services container - services.AddDefaultIdentity(configuration); + services.AddDefaultIdentity(Configuration); services.ConfigureFacebookAuthentication(options => { diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index c2709ded33..d4cefc9a67 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Routing; -using Microsoft.Data.Entity; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using MusicStore.Models; @@ -26,31 +25,25 @@ namespace MusicStore public void ConfigureServices(IServiceCollection services) { - //If this type is present - we're on mono - var runningOnMono = Type.GetType("Mono.Runtime") != null; + //Sql client not available on mono + var useInMemoryStore = Type.GetType("Mono.Runtime") != null; // Add EF services to the services container - if (runningOnMono) + if (useInMemoryStore) { - services.AddEntityFramework() + services.AddEntityFramework(Configuration) .AddInMemoryStore() - .AddDbContext(options => - { - options.UseInMemoryStore(); - }); ; + .AddDbContext(); } else { - services.AddEntityFramework() + services.AddEntityFramework(Configuration) .AddSqlServer() - .AddDbContext(options => - { - options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")); - }); + .AddDbContext(); } // Add Identity services to the services container - services.AddDefaultIdentity(Configuration.GetSubKey("Identity")); + services.AddDefaultIdentity(Configuration); services.ConfigureFacebookAuthentication(options => { diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index 8b45e9be93..e6d36a9209 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -2,7 +2,6 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Routing; -using Microsoft.Data.Entity; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using MusicStore.Models; @@ -30,6 +29,17 @@ namespace MusicStore /// public class StartupNtlmAuthentication { + public StartupNtlmAuthentication() + { + //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. + Configuration = new Configuration() + .AddJsonFile("config.json") + .AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values. + } + + public IConfiguration Configuration { get; private set; } + public void Configure(IApplicationBuilder app) { //Set up NTLM authentication for WebListener like below. @@ -56,12 +66,6 @@ namespace MusicStore await next.Invoke(); }); - //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 configuration = new Configuration() - .AddJsonFile("config.json") - .AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values. - //Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline. //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. app.UseErrorPage(ErrorPageOptions.ShowAll); @@ -69,15 +73,12 @@ namespace MusicStore app.UseServices(services => { // Add EF services to the services container - services.AddEntityFramework() + services.AddEntityFramework(Configuration) .AddSqlServer() - .AddDbContext(options => - { - options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString")); - }); + .AddDbContext(); // Add Identity services to the services container - services.AddDefaultIdentity(configuration.GetSubKey("Identity")); + services.AddDefaultIdentity(Configuration); // Add MVC services to the services container services.AddMvc(); @@ -117,4 +118,4 @@ namespace MusicStore SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait(); } } -} +} \ No newline at end of file diff --git a/src/MusicStore/config.json b/src/MusicStore/config.json index 97c59012c5..8913079e11 100644 --- a/src/MusicStore/config.json +++ b/src/MusicStore/config.json @@ -5,5 +5,10 @@ "DefaultConnection": { "Connectionstring": "Server=(localdb)\\MSSQLLocalDB;Database=MusicStore;Trusted_Connection=True;MultipleActiveResultSets=true" } + }, + "EntityFramework": { + "MusicStoreContext": { + "ConnectionStringKey": "Data:DefaultConnection:ConnectionString" + } } } \ No newline at end of file diff --git a/test/E2ETests/PublishAndRunTests.cs b/test/E2ETests/PublishAndRunTests.cs index f097a70fe5..3e2086f92f 100644 --- a/test/E2ETests/PublishAndRunTests.cs +++ b/test/E2ETests/PublishAndRunTests.cs @@ -16,7 +16,7 @@ namespace E2ETests [InlineData(ServerType.WebListener, KreFlavor.DesktopClr, KreArchitecture.amd64, "http://localhost:5002/", false)] //https://github.com/aspnet/KRuntime/issues/642 //[InlineData(ServerType.Helios, KreFlavor.CoreClr, KreArchitecture.amd64, "http://localhost:5001/", false)] - [InlineData(ServerType.Kestrel, KreFlavor.DesktopClr, KreArchitecture.x86, "http://localhost:5004/", true)] + [InlineData(ServerType.Kestrel, KreFlavor.Mono, KreArchitecture.x86, "http://localhost:5004/", true)] public void PublishAndRunTests(ServerType serverType, KreFlavor kreFlavor, KreArchitecture architecture, string applicationBaseUrl, bool RunTestOnMono = false) { Console.WriteLine("Variation Details : HostType = {0}, KreFlavor = {1}, Architecture = {2}, applicationBaseUrl = {3}", serverType, kreFlavor, architecture, applicationBaseUrl); diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index b444848875..f836dd37f7 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Net.Http; +using System.Threading; using Xunit; namespace E2ETests @@ -87,6 +88,7 @@ namespace E2ETests { Console.WriteLine("Failed to complete the request with error: {0}", exception.ToString()); Console.WriteLine("Retrying request.."); + Thread.Sleep(1 * 1000); //Wait for a second before retry } } }