Exemplo n.º 1
0
        public async Task GetSavedRefreshToken__Found_zero_matching_refresh_token__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    Func <Task> action = async() => await manager.GetSavedRefreshTokenAsync(_validRefreshToken.Token);

                    await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because RefreshToken not found.");
                }
            }
        }
Exemplo n.º 2
0
        public async Task GetSavedRefreshToken__Arguemnt_refresh_token_is_null_or_empty__Should_throw_ArgumentNullException([Values(null, "")] string refreshToken)
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    Func <Task> action = async() => await manager.GetSavedRefreshTokenAsync(refreshToken);

                    await action.Should().ThrowExactlyAsync <ArgumentException>("Because refreshToken cannot be null or empty.");
                }
            }
        }
Exemplo n.º 3
0
        public async Task GetSavedRefreshToken__Resource_is_null__Should_throw_InternalDbServiceException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.RefreshTokens = null as DbSet <RefreshToken>;
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    Func <Task> action = async() => await manager.GetSavedRefreshTokenAsync(_validRefreshToken.Token);

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null");
                }
            }
        }
Exemplo n.º 4
0
        public async Task GetSavedRefreshToken__Resource_is_empty__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.RefreshTokens.RemoveRange(await context.RefreshTokens.ToListAsync());
                    await context.SaveChangesAsync();
                }

                using (var context = await factory.CreateContextAsync())
                {
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    Func <Task> action = async() => await manager.GetSavedRefreshTokenAsync(_validRefreshToken.Token);

                    await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because resource is empty and cannot get single instance of RefreshToken.");
                }
            }
        }
Exemplo n.º 5
0
        public async Task GetSavedRefreshToken__Resource_does_not_exist__Should_throw_InternalDbServiceException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    // Drop RefreshTokens table.
                    context.Database.ExecuteSqlCommand("DROP TABLE [RefreshTokens]");
                }

                using (var context = await factory.CreateContextAsync())
                {
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    Func <Task> action = async() => await manager.GetSavedRefreshTokenAsync(_validRefreshToken.Token);

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource doesnt exist and cannot get single instance of RefreshToken. " +
                                                                                         "NOTE Excaption actually is type of 'SqLiteError' only if database provider is SQLite.");
                }
            }
        }
Exemplo n.º 6
0
        public async Task GetSavedRefreshToken__RefreshToken_found__Should_return_this_RefreshToken()
        {
            RefreshToken expectedRefreshToken;

            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.RefreshTokens.Add(_validRefreshToken);
                    await context.SaveChangesAsync();
                }

                using (var context = await factory.CreateContextAsync())
                {
                    expectedRefreshToken = await context.RefreshTokens.FirstOrDefaultAsync();

                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    var result = await manager.GetSavedRefreshTokenAsync(expectedRefreshToken.Token);

                    result.Should().BeEquivalentTo(expectedRefreshToken);
                }
            }
        }