Reacting to new Hosting API

This commit is contained in:
John Luo 2015-12-18 13:41:36 -08:00
parent cade3de890
commit 4f577e7217
5 changed files with 136 additions and 116 deletions

View File

@ -1,3 +1,3 @@
{ {
"projects": ["src", "C:\\Github\\Options\\src"] "projects": ["src"]
} }

View File

@ -2,6 +2,7 @@ using System.IO;
using IdentitySample.Models; using IdentitySample.Models;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.DataProtection;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
@ -100,5 +101,14 @@ namespace IdentitySamples
SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait(); SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();
} }
public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseStartup<Startup>()
.Build();
application.Run();
}
} }
} }

View File

@ -0,0 +1,4 @@
{
"server": "Microsoft.AspNet.Server.Kestrel",
"server.urls": "http://localhost:41532/"
}

View File

@ -6,7 +6,6 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*", "Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*", "Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Identity": "3.0.0-*", "Microsoft.AspNet.Identity": "3.0.0-*",
@ -17,6 +16,7 @@
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
"Microsoft.AspNet.Authorization": "1.0.0-*", "Microsoft.AspNet.Authorization": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"EntityFramework.Commands": "7.0.0-*", "EntityFramework.Commands": "7.0.0-*",
"EntityFramework.MicrosoftSqlServer": "7.0.0-*", "EntityFramework.MicrosoftSqlServer": "7.0.0-*",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
@ -24,10 +24,11 @@
"Microsoft.Extensions.OptionsModel": "1.0.0-*", "Microsoft.Extensions.OptionsModel": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*" "Microsoft.Extensions.Logging.Console": "1.0.0-*"
}, },
"compilationOptions": {
"emitEntryPoint": true
},
"commands": { "commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:41532", "web": "IdentitySample.Mvc"
"run": "run server.urls=http://localhost:41532",
"ef": "EntityFramework.Commands"
}, },
"webroot": ".", "webroot": ".",
"frameworks": { "frameworks": {

View File

@ -12,6 +12,7 @@ using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Authentication;
using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Features.Authentication;
@ -29,7 +30,9 @@ namespace Microsoft.AspNet.Identity.InMemory
[Fact] [Fact]
public void UseIdentityThrowsWithoutAddIdentity() public void UseIdentityThrowsWithoutAddIdentity()
{ {
Assert.Throws<InvalidOperationException>(() => TestServer.Create(app => app.UseIdentity())); var builder = new WebApplicationBuilder()
.Configure(app => app.UseIdentity());
Assert.Throws<InvalidOperationException>(() => new TestServer(builder));
} }
[Fact] [Fact]
@ -179,7 +182,8 @@ namespace Microsoft.AspNet.Identity.InMemory
private static TestServer CreateServer(Action<IServiceCollection> configureServices = null, Func<HttpContext, Task> testpath = null, Uri baseAddress = null) private static TestServer CreateServer(Action<IServiceCollection> configureServices = null, Func<HttpContext, Task> testpath = null, Uri baseAddress = null)
{ {
var server = TestServer.Create(app => var builder = new WebApplicationBuilder()
.Configure(app =>
{ {
app.UseIdentity(); app.UseIdentity();
app.Use(async (context, next) => app.Use(async (context, next) =>
@ -249,8 +253,8 @@ namespace Microsoft.AspNet.Identity.InMemory
await next(); await next();
} }
}); });
}, })
services => .ConfigureServices(services =>
{ {
services.AddIdentity<TestUser, TestRole>(); services.AddIdentity<TestUser, TestRole>();
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>(); services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
@ -260,6 +264,7 @@ namespace Microsoft.AspNet.Identity.InMemory
configureServices(services); configureServices(services);
} }
}); });
var server = new TestServer(builder);
server.BaseAddress = baseAddress; server.BaseAddress = baseAddress;
return server; return server;
} }