diff --git a/src/MusicStore/StartupOpenIdConnect.cs b/src/MusicStore/StartupOpenIdConnect.cs index 45b02eb034..9aafca8b34 100644 --- a/src/MusicStore/StartupOpenIdConnect.cs +++ b/src/MusicStore/StartupOpenIdConnect.cs @@ -86,9 +86,7 @@ namespace MusicStore }); } - //This method is invoked when ASPNET_ENV is 'Development' or is not defined - //The allowed values are Development,Staging and Production - public void ConfigureDevelopment(IApplicationBuilder app, ILoggerFactory loggerFactory) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); @@ -103,11 +101,6 @@ namespace MusicStore // default path is: /runtimeinfo app.UseRuntimeInfoPage(); - Configure(app); - } - - public void Configure(IApplicationBuilder app) - { // Configure Session. app.UseSession(); diff --git a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs new file mode 100644 index 0000000000..f44f136be9 --- /dev/null +++ b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs @@ -0,0 +1,134 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Diagnostics; +using Microsoft.AspNet.Diagnostics.Entity; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Routing; +using Microsoft.AspNet.Security; +using Microsoft.Framework.Cache.Memory; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Logging.Console; +using MusicStore.Models; + +namespace MusicStore +{ + public class StartupOpenIdConnectTesting + { + public StartupOpenIdConnectTesting() + { + //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 ConfigureServices(IServiceCollection services) + { + //Sql client not available on mono + var useInMemoryStore = Type.GetType("Mono.Runtime") != null; + + // Add EF services to the services container + if (useInMemoryStore) + { + services.AddEntityFramework(Configuration) + .AddInMemoryStore() + .AddDbContext(); + } + else + { + services.AddEntityFramework(Configuration) + .AddSqlServer() + .AddDbContext(); + } + + // Add Identity services to the services container + services.AddIdentity(Configuration) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders() + .AddMessageProvider() + .AddMessageProvider(); + + // Add MVC services to the services container + services.AddMvc(); + + //Add all SignalR related services to IoC. + services.AddSignalR(); + + //Add InMemoryCache + services.AddSingleton(); + + // Add session related services. + services.AddCachingServices(); + services.AddSessionServices(); + + // Configure Auth + services.Configure(options => + { + options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build()); + }); + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(); + + //Display custom error page in production when error occurs + //During development use the ErrorPage middleware to display error information in the browser + app.UseErrorPage(ErrorPageOptions.ShowAll); + + app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll); + + // Add the runtime information page that can be used by developers + // to see what packages are used by the application + // default path is: /runtimeinfo + app.UseRuntimeInfoPage(); + + // Configure Session. + app.UseSession(); + + //Configure SignalR + app.UseSignalR(); + + // Add static files to the request pipeline + app.UseStaticFiles(); + + // Add cookie-based authentication to the request pipeline + app.UseIdentity(); + + // Create an Azure Active directory application and copy paste the following + // https://github.com/aspnet/Security/issues/113 + app.UseOpenIdConnectAuthentication(options => + { + options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; + options.ClientId = "[ClientId]"; + options.BackchannelHttpHandler = null; // TODO: Yet to implement the handler. + }); + + // Add MVC to the request pipeline + app.UseMvc(routes => + { + routes.MapRoute( + name: "areaRoute", + template: "{area:exists}/{controller}/{action}", + defaults: new { action = "Index" }); + + routes.MapRoute( + name: "default", + template: "{controller}/{action}/{id?}", + defaults: new { controller = "Home", action = "Index" }); + + routes.MapRoute( + name: "api", + template: "{controller}/{id?}"); + }); + + //Populates the MusicStore sample data + SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait(); + } + } +} \ No newline at end of file