public async Task GenerateNegotiateResponseWithAppName(string appName, string id, string expectedResponse) { var requestIdProvider = new TestRequestIdProvider(id); var config = new ConfigurationBuilder().Build(); var serviceProvider = new ServiceCollection().AddSignalR() .AddAzureSignalR(o => { o.ConnectionString = DefaultConnectionString; o.ApplicationName = appName; }) .Services .AddLogging() .AddSingleton <IConfiguration>(config) .AddSingleton <IConnectionRequestIdProvider>(requestIdProvider) .BuildServiceProvider(); var requestFeature = new HttpRequestFeature { }; var features = new FeatureCollection(); features.Set <IHttpRequestFeature>(requestFeature); var httpContext = new DefaultHttpContext(features); var handler = serviceProvider.GetRequiredService <NegotiateHandler>(); var negotiateResponse = await handler.Process(httpContext, "chat"); Assert.NotNull(negotiateResponse); Assert.EndsWith(expectedResponse, negotiateResponse.Url); }
public async Task GenerateNegotiateResponseWithPathAndQuery(string path, string queryString, string id, string expectedQueryString) { var requestIdProvider = new TestRequestIdProvider(id); var config = new ConfigurationBuilder().Build(); var serviceProvider = new ServiceCollection().AddSignalR() .AddAzureSignalR(o => o.ConnectionString = DefaultConnectionString) .Services .AddLogging() .AddSingleton <IConfiguration>(config) .AddSingleton <IConnectionRequestIdProvider>(requestIdProvider) .BuildServiceProvider(); var requestFeature = new HttpRequestFeature { Path = path, QueryString = queryString }; var features = new FeatureCollection(); features.Set <IHttpRequestFeature>(requestFeature); var httpContext = new DefaultHttpContext(features); var handler = serviceProvider.GetRequiredService <NegotiateHandler>(); var negotiateResponse = await handler.Process(httpContext, "chat"); Assert.NotNull(negotiateResponse); Assert.EndsWith($"?hub=chat&{expectedQueryString}", negotiateResponse.Url); }
public async Task TestNegotiateHandlerWithMultipleEndpointsAndCustomerRouterAndAppName() { var requestIdProvider = new TestRequestIdProvider("a"); var config = new ConfigurationBuilder().Build(); var router = new TestCustomRouter(); var serviceProvider = new ServiceCollection().AddSignalR() .AddAzureSignalR(o => { o.ApplicationName = "testprefix"; o.Endpoints = new ServiceEndpoint[] { new ServiceEndpoint(ConnectionString2), new ServiceEndpoint(ConnectionString3, name: "chosen"), new ServiceEndpoint(ConnectionString4), }; }) .Services .AddLogging() .AddSingleton <IEndpointRouter>(router) .AddSingleton <IConfiguration>(config) .AddSingleton <IConnectionRequestIdProvider>(requestIdProvider) .BuildServiceProvider(); var requestFeature = new HttpRequestFeature { Path = "/user/path/negotiate/", QueryString = "?endpoint=chosen" }; var features = new FeatureCollection(); features.Set <IHttpRequestFeature>(requestFeature); var httpContext = new DefaultHttpContext(features); var handler = serviceProvider.GetRequiredService <NegotiateHandler>(); var negotiateResponse = await handler.Process(httpContext, "chat"); Assert.NotNull(negotiateResponse); Assert.Equal($"http://localhost3/client/?hub=testprefix_chat&asrs.op=%2Fuser%2Fpath&endpoint=chosen&asrs_request_id=a", negotiateResponse.Url); }
public async Task TestNegotiateHandlerWithMultipleEndpointsAndCustomRouter() { var requestIdProvider = new TestRequestIdProvider("a"); var config = new ConfigurationBuilder().Build(); var router = new TestCustomRouter(); var serviceProvider = new ServiceCollection().AddSignalR() .AddAzureSignalR( o => o.Endpoints = new ServiceEndpoint[] { new ServiceEndpoint(ConnectionString2), new ServiceEndpoint(ConnectionString3, name: "chosen"), new ServiceEndpoint(ConnectionString4), }) .Services .AddLogging() .AddSingleton <IEndpointRouter>(router) .AddSingleton <IConfiguration>(config) .AddSingleton <IConnectionRequestIdProvider>(requestIdProvider) .BuildServiceProvider(); var requestFeature = new HttpRequestFeature { Path = "/user/path/negotiate/", QueryString = "?endpoint=chosen" }; var features = new FeatureCollection(); features.Set <IHttpRequestFeature>(requestFeature); var httpContext = new DefaultHttpContext(features); var handler = serviceProvider.GetRequiredService <NegotiateHandler>(); var negotiateResponse = await handler.Process(httpContext, "chat"); Assert.NotNull(negotiateResponse); Assert.Equal($"http://localhost3/client/?hub=chat&asrs.op=%2Fuser%2Fpath&endpoint=chosen&asrs_request_id=a", negotiateResponse.Url); // With no query string should return 400 requestFeature = new HttpRequestFeature { Path = "/user/path/negotiate/", }; var responseFeature = new HttpResponseFeature(); features.Set <IHttpRequestFeature>(requestFeature); features.Set <IHttpResponseFeature>(responseFeature); httpContext = new DefaultHttpContext(features); handler = serviceProvider.GetRequiredService <NegotiateHandler>(); negotiateResponse = await handler.Process(httpContext, "chat"); Assert.Null(negotiateResponse); Assert.Equal(400, responseFeature.StatusCode); // With no query string should return 400 requestFeature = new HttpRequestFeature { Path = "/user/path/negotiate/", QueryString = "?endpoint=notexists" }; responseFeature = new HttpResponseFeature(); features.Set <IHttpRequestFeature>(requestFeature); features.Set <IHttpResponseFeature>(responseFeature); httpContext = new DefaultHttpContext(features); handler = serviceProvider.GetRequiredService <NegotiateHandler>(); await Assert.ThrowsAsync <InvalidOperationException>(() => handler.Process(httpContext, "chat")); }