diff --git a/global.json b/global.json index 62e52db817..983ba0401e 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": ["src", "C:\\Github\\Options\\src"] + "projects": ["src"] } diff --git a/samples/IdentitySample.Mvc/Startup.cs b/samples/IdentitySample.Mvc/Startup.cs index 191ed7cc05..7542316fbb 100644 --- a/samples/IdentitySample.Mvc/Startup.cs +++ b/samples/IdentitySample.Mvc/Startup.cs @@ -2,6 +2,7 @@ using System.IO; using IdentitySample.Models; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Data.Entity; @@ -100,5 +101,14 @@ namespace IdentitySamples SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait(); } + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/IdentitySample.Mvc/hosting.json b/samples/IdentitySample.Mvc/hosting.json new file mode 100644 index 0000000000..715337cb2d --- /dev/null +++ b/samples/IdentitySample.Mvc/hosting.json @@ -0,0 +1,4 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel", + "server.urls": "http://localhost:41532/" +} diff --git a/samples/IdentitySample.Mvc/project.json b/samples/IdentitySample.Mvc/project.json index 46a035a21b..5ab9ee6f27 100644 --- a/samples/IdentitySample.Mvc/project.json +++ b/samples/IdentitySample.Mvc/project.json @@ -1,42 +1,43 @@ { - "authors": [ - "Microsoft" - ], - "description": "Identity sample MVC application on K", - "version": "1.0.0-*", - "dependencies": { - "Microsoft.AspNet.Mvc": "6.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*", - "Microsoft.AspNet.Diagnostics": "1.0.0-*", - "Microsoft.AspNet.Identity": "3.0.0-*", - "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*", - "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", - "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", - "Microsoft.AspNet.Authentication.Google": "1.0.0-*", - "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", - "Microsoft.AspNet.Authorization": "1.0.0-*", - "Microsoft.AspNet.StaticFiles": "1.0.0-*", - "EntityFramework.Commands": "7.0.0-*", - "EntityFramework.MicrosoftSqlServer": "7.0.0-*", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", - "Microsoft.Extensions.Configuration.Json": "1.0.0-*", - "Microsoft.Extensions.OptionsModel": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*" + "authors": [ + "Microsoft" + ], + "description": "Identity sample MVC application on K", + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Mvc": "6.0.0-*", + "Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*", + "Microsoft.AspNet.Diagnostics": "1.0.0-*", + "Microsoft.AspNet.Identity": "3.0.0-*", + "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*", + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", + "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", + "Microsoft.AspNet.Authentication.Google": "1.0.0-*", + "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", + "Microsoft.AspNet.Authorization": "1.0.0-*", + "Microsoft.AspNet.StaticFiles": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "EntityFramework.Commands": "7.0.0-*", + "EntityFramework.MicrosoftSqlServer": "7.0.0-*", + "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", + "Microsoft.Extensions.Configuration.Json": "1.0.0-*", + "Microsoft.Extensions.OptionsModel": "1.0.0-*", + "Microsoft.Extensions.Logging.Console": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { + "web": "IdentitySample.Mvc" + }, + "webroot": ".", + "frameworks": { + "dnx451": { + "dependencies": { + "Microsoft.Extensions.Logging.NLog": "1.0.0-*" + } }, - "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:41532", - "run": "run server.urls=http://localhost:41532", - "ef": "EntityFramework.Commands" - }, - "webroot": ".", - "frameworks": { - "dnx451": { - "dependencies": { - "Microsoft.Extensions.Logging.NLog": "1.0.0-*" - } - }, - "dnxcore50": { - } + "dnxcore50": { } + } } diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs b/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs index e0fd3b6068..9b221fd64c 100644 --- a/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs +++ b/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Features.Authentication; @@ -29,7 +30,9 @@ namespace Microsoft.AspNet.Identity.InMemory [Fact] public void UseIdentityThrowsWithoutAddIdentity() { - Assert.Throws(() => TestServer.Create(app => app.UseIdentity())); + var builder = new WebApplicationBuilder() + .Configure(app => app.UseIdentity()); + Assert.Throws(() => new TestServer(builder)); } [Fact] @@ -179,87 +182,89 @@ namespace Microsoft.AspNet.Identity.InMemory private static TestServer CreateServer(Action configureServices = null, Func testpath = null, Uri baseAddress = null) { - var server = TestServer.Create(app => - { - app.UseIdentity(); - app.Use(async (context, next) => + var builder = new WebApplicationBuilder() + .Configure(app => { - var req = context.Request; - var res = context.Response; - var userManager = context.RequestServices.GetRequiredService>(); - var signInManager = context.RequestServices.GetRequiredService>(); - PathString remainder; - if (req.Path == new PathString("/normal")) + app.UseIdentity(); + app.Use(async (context, next) => { - res.StatusCode = 200; - } - else if (req.Path == new PathString("/createMe")) + var req = context.Request; + var res = context.Response; + var userManager = context.RequestServices.GetRequiredService>(); + var signInManager = context.RequestServices.GetRequiredService>(); + PathString remainder; + if (req.Path == new PathString("/normal")) + { + res.StatusCode = 200; + } + else if (req.Path == new PathString("/createMe")) + { + var result = await userManager.CreateAsync(new TestUser("hao"), TestPassword); + res.StatusCode = result.Succeeded ? 200 : 500; + } + else if (req.Path == new PathString("/createSimple")) + { + var result = await userManager.CreateAsync(new TestUser("simple"), "aaaaaa"); + res.StatusCode = result.Succeeded ? 200 : 500; + } + else if (req.Path == new PathString("/protected")) + { + res.StatusCode = 401; + } + else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder)) + { + var isPersistent = bool.Parse(remainder.Value.Substring(1)); + var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false); + res.StatusCode = result.Succeeded ? 200 : 500; + } + else if (req.Path == new PathString("/twofactorRememeber")) + { + var user = await userManager.FindByNameAsync("hao"); + await signInManager.RememberTwoFactorClientAsync(user); + res.StatusCode = 200; + } + else if (req.Path == new PathString("/isTwoFactorRememebered")) + { + var user = await userManager.FindByNameAsync("hao"); + var result = await signInManager.IsTwoFactorClientRememberedAsync(user); + res.StatusCode = result ? 200 : 500; + } + else if (req.Path == new PathString("/twofactorSignIn")) + { + } + else if (req.Path == new PathString("/me")) + { + var auth = new AuthenticateContext("Application"); + auth.Authenticated(context.User, new AuthenticationProperties().Items, new AuthenticationDescription().Items); + Describe(res, auth); + } + else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder)) + { + var auth = new AuthenticateContext(remainder.Value.Substring(1)); + await context.Authentication.AuthenticateAsync(auth); + Describe(res, auth); + } + else if (req.Path == new PathString("/testpath") && testpath != null) + { + await testpath(context); + } + else + { + await next(); + } + }); + }) + .ConfigureServices(services => + { + services.AddIdentity(); + services.AddSingleton, InMemoryUserStore>(); + services.AddSingleton, InMemoryRoleStore>(); + if (configureServices != null) { - var result = await userManager.CreateAsync(new TestUser("hao"), TestPassword); - res.StatusCode = result.Succeeded ? 200 : 500; - } - else if (req.Path == new PathString("/createSimple")) - { - var result = await userManager.CreateAsync(new TestUser("simple"), "aaaaaa"); - res.StatusCode = result.Succeeded ? 200 : 500; - } - else if (req.Path == new PathString("/protected")) - { - res.StatusCode = 401; - } - else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder)) - { - var isPersistent = bool.Parse(remainder.Value.Substring(1)); - var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false); - res.StatusCode = result.Succeeded ? 200 : 500; - } - else if (req.Path == new PathString("/twofactorRememeber")) - { - var user = await userManager.FindByNameAsync("hao"); - await signInManager.RememberTwoFactorClientAsync(user); - res.StatusCode = 200; - } - else if (req.Path == new PathString("/isTwoFactorRememebered")) - { - var user = await userManager.FindByNameAsync("hao"); - var result = await signInManager.IsTwoFactorClientRememberedAsync(user); - res.StatusCode = result ? 200 : 500; - } - else if (req.Path == new PathString("/twofactorSignIn")) - { - } - else if (req.Path == new PathString("/me")) - { - var auth = new AuthenticateContext("Application"); - auth.Authenticated(context.User, new AuthenticationProperties().Items, new AuthenticationDescription().Items); - Describe(res, auth); - } - else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder)) - { - var auth = new AuthenticateContext(remainder.Value.Substring(1)); - await context.Authentication.AuthenticateAsync(auth); - Describe(res, auth); - } - else if (req.Path == new PathString("/testpath") && testpath != null) - { - await testpath(context); - } - else - { - await next(); + configureServices(services); } }); - }, - services => - { - services.AddIdentity(); - services.AddSingleton, InMemoryUserStore>(); - services.AddSingleton, InMemoryRoleStore>(); - if (configureServices != null) - { - configureServices(services); - } - }); + var server = new TestServer(builder); server.BaseAddress = baseAddress; return server; }