public void TestGetEndpointsFromIdentityAndConnectionString() { var services = new ServiceCollection(); services.AddAzureClientsCore(); var factory = services.BuildServiceProvider().GetRequiredService <AzureComponentFactory>(); var config = new ConfigurationBuilder().AddInMemoryCollection().Build(); var serviceUri = "http://signalr.service.uri.com:441"; config["endpoints:eastus:serviceUri"] = serviceUri; config["endpoints:westus:secondary"] = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var endpoints = config.GetSection("endpoints").GetEndpoints(factory).ToArray(); Assert.Collection(endpoints, e => { Assert.Equal("eastus", e.Name); Assert.Equal(serviceUri, e.Endpoint); }, e => { Assert.Equal("westus", e.Name); Assert.Equal(EndpointType.Secondary, e.EndpointType); }); }
public void ConfigureServiceEndpoint_WithConnectionString() { var connectionStrings = FakeEndpointUtils.GetFakeConnectionString(2); var names = new string[] { "First", "Second" }; var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); foreach (var(name, connStr) in names.Zip(connectionStrings)) { configuration[$"{Constants.Keys.AzureSignalREndpointsKey}:{name}"] = connStr; } var connectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(); configuration[Constants.Keys.ConnectionStringDefaultKey] = connectionString; var optionsSetup = new ServiceManagerOptionsSetup(configuration); var options = new ServiceManagerOptions(); optionsSetup.Configure(options); var actualEndpoints = options.ServiceEndpoints; foreach (var(name, connStr) in names.Zip(connectionStrings)) { Assert.Contains(new ServiceEndpoint(name, connStr), actualEndpoints); } Assert.Equal(connectionString, options.ConnectionString); }
private ServiceManagerStore CreateServiceManagerStore(out IConfiguration configuration) { configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); configuration[Constants.AzureSignalRHubProtocol] = HubProtocol.NewtonsoftJson.ToString(); configuration[Constants.AzureSignalRConnectionStringName] = FakeEndpointUtils.GetFakeConnectionString(1).Single(); return(new ServiceManagerStore(configuration, NullLoggerFactory.Instance, null)); }
public void GetEndpointsWithSuffix(string relativePath) { var connectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); var connectionStringKey = "key"; configuration[connectionStringKey] = connectionString; configuration[$"{connectionStringKey}:{relativePath}"] = connectionString; Assert.Single(configuration.GetEndpoints(connectionStringKey)); }
public void TestAutoHealthCheckRouterWithSingleEndpoint() { var router = new AutoHealthCheckRouter(); var endpoints = new ServiceEndpoint[] { new ServiceEndpoint(FakeEndpointUtils.GetFakeConnectionString(1).First()) { Online = false } }; Assert.Equal(endpoints[0], router.GetNegotiateEndpoint(null, endpoints)); }
public void GetServiceManager_WithSingleEndpoint() { var connectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); var connectionStringKey = "key"; configuration[connectionStringKey] = connectionString; var managerStore = new ServiceManagerStore(configuration, NullLoggerFactory.Instance, null); var hubContextStore = managerStore.GetOrAddByConnectionStringKey(connectionStringKey); var manager = hubContextStore.ServiceManager; }
public void TestSignalROptionsFormat() { var options = new SignalROptions() { JsonObjectSerializer = new JsonObjectSerializer(), ServiceTransportType = ServiceTransportType.Persistent }; options.ServiceEndpoints.Add(new ServiceEndpoint(FakeEndpointUtils.GetFakeConnectionString())); options.ServiceEndpoints.Add(new ServiceEndpoint(new Uri("https://mysignalr.com"), new DefaultAzureCredential(), EndpointType.Secondary, "backup")); _outputHelper.WriteLine((options as IOptionsFormatter).Format()); }
public void GetEndpoints_IncludeNoSuffixEndpoint() { var count = 3; var connectionStrings = FakeEndpointUtils.GetFakeConnectionString(count).ToArray(); var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); var connectionStringKey = "key"; configuration[connectionStringKey] = connectionStrings[0]; configuration[$"{connectionStringKey}:a"] = connectionStrings[1]; configuration[$"{connectionStringKey}:a:primary"] = connectionStrings[2]; Assert.Equal(count, configuration.GetEndpoints(connectionStringKey, true).Count()); }
public void ForbidMultipleEndpointsInTransientModeFact() { Assert.Throws <NotImplementedException>(() => new ServiceManagerOptions { ConnectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(), ServiceEndpoints = FakeEndpointUtils.GetFakeEndpoint(1).ToArray() }.ValidateOptions()); Assert.Throws <NotImplementedException>(() => new ServiceManagerOptions { ServiceEndpoints = FakeEndpointUtils.GetFakeEndpoint(2).ToArray() }.ValidateOptions()); }
public async Task DefaultRouterExists() { var builder = new HostBuilder(); var host = builder .ConfigureAppConfiguration(b => b.AddInMemoryCollection( new Dictionary <string, string> { { "key", FakeEndpointUtils.GetFakeConnectionString(1).Single() }, { Constants.ServiceTransportTypeName, ServiceTransportType.Persistent.ToString() } })) .ConfigureWebJobs(b => b.AddSignalR()).Build(); var hubContext = await host.Services.GetRequiredService <IServiceManagerStore>().GetOrAddByConnectionStringKey("key").GetAsync("hubName") as ServiceHubContext; await Assert.ThrowsAsync <AzureSignalRNotConnectedException>(() => hubContext.NegotiateAsync()); }
public async Task StrongTypedHubContextNotCheckEndpointHealthWithSingleEndpoint(ServiceTransportType serviceTransportType) { var serviceManager = new ServiceManagerBuilder() .WithOptions(o => { o.ServiceTransportType = serviceTransportType; o.ConnectionString = FakeEndpointUtils.GetFakeConnectionString(1).First(); }) .WithLoggerFactory(_loggerFactory) .BuildServiceManager(); var hubContext = await serviceManager.CreateHubContextAsync <IChat>("hubName", default); var negotiateResponse = await hubContext.NegotiateAsync(); Assert.NotNull(negotiateResponse); }
public void TestGetNamedEndpointsFromConnectionString() { var connectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var config = new ConfigurationBuilder().AddInMemoryCollection().Build(); config["eastus"] = connectionString; config["eastus:primary"] = connectionString; config["eastus:secondary"] = connectionString; var endpoints = config.GetSection("eastus").GetNamedEndpointsFromConnectionString().ToArray(); Assert.Equal(3, endpoints.Length); Assert.All(endpoints, e => Assert.Equal("eastus", e.Name)); Assert.Equal(EndpointType.Primary, endpoints[0].EndpointType); Assert.Equal(EndpointType.Primary, endpoints[1].EndpointType); Assert.Equal(EndpointType.Secondary, endpoints[2].EndpointType); }
public void ProductInfoExists() { var connectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); var connectionStringKey = "key"; configuration[connectionStringKey] = connectionString; var productInfo = new ServiceCollection() .AddSignalRServiceManager(new OptionsSetup(configuration, NullLoggerFactory.Instance, connectionStringKey)) .BuildServiceProvider() .GetRequiredService <IOptions <ServiceManagerOptions> >() .Value.ProductInfo; Assert.NotNull(productInfo); }
public async Task MultiServiceEndpoints_NotAppliedToTransientModeAsync() { // to avoid possible file name conflict with another FileConfigHotReloadTest string configPath = nameof(MultiServiceEndpoints_NotAppliedToTransientModeAsync); var connStr = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var configObj = new { Azure = new { SignalR = new ServiceManagerOptions { ConnectionString = connStr } } }; File.WriteAllText(configPath, JsonConvert.SerializeObject(configObj)); var provider = new ServiceCollection().AddSignalRServiceManager() .AddSingleton <IConfiguration>(new ConfigurationBuilder().AddJsonFile(configPath, false, true).Build()) .BuildServiceProvider(); var optionsMonitor = provider.GetRequiredService <IOptionsMonitor <ServiceOptions> >(); Assert.Equal(connStr, optionsMonitor.CurrentValue.ConnectionString); //update json config file which won't pass validation var newConfigObj = new { Azure = new { SignalR = new { Endpoints = new { First = FakeEndpointUtils.GetFakeConnectionString(1).Single() }, ConnectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single() } } }; File.WriteAllText(configPath, JsonConvert.SerializeObject(newConfigObj)); await Task.Delay(5000); Assert.Equal(connStr, optionsMonitor.CurrentValue.ConnectionString);// as new config don't pass validation, it is not reloaded }
public void EmptyConfiguration_NotCleanOriginalValue() { const string app = "App"; var connStr = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var endpoints = FakeEndpointUtils.GetFakeEndpoint(2).ToArray(); var options = new ServiceManagerOptions { ApplicationName = app, ConnectionString = connStr, ServiceEndpoints = endpoints }; var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); var setup = new ServiceManagerOptionsSetup(configuration); setup.Configure(options); Assert.Equal(app, options.ApplicationName); Assert.Equal(connStr, options.ConnectionString); Assert.Equal(endpoints, options.ServiceEndpoints); }
public void ProductInfoValid() { var connectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single(); var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); var connectionStringKey = "key"; configuration[connectionStringKey] = connectionString; configuration[Constants.FunctionsWorkerRuntime] = Constants.DotnetWorker; var productInfo = new ServiceCollection() .AddSignalRServiceManager(new OptionsSetup(configuration, NullLoggerFactory.Instance, SingletonAzureComponentFactory.Instance, connectionStringKey)) .BuildServiceProvider() .GetRequiredService <IOptions <ServiceManagerOptions> >() .Value.ProductInfo; Assert.NotNull(productInfo); var reg = new Regex(@"\[(\w*)=(\w*)\]"); var match = reg.Match(productInfo); Assert.Equal(Constants.FunctionsWorkerProductInfoKey, match.Groups[1].Value); Assert.Equal(Constants.DotnetWorker, match.Groups[2].Value); }
public async Task ServerlessHubSyncNegotiate() { var hubContext = await new ServiceManagerBuilder().WithOptions(o => o.ConnectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single()).BuildServiceManager().CreateHubContextAsync("hub", default); var serviceManager = Mock.Of <IServiceManager>(); var myHub = new MyHub(hubContext, serviceManager); var connectionInfo = myHub.Negotiate("user"); }
public async Task NegotiateAsync() { var serviceManager = new ServiceManagerBuilder().WithOptions(o => o.ConnectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single()).BuildServiceManager(); var hubContext = await serviceManager.CreateHubContextAsync <IChatClient>("hubName", default); var myHub = new TestStronglyTypedHub(hubContext); var connectionInfo = await myHub.Negotiate("user"); Assert.NotNull(connectionInfo); }
public void GetStronglyTypedHubContextFact() { var serviceManager = new ServiceManagerBuilder().WithOptions(o => o.ConnectionString = FakeEndpointUtils.GetFakeConnectionString(1).Single()).BuildServiceManager(); var hubContext = new ServiceHubContextStore(null, serviceManager).GetAsync <IChatClient>(GetType().Name).Result; }