public void TestNegotiateHandlerWithMultipleEndpointsAndCustomRouter() { var config = new ConfigurationBuilder().Build(); var router = new TestCustomRouter(ConnectionString3); var serviceProvider = new ServiceCollection().AddSignalR() .AddAzureSignalR( o => o.Endpoints = new ServiceEndpoint[] { new ServiceEndpoint(ConnectionString2), new ServiceEndpoint(ConnectionString3), new ServiceEndpoint(ConnectionString4), }) .Services .AddLogging() .AddSingleton <IEndpointRouter>(router) .AddSingleton <IConfiguration>(config) .BuildServiceProvider(); var requestFeature = new HttpRequestFeature { Path = "/user/path/negotiate/", }; var features = new FeatureCollection(); features.Set <IHttpRequestFeature>(requestFeature); var httpContext = new DefaultHttpContext(features); var handler = serviceProvider.GetRequiredService <NegotiateHandler>(); var negotiateResponse = handler.Process(httpContext, "chat"); Assert.NotNull(negotiateResponse); Assert.Equal($"http://localhost3/client/?hub=chat&asrs.op=%2Fuser%2Fpath", negotiateResponse.Url); }
public async Task TestRunAzureSignalRWithMultipleAppSettingsAndCustomSettingsAndCustomRouter() { // Prepare the configuration using (new AppSettingsConfigScope(ConnectionString, ConnectionString2)) { var hubConfig = new HubConfiguration(); hubConfig.Resolver = new DefaultDependencyResolver(); var router = new TestCustomRouter(ConnectionString3); hubConfig.Resolver.Register(typeof(IEndpointRouter), () => router); using (WebApp.Start(ServiceUrl, app => app.RunAzureSignalR(AppName, hubConfig, options => { options.Endpoints = new ServiceEndpoint[] { new ServiceEndpoint(ConnectionString2, EndpointType.Secondary), new ServiceEndpoint(ConnectionString3), new ServiceEndpoint(ConnectionString4) }; }))) { var options = hubConfig.Resolver.Resolve <IOptions <ServiceOptions> >(); Assert.Equal(ConnectionString, options.Value.ConnectionString); Assert.Equal(3, options.Value.Endpoints.Length); var manager = hubConfig.Resolver.Resolve <IServiceEndpointManager>(); var endpoints = manager.GetAvailableEndpoints().ToArray(); Assert.Equal(4, endpoints.Length); var client = new HttpClient { BaseAddress = new Uri(ServiceUrl) }; endpoints = manager.GetPrimaryEndpoints().ToArray(); Assert.Equal(3, endpoints.Length); var response = await client.GetAsync("/negotiate"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var message = await response.Content.ReadAsStringAsync(); var responseObject = JsonConvert.DeserializeObject <ResponseMessage>(message); Assert.Equal("2.0", responseObject.ProtocolVersion); // with custome router, always goes to connection string 3 as passed into the router Assert.Equal("http://localhost3/aspnetclient", responseObject.RedirectUrl); } } }
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 void TestNegotiateHandlerWithMultipleEndpointsAndCustomRouter() { 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) .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 = handler.Process(httpContext, "chat"); Assert.NotNull(negotiateResponse); Assert.Equal($"http://localhost3/client/?hub=chat&asrs.op=%2Fuser%2Fpath&endpoint=chosen", 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 = 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>(); Assert.Throws <InvalidOperationException>(() => handler.Process(httpContext, "chat")); }