Пример #1
0
        public void Constructor_BindsValues()
        {
            var appsettings = @"
{
   'redis': {
        'client': {
            'host': 'localhost',
            'port': 1234,
            'password': '******',
            'instanceid': 'instanceid'
        }
   }
}";

            var    path      = TestHelpers.CreateTempFile(appsettings);
            string directory = Path.GetDirectoryName(path);
            string fileName  = Path.GetFileName(path);

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(directory);
            configurationBuilder.AddJsonFile(fileName);
            var config = configurationBuilder.Build();

            var sconfig = new RedisCacheConnectorOptions(config);

            Assert.Equal("localhost", sconfig.Host);
            Assert.Equal(1234, sconfig.Port);
            Assert.Equal("password", sconfig.Password);
            Assert.Equal("instanceid", sconfig.InstanceId);
            Assert.Equal(null, sconfig.ConnectionString);
        }
        public void CreateRedisServiceConnectorFactory_MultipleRedisServices_ThrowsConnectorException()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", RedisCacheTestHelpers.TwoServerVCAP);

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddCloudFoundry();
            var config = builder.Build();
            RedisCacheConnectorOptions connectorOptions = new RedisCacheConnectorOptions();

            // Act and Assert
            var ex = Assert.Throws <ConnectorException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config));

            Assert.Contains("Multiple", ex.Message);

            var ex2 = Assert.Throws <ConnectorException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, config));

            Assert.Contains("Multiple", ex2.Message);

            var ex3 = Assert.Throws <ConnectorException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, connectorOptions));

            Assert.Contains("Multiple", ex3.Message);
        }
Пример #3
0
        public void Create_CanReturnRedisCache()
        {
            // arrange
            RedisCacheConnectorOptions config = new RedisCacheConnectorOptions()
            {
                Host         = "localhost",
                Port         = 1234,
                Password     = "******",
                InstanceName = "instanceId"
            };
            RedisServiceInfo si = new RedisServiceInfo("myId", RedisServiceInfo.REDIS_SCHEME, "foobar", 4321, "sipassword")
            {
                ApplicationInfo = new ApplicationInstanceInfo()
                {
                    InstanceId = "instanceId"
                }
            };

            // act
            var factory = new RedisServiceConnectorFactory(si, config, typeof(RedisCache), typeof(RedisCacheOptions), null);
            var cache   = factory.Create(null);

            // assert
            Assert.NotNull(cache);
            Assert.IsType <RedisCache>(cache);
        }
Пример #4
0
        public void ConnectionString_Overridden_By_CloudFoundryConfig()
        {
            // arrange
            // simulate an appsettings file
            var appsettings = new Dictionary <string, string>()
            {
                ["redis:client:ConnectionString"] = "Server=fake;Database=test;Uid=steeltoe;Pwd=password;"
            };

            // add environment variables as Cloud Foundry would
            Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", RedisCacheTestHelpers.SingleServerVCAP);

            // add settings to config
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appsettings);
            configurationBuilder.AddEnvironmentVariables();
            configurationBuilder.AddCloudFoundry();
            var config = configurationBuilder.Build();

            // act
            var sconfig = new RedisCacheConnectorOptions(config);

            // assert
            Assert.NotEqual(appsettings["redis:client:ConnectionString"], sconfig.ToString());
        }
        public void Create_CanReturnConnectionMultiplexer()
        {
            // arrange
            RedisCacheConnectorOptions config = new RedisCacheConnectorOptions()
            {
                Host               = "localhost",
                Port               = 1234,
                Password           = "******",
                InstanceName       = "instanceId",
                AbortOnConnectFail = false,
                ConnectTimeout     = 1
            };
            RedisServiceInfo si = new RedisServiceInfo("myId", "127.0.0.1", 4321, "sipassword")
            {
                ApplicationInfo = new ApplicationInstanceInfo()
                {
                    InstanceId = "instanceId"
                }
            };
            MethodInfo initializer = typeof(ConnectionMultiplexer).GetMethod("Connect", new Type[] { typeof(ConfigurationOptions), typeof(TextWriter) });

            // act
            var factory = new RedisServiceConnectorFactory(si, config, typeof(ConnectionMultiplexer), typeof(ConfigurationOptions), initializer);
            var multi   = factory.Create(null);

            // assert
            Assert.NotNull(multi);
            Assert.IsType <ConnectionMultiplexer>(multi);
        }
