示例#1
0
 public async Task History_WithStartBeforeEnd_Throws()
 {
     await Assert.ThrowsAsync <AblyException>(() =>
                                              _channel.Presence.HistoryAsync(new PaginatedRequestParams {
         Start = Now, End = Now.AddHours(-1)
     }));
 }
示例#2
0
 public WithInvalidToken(ITestOutputHelper output) : base(output)
 {
     _returnedDummyTokenDetails = new TokenDetails("123")
     {
         Expires = Now.AddDays(1), ClientId = "123"
     };
 }
示例#3
0
            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);
            }
示例#4
0
        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));
        }
示例#5
0
            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");
            }
示例#6
0
        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());
        }
示例#7
0
            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");
            }
示例#8
0
 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"
         };
     }));
 }
示例#9
0
        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));
        }
示例#10
0
        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());
        }
示例#11
0
            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");
            }
示例#12
0
            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");
            }
示例#13
0
        public void NowAdd(TimeSpan ts)
        {
            DateTimeOffset n = Now.Add(ts);

            SetNowFunc(() => n);
        }
示例#14
0
        public void Now_ValueFunctionReturnsValueProperty()
        {
            var now = new Now();

            now.Value.Should().Be(now.ValueFn());
        }