public async Task SaveAsync_DoubleSave_ThrowsException() { var key = new JsonWebKeyStub(Guid.NewGuid()); await m_publicKeyDataProvider.SaveAsync(key).SafeAsync(); Assert.Throws <InvalidOperationException>(() => m_publicKeyDataProvider.SaveAsync(key).Wait()); }
public async Task GetById_IncorrectId_ReturnsKey() { var dummyKey = new JsonWebKeyStub( Guid.NewGuid() ); await m_publicKeyDataProvider.SaveAsync( dummyKey ).SafeAsync(); var key = await m_publicKeyDataProvider.GetByIdAsync( Guid.NewGuid() ).SafeAsync(); Assert.IsNull( key ); }
public async Task SaveAsync_DoubleSave_ThrowsException() { var id = Guid.NewGuid(); var key = new JsonWebKeyStub(id.ToString()); await m_publicKeyDataProvider.SaveAsync(id, key).ConfigureAwait(false); Assert.Throws <InvalidOperationException>(() => m_publicKeyDataProvider.SaveAsync(id, key).Wait()); }
public async Task GetById_IncorrectId_ReturnsKey() { var dummyKey = new JsonWebKeyStub(Guid.NewGuid()); await m_publicKeyDataProvider.SaveAsync(dummyKey).SafeAsync(); var key = await m_publicKeyDataProvider.GetByIdAsync(Guid.NewGuid()).SafeAsync(); Assert.IsNull(key); }
public async Task DeleteAsync_DoesSeemToDeleteKey() { var expectedKey = new JsonWebKeyStub(Guid.NewGuid()); Assert.DoesNotThrow(() => m_publicKeyDataProvider.DeleteAsync(expectedKey.Id).Wait()); var actualKey = await m_publicKeyDataProvider.GetByIdAsync(expectedKey.Id).SafeAsync(); Assert.IsNull(actualKey); }
public async Task GetById_CorrectId_ReturnsKey() { var expectedKey = new JsonWebKeyStub( Guid.NewGuid() ); await m_publicKeyDataProvider.SaveAsync( expectedKey ).SafeAsync(); var actualKey = await m_publicKeyDataProvider.GetByIdAsync( expectedKey.Id ).SafeAsync(); Assert.AreEqual( expectedKey.Id, actualKey.Id ); Assert.AreEqual( expectedKey.ExpiresAt, actualKey.ExpiresAt ); }
public async Task GetById_IncorrectId_ReturnsKey() { var id = Guid.NewGuid(); var dummyKey = new JsonWebKeyStub(id.ToString()); await m_publicKeyDataProvider.SaveAsync(id, dummyKey).ConfigureAwait(false); var key = await m_publicKeyDataProvider.GetByIdAsync(Guid.NewGuid()).ConfigureAwait(false); Assert.IsNull(key); }
public async Task DeleteAsync_DoesSeemToDeleteKey() { var expectedId = Guid.NewGuid(); var expectedKey = new JsonWebKeyStub(expectedId.ToString()); Assert.DoesNotThrow(() => m_publicKeyDataProvider.DeleteAsync(expectedId).Wait()); var actualKey = await m_publicKeyDataProvider.GetByIdAsync(expectedId).ConfigureAwait(false); Assert.IsNull(actualKey); }
public async Task GetById_CorrectId_ReturnsKey() { var expectedKey = new JsonWebKeyStub(Guid.NewGuid()); await m_publicKeyDataProvider.SaveAsync(expectedKey).SafeAsync(); var actualKey = await m_publicKeyDataProvider.GetByIdAsync(expectedKey.Id).SafeAsync(); Assert.AreEqual(expectedKey.Id, actualKey.Id); Assert.AreEqual(expectedKey.ExpiresAt, actualKey.ExpiresAt); }
public async Task GetByIdAsync_ValidId_ReturnsKey() { JsonWebKey key = new JsonWebKeyStub( Guid.NewGuid() ); AddKeyToDb( key ); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync( key.Id ) .SafeAsync(); Assert.IsNotNull( result ); Assert.AreEqual( key.Id, result.Id ); }
public async Task GetById_CorrectId_ReturnsKey() { var expectedId = Guid.NewGuid(); var expectedKey = new JsonWebKeyStub(expectedId.ToString()); await m_publicKeyDataProvider.SaveAsync(expectedId, expectedKey).ConfigureAwait(false); var actualKey = await m_publicKeyDataProvider.GetByIdAsync(expectedId).ConfigureAwait(false); Assert.AreEqual(expectedKey.Id, actualKey.Id); Assert.AreEqual(expectedKey.ExpiresAt, actualKey.ExpiresAt); }
public async Task DeleteAsync_DoesntDeleteOtherKey() { var expectedKey = new JsonWebKeyStub(Guid.NewGuid()); await m_publicKeyDataProvider.SaveAsync(expectedKey).SafeAsync(); Assert.DoesNotThrow(() => m_publicKeyDataProvider.DeleteAsync(Guid.NewGuid()).Wait()); var actualKey = await m_publicKeyDataProvider.GetByIdAsync(expectedKey.Id).SafeAsync(); Assert.IsNotNull(actualKey); Assert.AreEqual(expectedKey.Id, actualKey.Id); }
public async Task GetByIdAsync_ValidId_ReturnsKey() { JsonWebKey key = new JsonWebKeyStub(Guid.NewGuid().ToString()); AddKeyToDb(key); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(new Guid( key.Id )) .ConfigureAwait(false); Assert.IsNotNull(result); Assert.AreEqual(key.Id, result.Id); }
public async Task GetByIdAsync_ExpiredKey_DeletesAndReturnsNull() { JsonWebKey key = new JsonWebKeyStub( Guid.NewGuid(), DateTime.UtcNow - TimeSpan.FromMinutes( 1 ) ); AddKeyToDb( key ); m_mockPublicKeyDataProvider.Setup( kp => kp.DeleteAsync( key.Id ) ).Returns( Task.Delay( 0 ) ); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync( key.Id ) .SafeAsync(); m_mockPublicKeyDataProvider.Verify( kp => kp.DeleteAsync( key.Id ), Times.Once() ); Assert.IsNull( result ); }
public async Task GetByIdAsync_ValidId_ReturnsKey() { JsonWebKey key = new JsonWebKeyStub(Guid.NewGuid()); AddKeyToDb(key); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(key.Id) .SafeAsync(); Assert.IsNotNull(result); Assert.AreEqual(key.Id, result.Id); }
public async Task GetByIdAsync_InvalidId_ReturnsNull() { JsonWebKey key = new JsonWebKeyStub( Guid.NewGuid() ); AddKeyToDb( key ); Guid id = Guid.NewGuid(); m_mockPublicKeyDataProvider.Setup( kp => kp.GetByIdAsync( id ) ).ReturnsAsync( null ); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync( id ) .SafeAsync(); Assert.IsNull( result ); }
public async Task GetById_CorrectIdWithOthers_ReturnsKey() { var expectedId = Guid.NewGuid(); var expectedKey = new JsonWebKeyStub(expectedId.ToString()); await m_publicKeyDataProvider.SaveAsync(expectedId, expectedKey).SafeAsync(); var dummyKey = new JsonWebKeyStub(Guid.NewGuid().ToString()); await m_publicKeyDataProvider.SaveAsync(new Guid( dummyKey.Id ), dummyKey).SafeAsync(); var actualKey = await m_publicKeyDataProvider.GetByIdAsync(expectedId).SafeAsync(); Assert.AreEqual(expectedKey.Id, actualKey.Id); Assert.AreEqual(expectedKey.ExpiresAt, actualKey.ExpiresAt); }
public async Task GetByIdAsync_ExpiredKey_DeletesAndReturnsNull() { JsonWebKey key = new JsonWebKeyStub(Guid.NewGuid().ToString(), NOW - TimeSpan.FromTicks(1)); AddKeyToDb(key); m_mockPublicKeyDataProvider.Setup(kp => kp.DeleteAsync(new Guid(key.Id))).Returns(Task.CompletedTask); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(new Guid( key.Id )) .ConfigureAwait(false); m_mockPublicKeyDataProvider.Verify(kp => kp.DeleteAsync(new Guid(key.Id)), Times.Once()); Assert.IsNull(result); }
public async Task GetByIdAsync_ExpiredKey_DeletesAndReturnsNull() { JsonWebKey key = new JsonWebKeyStub(Guid.NewGuid(), NOW - TimeSpan.FromTicks(1)); AddKeyToDb(key); m_mockPublicKeyDataProvider.Setup(kp => kp.DeleteAsync(key.Id)).Returns(Task.Delay(0)); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(key.Id) .SafeAsync(); m_mockPublicKeyDataProvider.Verify(kp => kp.DeleteAsync(key.Id), Times.Once()); Assert.IsNull(result); }
public async Task GetByIdAsync_InvalidId_ReturnsNull() { JsonWebKey key = new JsonWebKeyStub(Guid.NewGuid()); AddKeyToDb(key); Guid id = Guid.NewGuid(); m_mockPublicKeyDataProvider.Setup(kp => kp.GetByIdAsync(id)).ReturnsAsync(null); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(id) .SafeAsync(); Assert.IsNull(result); }
public async Task GetByIdAsync_InvalidId_ReturnsNull() { JsonWebKey key = new JsonWebKeyStub(Guid.NewGuid().ToString()); AddKeyToDb(key); var id = Guid.NewGuid(); m_mockPublicKeyDataProvider.Setup(kp => kp.GetByIdAsync(id)).ReturnsAsync(value: null); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(id) .ConfigureAwait(false); Assert.IsNull(result); }
public async Task GetByIdAsync_OtherKeyExpired_GetsDeletedAsWell() { JsonWebKey freshKey = new JsonWebKeyStub(Guid.NewGuid()); JsonWebKey expiredKey = new JsonWebKeyStub(Guid.NewGuid(), NOW - TimeSpan.FromTicks(1)); AddKeyToDb(freshKey); AddKeyToDb(expiredKey); m_mockPublicKeyDataProvider .Setup(pkdb => pkdb.DeleteAsync(expiredKey.Id)) .Returns(Task.Delay(0)); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync(freshKey.Id) .SafeAsync(); Assert.IsNotNull(result); Assert.AreEqual(freshKey.Id, result.Id); m_mockPublicKeyDataProvider.Verify(pkdp => pkdp.DeleteAsync(expiredKey.Id), Times.Once); }
public async Task GetByIdAsync_OtherKeyExpired_GetsDeletedAsWell() { JsonWebKey freshKey = new JsonWebKeyStub( Guid.NewGuid() ); JsonWebKey expiredKey = new JsonWebKeyStub( Guid.NewGuid(), DateTime.UtcNow - TimeSpan.FromSeconds( 1 ) ); AddKeyToDb( freshKey ); AddKeyToDb( expiredKey ); m_mockPublicKeyDataProvider .Setup( pkdb => pkdb.DeleteAsync( expiredKey.Id ) ) .Returns( Task.Delay( 0 ) ); JsonWebKey result = await m_publicKeyDataProvider .GetByIdAsync( freshKey.Id ) .SafeAsync(); Assert.IsNotNull( result ); Assert.AreEqual( freshKey.Id, result.Id ); m_mockPublicKeyDataProvider.Verify( pkdp => pkdp.DeleteAsync( expiredKey.Id ), Times.Once ); }
public async Task SaveAsync_DoubleSave_ThrowsException() { var key = new JsonWebKeyStub( Guid.NewGuid() ); await m_publicKeyDataProvider.SaveAsync( key ).SafeAsync(); Assert.Throws<InvalidOperationException>( () => m_publicKeyDataProvider.SaveAsync( key ).Wait() ); }
public async Task DeleteAsync_DoesntDeleteOtherKey() { var expectedKey = new JsonWebKeyStub( Guid.NewGuid() ); await m_publicKeyDataProvider.SaveAsync( expectedKey ).SafeAsync(); Assert.DoesNotThrow( () => m_publicKeyDataProvider.DeleteAsync( Guid.NewGuid() ).Wait() ); var actualKey = await m_publicKeyDataProvider.GetByIdAsync( expectedKey.Id ).SafeAsync(); Assert.IsNotNull( actualKey ); Assert.AreEqual( expectedKey.Id, actualKey.Id ); }
public async Task DeleteAsync_DoubleDelete_DoesSeemToDeleteKey() { var expectedKey = new JsonWebKeyStub( Guid.NewGuid() ); Assert.DoesNotThrow( () => m_publicKeyDataProvider.DeleteAsync( expectedKey.Id ).Wait() ); Assert.DoesNotThrow( () => m_publicKeyDataProvider.DeleteAsync( expectedKey.Id ).Wait() ); var actualKey = await m_publicKeyDataProvider.GetByIdAsync( expectedKey.Id ).SafeAsync(); Assert.IsNull( actualKey ); }