Пример #6
0
        public void Create_CanReturnConnectionMultiplexer()
        {
            // arrange
            RedisCacheConnectorOptions config = new RedisCacheConnectorOptions()
            {
                Host               = "localhost",
                Port               = 1234,
                Password           = "******",
                InstanceName       = "instanceId",
                AbortOnConnectFail = false,
                ConnectTimeout     = 1
            };
            RedisServiceInfo si = new RedisServiceInfo("myId", RedisServiceInfo.REDIS_SCHEME, "127.0.0.1", 4321, "sipassword")
            {
                ApplicationInfo = new ApplicationInstanceInfo()
                {
                    InstanceId = "instanceId"
                }
            };

            // act
            var factory = new RedisServiceConnectorFactory(si, config, typeof(ConnectionMultiplexer), typeof(ConfigurationOptions), RedisTypeLocator.StackExchangeInitializer);
            var multi   = factory.Create(null);

            // assert
            Assert.NotNull(multi);
            Assert.IsType <ConnectionMultiplexer>(multi);
        }
Пример #7
0
        public void ConfigureConnection_NoServiceInfo_ReturnsExpected()
        {
            // arrange
            var configurer = new RedisCacheConfigurer();
            var config     = new RedisCacheConnectorOptions()
            {
                Host     = "localhost",
                Port     = 1234,
                Password = "******"
            };

            // act
            var opts = configurer.Configure(null, config);

            Assert.NotNull(opts);

            // assert
            Assert.NotNull(((ConfigurationOptions)opts.ToStackExchangeObject(typeof(ConfigurationOptions))).EndPoints);
            var ep = ((ConfigurationOptions)opts.ToStackExchangeObject(typeof(ConfigurationOptions))).EndPoints[0] as DnsEndPoint;

            Assert.NotNull(ep);
            Assert.Equal("localhost", ep.Host);
            Assert.Equal(1234, ep.Port);
            Assert.Equal("password", opts.Password);
        }
        /// <summary>
        /// Adds ConnectionMultiplexer (as ConnectionMultiplexer and IConnectionMultiplexer) to your Autofac Container
        /// </summary>
        /// <param name="container">Your Autofac Container Builder</param>
        /// <param name="config">Application configuration</param>
        /// <param name="serviceName">Cloud Foundry service name binding</param>
        /// <returns>the RegistrationBuilder for (optional) additional configuration</returns>
        public static IRegistrationBuilder <object, SimpleActivatorData, SingleRegistrationStyle> RegisterRedisConnectionMultiplexer(
            this ContainerBuilder container,
            IConfiguration config,
            string serviceName = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            Type       redisInterface      = RedisTypeLocator.StackExchangeInterface;
            Type       redisImplementation = RedisTypeLocator.StackExchangeImplementation;
            Type       redisOptions        = RedisTypeLocator.StackExchangeOptions;
            MethodInfo initializer         = RedisTypeLocator.StackExchangeInitializer;

            RedisServiceInfo info = serviceName != null
                ? config.GetRequiredServiceInfo <RedisServiceInfo>(serviceName)
                : config.GetSingletonServiceInfo <RedisServiceInfo>();

            RedisCacheConnectorOptions   redisConfig = new RedisCacheConnectorOptions(config);
            RedisServiceConnectorFactory factory     = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, initializer ?? null);

            container.Register(c => new RedisHealthContributor(factory, redisImplementation, c.ResolveOptional <ILogger <RedisHealthContributor> >())).As <IHealthContributor>();
            return(container.Register(c => factory.Create(null)).As(redisInterface, redisImplementation));
        }
Пример #9
0
        public void ConfigureConnection_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            // arrange
            var configurer = new RedisCacheConfigurer();
            var config     = new RedisCacheConnectorOptions()
            {
                Host     = "localhost",
                Port     = 1234,
                Password = "******"
            };
            var si = new RedisServiceInfo("myId", RedisServiceInfo.REDIS_SCHEME, "foobar", 4321, "sipassword");

            // act
            var opts = configurer.Configure(si, config);

            Assert.NotNull(opts);

            // assert
            Assert.NotNull(((ConfigurationOptions)opts.ToStackExchangeObject(typeof(ConfigurationOptions))).EndPoints);
            var ep = ((ConfigurationOptions)opts.ToStackExchangeObject(typeof(ConfigurationOptions))).EndPoints[0] as DnsEndPoint;

            Assert.NotNull(ep);
            Assert.Equal("foobar", ep.Host);
            Assert.Equal(4321, ep.Port);
            Assert.Equal("sipassword", opts.Password);
        }
