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 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 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_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_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_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 ); }
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 ); }