public async Task NullToken_Throws() { var service = new FakeSingleUseTokenServiceBase(Clock()); await Assert.ThrowsAsync <ArgumentNullException>("token", async() => { await service.Validate(token: null !); });
public async Task ValidToken_ReturnsTrue() { var token = new SingleUseToken("token"); var clock = Clock(); var expiration = clock.UtcNow.ToOffset().AddHours(1); var service = new FakeSingleUseTokenServiceBase(clock); await service.Create(token, new UtcDateTime(expiration)); Assert.True(await service.Validate(token)); }
public async Task TokenNotExists_ReturnsFalse() { var token = new SingleUseToken("token"); var clock = Clock(); var service = new FakeSingleUseTokenServiceBase(clock) { Retrieve_ShouldReturnData = false }; Assert.False(await service.Validate(token)); }
public async Task WhenCalled_CallsCreateOnService() { var token = new SingleUseToken("token"); var clock = Clock(); var expiration = clock.UtcNow.ToOffset().AddHours(1); var service = new FakeSingleUseTokenServiceBase(clock); await service.Create(token, new UtcDateTime(expiration)); Assert.Equal(token.Value, service.Create_InputData_Value); Assert.Equal(expiration, service.Create_InputData_Expiration); }
public async Task ExpirationAlreadyPassed_Throws() { var token = new SingleUseToken("token"); var clock = Clock(); var expiration = clock.UtcNow.ToOffset().AddHours(-1); var service = new FakeSingleUseTokenServiceBase(clock); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await service.Create(token, new UtcDateTime(expiration)); }); }
public async Task NullToken_Throws() { var clock = Clock(); var service = new FakeSingleUseTokenServiceBase(clock); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await service.Create( token: null !, expiration: new UtcDateTime(clock.UtcNow.ToOffset().AddHours(1))); }); }
public async Task TokenExpired_ReturnsFalse() { var token = new SingleUseToken("token"); var clock = Clock(); var expiration = clock.UtcNow.ToOffset().AddHours(-1); var service = new FakeSingleUseTokenServiceBase(clock) { Retrieve_Output_Expiration = expiration }; Assert.False(await service.Validate(token)); }
public async Task TokenExpired_DeletesToken() { var token = new SingleUseToken("token"); var clock = Clock(); var expiration = clock.UtcNow.ToOffset().AddHours(-1); var service = new FakeSingleUseTokenServiceBase(clock) { Retrieve_Output_Expiration = expiration }; await service.Validate(token); Assert.Equal(token.Value, service.Delete_InputData_Value); Assert.Equal(expiration, service.Delete_InputData_Expiration); }