public static CustomMappersConfiguration UserMappers() { var r = new CustomMappersConfiguration(); r.Register(d => new Address(d["Address"] as string)); return(r); }
public void GetAsync_WhenCalled_ExpectResponse() { // Arrange var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>(); mockCacheConfiguration.Setup(r => r.Get).Returns( new RedisCacheConfigurationEntity { CacheDuration = 10, RedisCacheDefaultPrefix = "DEFAULT", UseObjectCompression = false }); var customMappersConfiguration = new CustomMappersConfiguration { ClientMapper = CustomMapperFactory.CreateClientMapper<CustomClient>() }; var jsonSettingsFactory = new JsonSettingsFactory(customMappersConfiguration); var cacheManager = new RedisCacheManager<Token>( RedisHelpers.ConnectionMultiplexer, mockCacheConfiguration.Object, jsonSettingsFactory.Create()); var tokenStore = new TokenHandleStore( cacheManager, mockCacheConfiguration.Object); // Act var stopwatch = Stopwatch.StartNew(); var token = tokenStore.GetAsync("Existing").Result; stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(token, Is.Not.Null); Assert.That(token.Client.GetType(), Is.EqualTo(typeof(CustomClient))); var customClient = (CustomClient)token.Client; Assert.That(customClient.AppId, Is.EqualTo(12)); }
/// <summary> /// Initializes a new instance of the <see cref="JsonSettingsFactory" /> class. /// </summary> /// <param name="customMappersConfiguration">The custom mappers configuration.</param> public JsonSettingsFactory(CustomMappersConfiguration customMappersConfiguration) { Contract.Requires(customMappersConfiguration != null); this.customMappersConfiguration = customMappersConfiguration; }
public void StoreAsync_WhenCalled_ExpectAction() { // Arrange var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>(); mockCacheConfiguration.Setup(r => r.Get).Returns( new RedisCacheConfigurationEntity { CacheDuration = 10, RedisCacheDefaultPrefix = "DEFAULT", UseObjectCompression = false }); var customMappersConfiguration = new CustomMappersConfiguration { ClientMapper = CustomMapperFactory.CreateClientMapper<CustomClient>() }; var jsonSettingsFactory = new JsonSettingsFactory(customMappersConfiguration); var cacheManager = new RedisCacheManager<Token>( RedisHelpers.ConnectionMultiplexer, mockCacheConfiguration.Object, jsonSettingsFactory.Create()); var tokenStore = new TokenHandleStore( cacheManager, mockCacheConfiguration.Object); var claim1 = new Claim("Type1", "Value1"); var claim2 = new Claim("Type2", "Value2"); var client = new CustomClient { Claims = new List<Claim> { claim1, claim2 } }; var token = new Token { Claims = new List<Claim> { claim1, claim2 }, Client = client, Type = "Type", CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)), Version = 1, Issuer = "Issuer", Lifetime = 120, Audience = "Audience" }; // Act var stopwatch = Stopwatch.StartNew(); tokenStore.StoreAsync("KeyToStore", token).Wait(); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); var redisValue = RedisHelpers.ConnectionMultiplexer.GetDatabase().StringGet("DEFAULT_THS_KeyToStore"); Assert.That(redisValue.HasValue, Is.True); Console.WriteLine(redisValue); }
/// <summary> /// Creates the specified connection multiplexer. /// </summary> /// <param name="redisConnectionString">The redis connection string.</param> /// <param name="connectionMultiplexer">The connection multiplexer.</param> /// <param name="configuration">The configuration.</param> /// <param name="mappers">The mappers.</param> /// <returns> /// <see cref="Tuple" /> containing singleton instances of objects to be used with Identity Server. /// <para>Item 1: Client store cache (<see cref="ICache{T}" />)</para><para>Item 2: Scope store cache (<see cref="ICache{T}" />)</para><para>Item 3: User service cache (<see cref="ICache{T}" />)</para> /// </returns> public static Entities.Caches Create( string redisConnectionString = null, ConnectionMultiplexer connectionMultiplexer = null, IConfiguration<RedisCacheConfigurationEntity> configuration = null, CustomMappersConfiguration mappers = null) { if (incomingRedisConnectionString == null) { incomingRedisConnectionString = redisConnectionString; } if (incomingConnectionMultiplexer == null) { incomingConnectionMultiplexer = connectionMultiplexer; } if (incomingConfiguration == null) { incomingConfiguration = configuration; } if (incomingMappers == null) { incomingMappers = mappers ?? new CustomMappersConfiguration(); } return LazyCaches.Value; }