Couple more reaction changes for Hosting (#1126)

This commit is contained in:
BrennanConroy 2017-11-15 13:31:17 -08:00 committed by GitHub
parent 5d8aa1ee2a
commit 3a8f512fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 143 deletions

View File

@ -14,17 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
var ex = Assert.Throws<NotSupportedException>(() =>
{
using (var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseSignalR(options => options.MapHub<InvalidHub>("overloads"));
})
.Build())
using (var builder = BuildWebHost(options => options.MapHub<InvalidHub>("overloads")))
{
builder.Start();
}
@ -37,20 +27,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public void MapHubFindsAuthAttributeOnHub()
{
var authCount = 0;
using (var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseSignalR(options => options.MapHub<AuthHub>("path", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
}));
})
.Build())
using (var builder = BuildWebHost(options => options.MapHub<AuthHub>("path", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
})))
{
builder.Start();
}
@ -62,20 +42,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public void MapHubFindsAuthAttributeOnInheritedHub()
{
var authCount = 0;
using (var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseSignalR(options => options.MapHub<InheritedAuthHub>("path", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
}));
})
.Build())
using (var builder = BuildWebHost(options => options.MapHub<InheritedAuthHub>("path", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
})))
{
builder.Start();
}
@ -87,25 +57,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub()
{
var authCount = 0;
using (var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseSignalR(options => options.MapHub<DoubleAuthHub>("path", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
}));
})
.Build())
using (var builder = BuildWebHost(options => options.MapHub<DoubleAuthHub>("path", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
})))
{
builder.Start();
}
Assert.Equal(2, authCount);
Assert.Equal(2, authCount);
}
private class InvalidHub : Hub
@ -132,5 +92,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private class AuthHub : Hub
{
}
private IWebHost BuildWebHost(Action<HubRouteBuilder> configure)
{
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseSignalR(options => configure(options));
})
.Build();
}
}
}

View File

@ -32,28 +32,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
public void MapEndPointFindsAuthAttributeOnEndPoint()
{
var authCount = 0;
var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSockets();
services.AddEndPoint<AuthEndPoint>();
})
.Configure(app =>
{
app.UseSockets(routes =>
{
routes.MapEndPoint<AuthEndPoint>("auth", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
});
});
})
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
})
.Build();
using (var builder = BuildWebHost<AuthEndPoint>("auth",
options => authCount += options.AuthorizationData.Count))
{
builder.Start();
}
Assert.Equal(1, authCount);
}
@ -62,28 +45,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
public void MapEndPointFindsAuthAttributeOnInheritedEndPoint()
{
var authCount = 0;
var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSockets();
services.AddEndPoint<InheritedAuthEndPoint>();
})
.Configure(app =>
{
app.UseSockets(routes =>
{
routes.MapEndPoint<InheritedAuthEndPoint>("auth", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
});
});
})
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
})
.Build();
using (var builder = BuildWebHost<InheritedAuthEndPoint>("auth",
options => authCount += options.AuthorizationData.Count))
{
builder.Start();
}
Assert.Equal(1, authCount);
}
@ -92,28 +58,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
public void MapEndPointFindsAuthAttributesOnDoubleAuthEndPoint()
{
var authCount = 0;
var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSockets();
services.AddEndPoint<DoubleAuthEndPoint>();
})
.Configure(app =>
{
app.UseSockets(routes =>
{
routes.MapEndPoint<DoubleAuthEndPoint>("auth", httpSocketOptions =>
{
authCount += httpSocketOptions.AuthorizationData.Count;
});
});
})
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
})
.Build();
using (var builder = BuildWebHost<DoubleAuthEndPoint>("auth",
options => authCount += options.AuthorizationData.Count))
{
builder.Start();
}
Assert.Equal(2, authCount);
}
@ -122,29 +71,8 @@ namespace Microsoft.AspNetCore.Sockets.Tests
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")]
public async Task MapEndPointWithWebSocketSubProtocolSetsProtocol()
{
var host = new WebHostBuilder()
.UseUrls("http://127.0.0.1:0")
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSockets();
services.AddEndPoint<MyEndPoint>();
})
.Configure(app =>
{
app.UseSockets(routes =>
{
routes.MapEndPoint<MyEndPoint>("socket", httpSocketOptions =>
{
httpSocketOptions.WebSockets.SubProtocol = "protocol1";
});
});
})
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
})
.Build();
var host = BuildWebHost<MyEndPoint>("socket",
options => options.WebSockets.SubProtocol = "protocol1");
await host.StartAsync();
@ -193,5 +121,30 @@ namespace Microsoft.AspNetCore.Sockets.Tests
throw new NotImplementedException();
}
}
private IWebHost BuildWebHost<TEndPoint>(string path, Action<HttpSocketOptions> configure) where TEndPoint : EndPoint
{
return new WebHostBuilder()
.UseUrls("http://127.0.0.1:0")
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSockets();
services.AddEndPoint<TEndPoint>();
})
.Configure(app =>
{
app.UseSockets(routes =>
{
routes.MapEndPoint<TEndPoint>(path,
httpSocketOptions => configure(httpSocketOptions));
});
})
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
})
.Build();
}
}
}