public async Task History_WithStartBeforeEnd_Throws() { await Assert.ThrowsAsync <AblyException>(() => _channel.Presence.HistoryAsync(new PaginatedRequestParams { Start = Now, End = Now.AddHours(-1) })); }
public WithInvalidToken(ITestOutputHelper output) : base(output) { _returnedDummyTokenDetails = new TokenDetails("123") { Expires = Now.AddDays(1), ClientId = "123" }; }
public async Task WhenErrorCodeIsTokenSpecific_ShouldAutomaticallyTryToRenewTokenIfRequestFails(int errorCode) { //Now = DateTimeOffset.Now; var tokenDetails = new TokenDetails("id") { Expires = Now.AddHours(1) }; //Had to inline the method otherwise the tests intermittently fail. bool firstAttempt = true; var client = GetRestClient(request => { if (request.Url.Contains("/keys")) { return(_returnedDummyTokenDetails.ToJson().ToAblyResponse()); } if (firstAttempt) { firstAttempt = false; throw new AblyException(new ErrorInfo("", errorCode, HttpStatusCode.Unauthorized)); } return(AblyResponse.EmptyResponse.ToTask()); }, opts => opts.TokenDetails = tokenDetails); await client.StatsAsync(); client.AblyAuth.CurrentToken.Expires.Should().BeCloseTo(_returnedDummyTokenDetails.Expires); client.AblyAuth.CurrentToken.ClientId.Should().Be(_returnedDummyTokenDetails.ClientId); }
public void ShouldThrowIfStartIsGreaterThanEnd(int startOffset, int endOffset, QueryDirection direction) { var query = new StatsRequestParams { Start = Now.AddHours(startOffset), End = Now.AddHours(endOffset), Direction = direction }; ThrowsAsync <AblyException>(() => ExecuteStatsQuery(query)); }
public async Task WithDefaultTokenParams_ShouldSetTokenRequestValuesCorrectly() { var client = GetClientWithTokenParams(); var request = await client.Auth.CreateTokenRequestAsync(); request.Capability.Should().Be(Capability.AllowAll); request.ClientId.Should().Be("123"); request.KeyName.Should().Be(ApiKey.Parse(client.Options.Key).KeyName); request.Ttl.Should().Be(TimeSpan.FromHours(2)); request.Timestamp.Should().Be(Now.AddMinutes(1)); request.Nonce.Should().Be("defaultnonce"); }
public async Task ShouldAcceptStartAndEndDateTimes(int startOffset, int endOffset, QueryDirection direction) { var query = new StatsRequestParams { Start = Now.AddHours(startOffset), End = Now.AddHours(endOffset), Direction = direction }; await ExecuteStatsQuery(query); LastRequest.AssertContainsParameter("start", query.Start.Value.ToUnixTimeInMilliseconds().ToString()); LastRequest.AssertContainsParameter("end", query.End.Value.ToUnixTimeInMilliseconds().ToString()); }
public async Task WithDefaultTokenParams_ShouldSetTokenRequestValuesCorrectly() { var client = GetClientWithTokenParams(); var request = await CreateTokenRequest(client); request.Capability.Should().Be(Capability.AllowAll); request.ClientId.Should().Be("123"); request.KeyName.Should().Be(ApiKey.Parse(client.Options.Key).KeyName); request.Ttl.Should().Be(TimeSpan.FromHours(2)); Debug.Assert(request.Timestamp.HasValue, "Expected a 'Value', got none."); request.Timestamp.Value.Should().BeCloseTo(Now.AddMinutes(1), TimeSpan.FromMilliseconds(100)); request.Nonce.Should().Be("defaultnonce"); }
private AblyRest GetClientWithTokenParams() { return(GetRestClient(null, options => { options.DefaultTokenParams = new TokenParams { Ttl = TimeSpan.FromHours(2), Capability = Capability.AllowAll, ClientId = "123", Timestamp = Now.AddMinutes(1), Nonce = "defaultnonce" }; })); }
public void Now_ResetUpdatesValue() { var now = new Now(); var oldNow = now.Value; const int delta = 500; var newNow = oldNow.AddMilliseconds(delta); now.Reset(newNow); now.Value.Should().Be(newNow); (now.Value - oldNow).Should().BeGreaterOrEqualTo(TimeSpan.FromMilliseconds(delta)); }
public async Task ShouldSetCorrectHeaders() { var rest = GetRestClient(); var query = new StatsRequestParams { Start = Now.AddHours(-1), End = Now, Direction = QueryDirection.Forwards, Limit = 1000 }; await rest.StatsAsync(query); LastRequest.AssertContainsParameter("start", query.Start.Value.ToUnixTimeInMilliseconds().ToString()); LastRequest.AssertContainsParameter("end", query.End.Value.ToUnixTimeInMilliseconds().ToString()); LastRequest.AssertContainsParameter("direction", query.Direction.ToString().ToLower()); LastRequest.AssertContainsParameter("limit", query.Limit.Value.ToString()); }
public async Task WithOverrideTokenParams_ShouldSetTokenRequestValuesCorrectly() { var client = GetClientWithTokenParams(); var overridingTokenParams = new TokenParams() { Ttl = TimeSpan.FromHours(1), ClientId = "999", Capability = new Capability(), Nonce = "overrideNonce", Timestamp = Now.AddMinutes(10) }; var request = await client.Auth.CreateTokenRequestAsync(overridingTokenParams); request.Capability.Should().Be(Capability.Empty); request.ClientId.Should().Be("999"); request.Ttl.Should().Be(TimeSpan.FromHours(1)); request.Timestamp.Should().Be(Now.AddMinutes(10)); request.Nonce.Should().Be("overrideNonce"); }
public async Task WithOverrideTokenParams_ShouldSetTokenRequestValuesCorrectly() { var client = GetClientWithTokenParams(); var overridingTokenParams = new TokenParams { Ttl = TimeSpan.FromHours(1), ClientId = "999", Capability = new Capability(), Nonce = "overrideNonce", Timestamp = Now.AddMinutes(10) }; var request = await CreateTokenRequest(client, overridingTokenParams); request.Capability.Should().Be(Capability.Empty); request.ClientId.Should().Be("999"); request.Ttl.Should().Be(TimeSpan.FromHours(1)); Debug.Assert(request.Timestamp.HasValue, "Expected a 'Value', got none."); request.Timestamp.Value.Should().BeCloseTo(Now.AddMinutes(10), TimeSpan.FromMilliseconds(500)); request.Nonce.Should().Be("overrideNonce"); }
public void NowAdd(TimeSpan ts) { DateTimeOffset n = Now.Add(ts); SetNowFunc(() => n); }
public void Now_ValueFunctionReturnsValueProperty() { var now = new Now(); now.Value.Should().Be(now.ValueFn()); }