Пример #10
0
        public void ConfigureConnection_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            RedisCacheConfigurer       configurer = new RedisCacheConfigurer();
            RedisCacheConnectorOptions config     = new RedisCacheConnectorOptions()
            {
                Host     = "localhost",
                Port     = 1234,
                Password = "******"
            };
            RedisServiceInfo si = new RedisServiceInfo("myId", "foobar", 4321, "sipassword");

            si.ApplicationInfo = new ApplicationInstanceInfo()
            {
                InstanceId = "instanceId"
            };
            var opts = configurer.ConfigureConnection(si, config);

            Assert.NotNull(opts);

            Assert.NotNull(opts.EndPoints);
            var ep = opts.EndPoints[0] as DnsEndPoint;

            Assert.NotNull(ep);
            Assert.Equal("foobar", ep.Host);
            Assert.Equal(4321, ep.Port);
            Assert.Equal("sipassword", opts.Password);
        }
Пример #11
0
        public void Configure_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            RedisCacheConfigurer       configurer = new RedisCacheConfigurer();
            RedisCacheConnectorOptions config     = new RedisCacheConnectorOptions()
            {
                Host       = "localhost",
                Port       = 1234,
                Password   = "******",
                InstanceId = "instanceId"
            };
            RedisServiceInfo si = new RedisServiceInfo("myId", "foobar", 4321, "sipassword");

            si.ApplicationInfo = new ApplicationInstanceInfo()
            {
                InstanceId = "instanceId"
            };
            var opts = configurer.Configure(si, config);

            Assert.NotNull(opts);
            var redisOptions = opts.Value;

            Assert.NotNull(redisOptions);

            Assert.Equal("foobar:4321,password=sipassword,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", redisOptions.Configuration);
            Assert.Equal("instanceId", redisOptions.InstanceName);
        }
Пример #12
0
        public void Constructor_BindsValues()
        {
            var appsettings = @"
{
   'redis': {
        'client': {
            'host': 'localhost',
            'port': 1234,
            'password': '******',
            'instanceid': 'instanceid',
            'allowAdmin': true,
            'clientName': 'foobar',
            'connectRetry': 100,
            'connectTimeout': 100,
            'abortOnConnectFail': true,
            'keepAlive': 100,
            'resolveDns': true,
            'serviceName': 'foobar',
            'ssl': true,
            'sslHost': 'foobar',
            'writeBuffer': 100,
            'tieBreaker': 'foobar'
        }
   }
}";

            var    path      = TestHelpers.CreateTempFile(appsettings);
            string directory = Path.GetDirectoryName(path);
            string fileName  = Path.GetFileName(path);

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(directory);
            configurationBuilder.AddJsonFile(fileName);
            var config = configurationBuilder.Build();

            var sconfig = new RedisCacheConnectorOptions(config);

            Assert.Equal("localhost", sconfig.Host);
            Assert.Equal(1234, sconfig.Port);
            Assert.Equal("password", sconfig.Password);
            Assert.Equal("instanceid", sconfig.InstanceId);

            Assert.Equal(true, sconfig.AllowAdmin);
            Assert.Equal("foobar", sconfig.ClientName);
            Assert.Equal(100, sconfig.ConnectRetry);
            Assert.Equal(100, sconfig.ConnectTimeout);
            Assert.Equal(true, sconfig.AbortOnConnectFail);
            Assert.Equal(100, sconfig.KeepAlive);
            Assert.Equal(true, sconfig.ResolveDns);
            Assert.Equal("foobar", sconfig.ServiceName);
            Assert.Equal(true, sconfig.Ssl);
            Assert.Equal("foobar", sconfig.SslHost);
            Assert.Equal("foobar", sconfig.TieBreaker);
            Assert.Equal(100, sconfig.WriteBuffer);


            Assert.Equal(null, sconfig.ConnectionString);
        }
