Couple more reaction changes for Hosting (#1126)
This commit is contained in:
parent
5d8aa1ee2a
commit
3a8f512fa7
|
|
@ -14,17 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
{
|
{
|
||||||
var ex = Assert.Throws<NotSupportedException>(() =>
|
var ex = Assert.Throws<NotSupportedException>(() =>
|
||||||
{
|
{
|
||||||
using (var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost(options => options.MapHub<InvalidHub>("overloads")))
|
||||||
.UseKestrel()
|
|
||||||
.ConfigureServices(services =>
|
|
||||||
{
|
|
||||||
services.AddSignalR();
|
|
||||||
})
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UseSignalR(options => options.MapHub<InvalidHub>("overloads"));
|
|
||||||
})
|
|
||||||
.Build())
|
|
||||||
{
|
{
|
||||||
builder.Start();
|
builder.Start();
|
||||||
}
|
}
|
||||||
|
|
@ -37,20 +27,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
public void MapHubFindsAuthAttributeOnHub()
|
public void MapHubFindsAuthAttributeOnHub()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
using (var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost(options => options.MapHub<AuthHub>("path", httpSocketOptions =>
|
||||||
.UseKestrel()
|
{
|
||||||
.ConfigureServices(services =>
|
authCount += httpSocketOptions.AuthorizationData.Count;
|
||||||
{
|
})))
|
||||||
services.AddSignalR();
|
|
||||||
})
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UseSignalR(options => options.MapHub<AuthHub>("path", httpSocketOptions =>
|
|
||||||
{
|
|
||||||
authCount += httpSocketOptions.AuthorizationData.Count;
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.Build())
|
|
||||||
{
|
{
|
||||||
builder.Start();
|
builder.Start();
|
||||||
}
|
}
|
||||||
|
|
@ -62,20 +42,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
public void MapHubFindsAuthAttributeOnInheritedHub()
|
public void MapHubFindsAuthAttributeOnInheritedHub()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
using (var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost(options => options.MapHub<InheritedAuthHub>("path", httpSocketOptions =>
|
||||||
.UseKestrel()
|
{
|
||||||
.ConfigureServices(services =>
|
authCount += httpSocketOptions.AuthorizationData.Count;
|
||||||
{
|
})))
|
||||||
services.AddSignalR();
|
|
||||||
})
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UseSignalR(options => options.MapHub<InheritedAuthHub>("path", httpSocketOptions =>
|
|
||||||
{
|
|
||||||
authCount += httpSocketOptions.AuthorizationData.Count;
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.Build())
|
|
||||||
{
|
{
|
||||||
builder.Start();
|
builder.Start();
|
||||||
}
|
}
|
||||||
|
|
@ -87,25 +57,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub()
|
public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
using (var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost(options => options.MapHub<DoubleAuthHub>("path", httpSocketOptions =>
|
||||||
.UseKestrel()
|
{
|
||||||
.ConfigureServices(services =>
|
authCount += httpSocketOptions.AuthorizationData.Count;
|
||||||
{
|
})))
|
||||||
services.AddSignalR();
|
|
||||||
})
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UseSignalR(options => options.MapHub<DoubleAuthHub>("path", httpSocketOptions =>
|
|
||||||
{
|
|
||||||
authCount += httpSocketOptions.AuthorizationData.Count;
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.Build())
|
|
||||||
{
|
{
|
||||||
builder.Start();
|
builder.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(2, authCount);
|
Assert.Equal(2, authCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class InvalidHub : Hub
|
private class InvalidHub : Hub
|
||||||
|
|
@ -132,5 +92,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
private class AuthHub : Hub
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,28 +32,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
public void MapEndPointFindsAuthAttributeOnEndPoint()
|
public void MapEndPointFindsAuthAttributeOnEndPoint()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost<AuthEndPoint>("auth",
|
||||||
.UseKestrel()
|
options => authCount += options.AuthorizationData.Count))
|
||||||
.ConfigureServices(services =>
|
{
|
||||||
{
|
builder.Start();
|
||||||
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();
|
|
||||||
|
|
||||||
Assert.Equal(1, authCount);
|
Assert.Equal(1, authCount);
|
||||||
}
|
}
|
||||||
|
|
@ -62,28 +45,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
public void MapEndPointFindsAuthAttributeOnInheritedEndPoint()
|
public void MapEndPointFindsAuthAttributeOnInheritedEndPoint()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost<InheritedAuthEndPoint>("auth",
|
||||||
.UseKestrel()
|
options => authCount += options.AuthorizationData.Count))
|
||||||
.ConfigureServices(services =>
|
{
|
||||||
{
|
builder.Start();
|
||||||
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();
|
|
||||||
|
|
||||||
Assert.Equal(1, authCount);
|
Assert.Equal(1, authCount);
|
||||||
}
|
}
|
||||||
|
|
@ -92,28 +58,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
public void MapEndPointFindsAuthAttributesOnDoubleAuthEndPoint()
|
public void MapEndPointFindsAuthAttributesOnDoubleAuthEndPoint()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
var builder = new WebHostBuilder()
|
using (var builder = BuildWebHost<DoubleAuthEndPoint>("auth",
|
||||||
.UseKestrel()
|
options => authCount += options.AuthorizationData.Count))
|
||||||
.ConfigureServices(services =>
|
{
|
||||||
{
|
builder.Start();
|
||||||
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();
|
|
||||||
|
|
||||||
Assert.Equal(2, authCount);
|
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")]
|
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")]
|
||||||
public async Task MapEndPointWithWebSocketSubProtocolSetsProtocol()
|
public async Task MapEndPointWithWebSocketSubProtocolSetsProtocol()
|
||||||
{
|
{
|
||||||
var host = new WebHostBuilder()
|
var host = BuildWebHost<MyEndPoint>("socket",
|
||||||
.UseUrls("http://127.0.0.1:0")
|
options => options.WebSockets.SubProtocol = "protocol1");
|
||||||
.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();
|
|
||||||
|
|
||||||
await host.StartAsync();
|
await host.StartAsync();
|
||||||
|
|
||||||
|
|
@ -193,5 +121,30 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
throw new NotImplementedException();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue