public Task Create(SingleUseToken token, DateTimeOffset expiration) { this.Create_InputToken = token; this.Create_InputExpiration = expiration; return(Task.CompletedTask); }
protected override async Task <SingleUseTokenData?> Retrieve(SingleUseToken token) { Guard.Null(nameof(token), token); var model = await this.Store.Retrieve(token).ConfigureAwait(false); return(model?.ToData()); }
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 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 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 virtual Task Create(SingleUseToken token, UtcDateTime expiration) { Guard.Null(nameof(token), token); var record = new SingleUseTokenData(token, expiration); if (record.IsExpired(this._clock)) { throw new InvalidOperationException("Unable to create this token because it will have already expired."); } return(this.Create(record)); }
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); }
protected override Task <SingleUseTokenData?> Retrieve(SingleUseToken token) { this.Retrieve_InputToken = token; if (this.Retrieve_ShouldReturnData) { this.Retrieve_Output_Value = token.Value; return(Task.FromResult <SingleUseTokenData?>( new SingleUseTokenData(token, new UtcDateTime(this.Retrieve_Output_Expiration)))); } return(Task.FromResult <SingleUseTokenData?>(null)); }
public virtual async Task <bool> Validate(SingleUseToken token) { Guard.Null(nameof(token), token); var record = await this.Retrieve(token).ConfigureAwait(false); if (record != null) { await this.Delete(record).ConfigureAwait(false); if (!record.IsExpired(this._clock)) { return(true); } } return(false); }
public SingleUseTokenData(SingleUseToken token, UtcDateTime expiration) : this(Guard.Null(nameof(token), token).Value, expiration) { }
public Task <bool> Validate(SingleUseToken token) { this.Validate_InputToken = token; return(Task.FromResult(this.Validate_Output)); }
protected static TableEntityKeys CreateKeys(SingleUseToken token) => new TableEntityKeys(Guard.Null(nameof(token), token).Value, "Token");
new public static TableEntityKeys CreateKeys(SingleUseToken token) => TableSingleUseTokenService.CreateKeys(token);
new public Task <SingleUseTokenData?> Retrieve(SingleUseToken token) => base.Retrieve(token);
protected abstract Task <SingleUseTokenData?> Retrieve(SingleUseToken token);