Пример #13
0
        public string GetConnectionString()
        {
            var info        = configuration.GetSingletonServiceInfo <RedisServiceInfo>();
            var redisConfig = new RedisCacheConnectorOptions(configuration);

            var connectionOptions = new RedisCacheConfigurer().Configure(info, redisConfig);

            return(connectionOptions.ToString());
        }
        public void CreateRedisServiceConnectorFactory_ThrowsIfConnectorOptionsNull()
        {
            var config = new ConfigurationBuilder().Build();
            RedisCacheConnectorOptions connectorOptions = null;

            var ex = Assert.Throws <ArgumentNullException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, connectorOptions, "foobar"));

            Assert.Contains(nameof(connectorOptions), ex.Message);
        }
Пример #15
0
        public void UpdateOptions_FromServiceInfo_ReturnsExcpected()
        {
            var configurer  = new RedisCacheConfigurer();
            var connOptions = new RedisCacheConnectorOptions();
            var si          = new RedisServiceInfo("myId", RedisServiceInfo.REDIS_SCHEME, "foobar", 4321, "sipassword");

            configurer.UpdateOptions(si, connOptions);

            Assert.Equal("foobar:4321,password=sipassword,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", connOptions.ToString());
            Assert.Null(connOptions.InstanceName);
        }
        public void Microsoft_Is_Connected_Returns_Up_Status()
        {
            var redisOptions = new RedisCacheConnectorOptions();
            var sInfo        = new RedisServiceInfo("MyId", "redis://localhost:6379");
            var logrFactory  = new LoggerFactory();
            var connFactory  = new RedisServiceConnectorFactory(sInfo, redisOptions, RedisTypeLocator.MicrosoftImplementation, RedisTypeLocator.MicrosoftOptions, null);
            var h            = new RedisHealthContributor(connFactory, RedisTypeLocator.MicrosoftImplementation, logrFactory.CreateLogger <RedisHealthContributor>());

            var status = h.Health();

            Assert.Equal(HealthStatus.UP, status.Status);
        }
Пример #17
0
        public void Constructor_BindsValues()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["redis:client:host"]               = "localhost",
                ["redis:client:port"]               = "1234",
                ["redis:client:password"]           = "******",
                ["redis:client:instancename"]       = "instanceid",
                ["redis:client:allowAdmin"]         = "true",
                ["redis:client:clientName"]         = "foobar",
                ["redis:client:connectRetry"]       = "100",
                ["redis:client:connectTimeout"]     = "100",
                ["redis:client:abortOnConnectFail"] = "true",
                ["redis:client:keepAlive"]          = "100",
                ["redis:client:resolveDns"]         = "true",
                ["redis:client:serviceName"]        = "foobar",
                ["redis:client:ssl"]         = "true",
                ["redis:client:sslHost"]     = "foobar",
                ["redis:client:writeBuffer"] = "100",
                ["redis:client:tieBreaker"]  = "foobar",
                ["redis:client:syncTimeout"] = "100"
            };

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();

            var sconfig = new RedisCacheConnectorOptions(config);

            Assert.Equal("localhost", sconfig.Host);
            Assert.Equal(1234, sconfig.Port);
            Assert.Equal("password", sconfig.Password);
            Assert.Equal("instanceid", sconfig.InstanceName);

            Assert.True(sconfig.AllowAdmin);
            Assert.Equal("foobar", sconfig.ClientName);
            Assert.Equal(100, sconfig.ConnectRetry);
            Assert.Equal(100, sconfig.ConnectTimeout);
            Assert.True(sconfig.AbortOnConnectFail);
            Assert.Equal(100, sconfig.KeepAlive);
            Assert.True(sconfig.ResolveDns);
            Assert.Equal("foobar", sconfig.ServiceName);
            Assert.True(sconfig.Ssl);
            Assert.Equal("foobar", sconfig.SslHost);
            Assert.Equal("foobar", sconfig.TieBreaker);
            Assert.Equal(100, sconfig.WriteBuffer);
            Assert.Equal(100, sconfig.SyncTimeout);

            Assert.Null(sconfig.ConnectionString);
        }
