Exemplo n.º 1
0
 public RedisClientTests(ITestOutputHelper output)
 {
     _output                = output;
     _startedPublisher      = Substitute.For <ISessionCreatedEventPublisher>();
     _endedPublisher        = Substitute.For <ISessionEndedEventPublisher>();
     _connectionMultiplexer = ConnectionMultiplexer.Connect("");
     _client                = new RedisSessionsClient(
         _connectionMultiplexer,
         "Sessions",
         TimeSpan.FromMinutes(1),
         TimeSpan.FromMinutes(5),
         EmptyLogFactory.Instance,
         _startedPublisher,
         _endedPublisher,
         2);
 }
Exemplo n.º 2
0
        public async Task Session_Should_Expire()
        {
            _client = new RedisSessionsClient(
                _connectionMultiplexer,
                "Sessions",
                TimeSpan.FromSeconds(1),
                TimeSpan.FromMinutes(5),
                EmptyLogFactory.Instance,
                _startedPublisher,
                _endedPublisher);
            var session = await _client.Authenticate(Guid.NewGuid().ToString(), "SomeInfo");

            await Task.Delay(TimeSpan.FromSeconds(2));

            var result = await _client.GetAsync(session.SessionToken);

            Assert.Null(result);
        }
Exemplo n.º 3
0
        public async Task Should_Not_Return_UserIds()
        {
            _client = new RedisSessionsClient(
                _connectionMultiplexer,
                "Sessions",
                TimeSpan.FromSeconds(1),
                TimeSpan.FromMinutes(5),
                EmptyLogFactory.Instance,
                _startedPublisher,
                _endedPublisher);
            var user1 = Guid.NewGuid().ToString();
            var user2 = Guid.NewGuid().ToString();
            await _client.Authenticate(user1, "SomeInfo");

            await _client.Authenticate(user2, "SomeInfo");

            await Task.Delay(TimeSpan.FromSeconds(2));

            var result = await _client.GetActiveClientIdsAsync();

            Assert.Empty(result);
        }
        public async Task Session_Should_Be_Refreshed_WithRefresh()
        {
            _client = new RedisSessionsClient(
                _connectionMultiplexer,
                "Sessions",
                TimeSpan.FromSeconds(1),
                TimeSpan.FromMinutes(5),
                LogFactory.Create(),
                _startedPublisher,
                _endedPublisher);
            var session = await _client.Authenticate(Guid.NewGuid().ToString(), "SomeInfo");

            await Task.Delay(TimeSpan.FromSeconds(0.8));

            await _client.RefreshSessionAsync(session.SessionToken);

            await Task.Delay(TimeSpan.FromSeconds(0.8));

            var result = await _client.GetAsync(session.SessionToken);

            Assert.NotNull(result);
        }