Пример #1
0
        public async Task DeleteRefreshTokenAsync__Argument_refresh_token_is_null__Should_throw_ArgumentNullException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    Func <Task> action = async() => await manager.DeleteRefreshTokenAsync(null);

                    await action.Should().ThrowExactlyAsync <ArgumentNullException>();
                }
            }
        }
Пример #2
0
        public async Task DeleteRefreshTokenAsync__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.DeleteRefreshTokenAsync(_validRefreshToken);

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null");
                }
            }
        }
Пример #3
0
        public async Task DeleteRefreshTokenAsync__Delete_successful__Resources_should_not_contain_deleted_refresh_token()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.RefreshTokens.Add(_validRefreshToken);
                    context.SaveChanges();
                }

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

                    await manager.DeleteRefreshTokenAsync(_validRefreshToken);

                    context.RefreshTokens.Where(x => x.Token.Equals(_validRefreshToken.Token)).Count().Should().Be(0);
                }
            }
        }
Пример #4
0
        public async Task DeleteRefreshTokenAsync__Resource_is_empty__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.RefreshTokens.RemoveRange(await context.RefreshTokens.ToArrayAsync());
                    await context.SaveChangesAsync();
                }

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

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

                    await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because resource is empty and cannot delete any element.");
                }
            }
        }
Пример #5
0
        public async Task DeleteRefreshTokenAsync__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.DeleteRefreshTokenAsync(_validRefreshToken);

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource doesnt exist and cannot get single instance of RefreshToken. " +
                                                                                         "NOTE Exception actually is type of 'SqLiteError' only if database provider is SQLite.");
                }
            }
        }
Пример #6
0
        public async Task DeleteRefreshTokenAsync__RefreshToken_to_be_deleted_not_found__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.RefreshTokens.Add(new RefreshToken {
                        Id = Guid.NewGuid().ToString(), Token = "sample_new_token"
                    });
                    context.SaveChanges();
                }

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

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

                    await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because RefreshToken to be deleted not found.");
                }
            }
        }
Пример #7
0
        public async Task DeleteRefreshTokenAsync__Delete_successful__Resources_length_should_be_less_by_1()
        {
            int expectedLength;

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

                using (var context = await factory.CreateContextAsync())
                {
                    expectedLength = context.RefreshTokens.Count() - 1;
                    var manager = new RefreshTokenManager(context, _logger, _jwtOptions);

                    await manager.DeleteRefreshTokenAsync(_validRefreshToken);

                    context.RefreshTokens.Count().Should().Be(expectedLength);
                }
            }
        }