Пример #18
0
        public void ConnectionString_Returned_AsConfigured()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["redis:client:ConnectionString"] = "Server=fake;Database=test;Uid=steeltoe;Pwd=password;"
            };
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();

            var sconfig = new RedisCacheConnectorOptions(config);

            Assert.Equal(appsettings["redis:client:ConnectionString"], sconfig.ToString());
        }
        public void StackExchange_Is_Connected_Returns_Up_Status()
        {
            // arrange
            var redisOptions = new RedisCacheConnectorOptions();
            var sInfo        = new RedisServiceInfo("MyId", "redis://localhost:6379");
            var logrFactory  = new LoggerFactory();
            var connFactory  = new RedisServiceConnectorFactory(sInfo, redisOptions, RedisTypeLocator.StackExchangeImplementation, RedisTypeLocator.StackExchangeOptions, RedisTypeLocator.StackExchangeInitializer);
            var h            = new RedisHealthContributor(connFactory, RedisTypeLocator.StackExchangeImplementation, logrFactory.CreateLogger <RedisHealthContributor>());

            // act
            var status = h.Health();

            // assert
            Assert.Equal(HealthStatus.UP, status.Status);
        }
Пример #20
0
        public void UpdateOptions_FromServiceInfo_ReturnsExcpected()
        {
            RedisCacheConfigurer       configurer  = new RedisCacheConfigurer();
            RedisCacheConnectorOptions connOptions = new RedisCacheConnectorOptions();
            RedisServiceInfo           si          = new RedisServiceInfo("myId", "foobar", 4321, "sipassword");

            si.ApplicationInfo = new ApplicationInstanceInfo()
            {
                ApplicationId = "applicationId"
            };
            configurer.UpdateOptions(si, connOptions);

            Assert.Equal("foobar:4321,password=sipassword,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", connOptions.ToString());
            Assert.Null(connOptions.InstanceId);
        }
Пример #21
0
        public void UpdateOptions_FromConfig_WithConnectionString_ReturnsExcpected()
        {
            RedisCacheConfigurer       configurer   = new RedisCacheConfigurer();
            RedisCacheOptions          redisOptions = new RedisCacheOptions();
            RedisCacheConnectorOptions config       = new RedisCacheConnectorOptions()
            {
                ConnectionString = "foobar",
                InstanceId       = "instanceId"
            };

            configurer.UpdateOptions(config, redisOptions);

            Assert.Equal("foobar", redisOptions.Configuration);
            Assert.Equal("instanceId", redisOptions.InstanceName);
        }
        public void Microsoft_Not_Connected_Returns_Down_Status()
        {
            var redisOptions = new RedisCacheConnectorOptions()
            {
                ConnectTimeout = 1
            };
            var sInfo       = new RedisServiceInfo("MyId", "redis://localhost:6378");
            var logrFactory = new LoggerFactory();
            var connFactory = new RedisServiceConnectorFactory(sInfo, redisOptions, RedisTypeLocator.MicrosoftImplementation, RedisTypeLocator.MicrosoftOptions, null);
            var h           = new RedisHealthContributor(connFactory, RedisTypeLocator.MicrosoftImplementation, logrFactory.CreateLogger <RedisHealthContributor>());

            var status = h.Health();

            Assert.Equal(HealthStatus.DOWN, status.Status);
            Assert.Equal("Redis health check failed", status.Description);
        }
Пример #23
0
        public void UpdateOptions_FromConfig_WithOutConnectionString_ReturnsExcpected()
        {
            RedisCacheConfigurer       configurer   = new RedisCacheConfigurer();
            RedisCacheOptions          redisOptions = new RedisCacheOptions();
            RedisCacheConnectorOptions config       = new RedisCacheConnectorOptions()
            {
                Host       = "localhost",
                Port       = 1234,
                Password   = "******",
                InstanceId = "instanceId"
            };

            configurer.UpdateOptions(config, redisOptions);

            Assert.Equal("localhost:1234,password=password,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", redisOptions.Configuration);
            Assert.Equal("instanceId", redisOptions.InstanceName);
        }
        public void CreateRedisServiceConnectorFactory_ThrowsIfConfigurationNull()
        {
            // Arrange
            IConfigurationRoot config = null;
            IConfigurationRoot connectorConfiguration = new ConfigurationBuilder().Build();
            RedisCacheConnectorOptions connectorOptions = new RedisCacheConnectorOptions();

            // Act and Assert
            var ex = Assert.Throws<ArgumentNullException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, "foobar"));
            Assert.Contains(nameof(config), ex.Message);

            var ex2 = Assert.Throws<ArgumentNullException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, connectorConfiguration, "foobar"));
            Assert.Contains(nameof(config), ex2.Message);

            var ex3 = Assert.Throws<ArgumentNullException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, connectorOptions, "foobar"));
            Assert.Contains(nameof(config), ex3.Message);
        }
        public void CreateRedisServiceConnectorFactory_WithServiceName_NoVCAPs_ThrowsConnectorException()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();
            IConfigurationRoot config = new ConfigurationBuilder().Build();
            RedisCacheConnectorOptions connectorOptions = new RedisCacheConnectorOptions();

            // Act and Assert
            var ex = Assert.Throws<ConnectorException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, "foobar"));
            Assert.Contains("foobar", ex.Message);

            var ex2 = Assert.Throws<ConnectorException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, config, "foobar"));
            Assert.Contains("foobar", ex2.Message);

            var ex3 = Assert.Throws<ConnectorException>(() => RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config, connectorOptions, "foobar"));
            Assert.Contains("foobar", ex3.Message);
        }
