public async Task AddRefreshToken__Add_successful__Resource_contains_added_RefreshToken() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { var manager = new RefreshTokenManager(context, _logger, _jwtOptions); await manager.AddRefreshTokenAsync(_validRefreshToken); context.RefreshTokens.Contains(_validRefreshToken).Should().BeTrue(); } } }
public async Task AddRefreshToken__Argument_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.AddRefreshTokenAsync(null); await action.Should().ThrowExactlyAsync <ArgumentNullException>("Because argument 'refreshToken' is null."); } } }
public async Task AddRefreshToken__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.AddRefreshTokenAsync(_validRefreshToken); await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null"); } } }
public async Task AddRefreshToken__Add_successful__Resource_length_should_be_greater_by_1() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { int expectedLength = context.RefreshTokens.Count() + 1; var manager = new RefreshTokenManager(context, _logger, _jwtOptions); await manager.AddRefreshTokenAsync(_validRefreshToken); context.RefreshTokens.Count().Should().Be(expectedLength); } } }
public async Task AddRefreshToken__In_resource_exists_the_same_RefreshToken_as_this_one_to_be_added__Should_throw_InvalidOperationException() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { context.RefreshTokens.Add(_validRefreshToken); await context.SaveChangesAsync(); } using (var context = await factory.CreateContextAsync()) { var manager = new RefreshTokenManager(context, _logger, _jwtOptions); Func <Task> action = async() => await manager.AddRefreshTokenAsync(_validRefreshToken); await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because in resource exists the same RefreshToken as this one to be added."); } } }
public async Task AddRefreshToken__Resource_does_not_exist__Should_throw_InternalDbmanagerException() { 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.AddRefreshTokenAsync(_validRefreshToken); 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."); } } }