Пример #26
0
        public void Configure_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            var configurer = new RedisCacheConfigurer();
            var config     = new RedisCacheConnectorOptions()
            {
                Host         = "localhost",
                Port         = 1234,
                Password     = "******",
                InstanceName = "instanceId"
            };
            var si = new RedisServiceInfo("myId", RedisServiceInfo.REDIS_SCHEME, "foobar", 4321, "sipassword");
            var connectionSettings = configurer.Configure(si, config);

            Assert.NotNull(connectionSettings);

            Assert.Equal("foobar:4321,password=sipassword,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", connectionSettings.ToString());
            Assert.Equal("instanceId", connectionSettings.InstanceName);
        }
Пример #27
0
        public void Configure_NoServiceInfo_ReturnsExpected()
        {
            var configurer = new RedisCacheConfigurer();
            var config     = new RedisCacheConnectorOptions()
            {
                Host         = "localhost",
                Port         = 1234,
                Password     = "******",
                InstanceName = "instanceId"
            };
            var opts = configurer.Configure(null, config);

            Assert.NotNull(opts);
            var redisOptions = (RedisCacheOptions)opts.ToMicrosoftExtensionObject(typeof(RedisCacheOptions));

            Assert.NotNull(redisOptions);

            Assert.Equal("localhost:1234,password=password,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", redisOptions.Configuration);
            Assert.Equal("instanceId", redisOptions.InstanceName);
        }
Пример #28
0
        public void Configure_NoServiceInfo_ReturnsExpected()
        {
            RedisCacheConfigurer       configurer = new RedisCacheConfigurer();
            RedisCacheConnectorOptions config     = new RedisCacheConnectorOptions()
            {
                Host       = "localhost",
                Port       = 1234,
                Password   = "******",
                InstanceId = "instanceId"
            };
            var opts = configurer.Configure(null, config);

            Assert.NotNull(opts);
            var redisOptions = opts.Value;

            Assert.NotNull(redisOptions);

            Assert.Equal("localhost:1234,password=password", redisOptions.Configuration);
            Assert.Equal("instanceId", redisOptions.InstanceName);
        }
        public void CreateCache_ReturnsRedisCache()
        {
            RedisCacheConnectorOptions config = new RedisCacheConnectorOptions()
            {
                Host       = "localhost",
                Port       = 1234,
                Password   = "******",
                InstanceId = "instanceId"
            };
            RedisServiceInfo si = new RedisServiceInfo("myId", "foobar", 4321, "sipassword");

            si.ApplicationInfo = new ApplicationInstanceInfo()
            {
                InstanceId = "instanceId"
            };
            var factory = new RedisServiceConnectorFactory(si, config);
            var cache   = factory.CreateCache(null);

            Assert.NotNull(cache);
        }
        public void CreateRedisServiceConnectorFactory_NoVCAPs_CreatesFactory()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["redis:client:host"]               = "127.0.0.1",
                ["redis:client:port"]               = "1234",
                ["redis:client:password"]           = "******",
                ["redis:client:abortOnConnectFail"] = "false"
            };

            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appsettings);
            var config           = configurationBuilder.Build();
            var connectorOptions = new RedisCacheConnectorOptions(config);

            Assert.NotNull(RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(config));
            Assert.NotNull(RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(new ConfigurationBuilder().Build(), config));
            Assert.NotNull(RedisCacheConfigurationExtensions.CreateRedisServiceConnectorFactory(new ConfigurationBuilder().Build(), connectorOptions));
        }