コード例 #1
0
        public async Task Request_SimpleGet(Protocol protocol)
        {
            var client = TrackLastRequest(await GetRestClient(protocol));

            var testParams = new Dictionary <string, string> {
                { "testParams", "testParamValue" }
            };
            var testHeaders = new Dictionary <string, string> {
                { "X-Test-Header", "testHeaderValue" }
            };

            var paginatedResponse = await client.Request(HttpMethod.Get.Method, _channelPath, testParams, null, testHeaders);

            _lastRequest.Headers.Should().ContainKey("Authorization");
            _lastRequest.Headers.Should().ContainKey("X-Test-Header");
            _lastRequest.Headers["X-Test-Header"].Should().Be("testHeaderValue");
            paginatedResponse.Should().NotBeNull();
            paginatedResponse.StatusCode.Should().Be(HttpStatusCode.OK); // 200
            paginatedResponse.Success.Should().BeTrue();
            paginatedResponse.ErrorCode.Should().Be(0);
            paginatedResponse.ErrorMessage.Should().BeNull();
            paginatedResponse.Items.Should().HaveCount(1);
            paginatedResponse.Items.First().Should().BeOfType <JObject>();
            paginatedResponse.Response.ContentType.Should().Be(AblyHttpClient.GetHeaderValue(protocol));
            var channelDetails = paginatedResponse.Items.First() as JObject; // cast from JToken

            channelDetails["channelId"].ToString().Should().BeEquivalentTo(_channelName);
        }
コード例 #2
0
        public async Task Request_PaginatedWithLimit(Protocol protocol)
        {
            var client = TrackLastRequest(await GetRestClient(protocol));

            var testParams = new Dictionary <string, string> {
                { "prefix", _channelNamePrefix }, { "limit", "1" }
            };

            var paginatedResponse = await client.Request(HttpMethod.Get, _channelsPath, testParams);

            _lastRequest.Headers.Should().ContainKey("Authorization");
            paginatedResponse.Should().NotBeNull();
            paginatedResponse.StatusCode.Should().Be(HttpStatusCode.OK); // 200
            paginatedResponse.Success.Should().BeTrue();
            paginatedResponse.ErrorCode.Should().Be(0);
            paginatedResponse.Response.ContentType.Should().Be(AblyHttpClient.GetHeaderValue(protocol));
            var items = paginatedResponse.Items;

            items.Should().HaveCount(1);
            foreach (var item in items)
            {
                (item as JObject)["channelId"].ToString().Should().StartWith(_channelNamePrefix);
            }

            var page2 = await paginatedResponse.NextAsync();

            page2.Items.Should().HaveCount(1);
            page2.StatusCode.Should().Be(HttpStatusCode.OK); // 200
            page2.Success.Should().BeTrue();
            page2.ErrorCode.Should().Be(0);
            page2.Response.ContentType.Should().Be(AblyHttpClient.GetHeaderValue(protocol));

            // show that the 2 pages are different
            var item1 = items[0] as JObject;
            var item2 = page2.Items[0] as JObject;

            item1["channelId"].ToString().Should().NotBe(item2["channelId"].ToString());
        }
コード例 #3
0
        public async Task Request_Post(Protocol protocol)
        {
            var client = TrackLastRequest(await GetRestClient(protocol));

            var body1 = JToken.Parse("{ \"name\": \"rsc19test\", \"data\": \"from-json-string\" }");
            var body2 = JToken.FromObject(new Message("rsc19test", "from-message"));

            var paginatedResponse = await client.Request(HttpMethod.Post, _channelMessagesPath, null, body1);

            _lastRequest.Headers.Should().ContainKey("Authorization");
            paginatedResponse.Should().NotBeNull();
            paginatedResponse.StatusCode.Should().Be(HttpStatusCode.Created); // 201
            paginatedResponse.Success.Should().BeTrue();
            paginatedResponse.ErrorCode.Should().Be(0);
            paginatedResponse.ErrorMessage.Should().BeNull();
            paginatedResponse.Response.ContentType.Should().Be(AblyHttpClient.GetHeaderValue(protocol));

            await client.Request(HttpMethod.Post, _channelMessagesPath, null, body2);

            var ch    = client.Channels.Get(_channelName);
            var body3 = new Message("rsc19test", "from-publish");

            ch.Publish(body3);

            await Task.Delay(1000);

            var paginatedResult = client.Channels.Get(_channelName).History(new PaginatedRequestParams {
                Limit = 3
            });

            paginatedResult.Should().NotBeNull();
            paginatedResult.Items.Should().HaveCount(3);
            paginatedResult.Items[2].Data.Should().BeEquivalentTo("from-json-string");
            paginatedResult.Items[1].Data.Should().BeEquivalentTo("from-message");
            paginatedResult.Items[0].Data.Should().BeEquivalentTo("from-publish");
        }
コード例 #4
0
        public async Task Request_Paginated(Protocol protocol)
        {
            var client = TrackLastRequest(await GetRestClient(protocol));

            var testParams = new Dictionary <string, string> {
                { "prefix", _channelNamePrefix }
            };

            var paginatedResponse = await client.Request(HttpMethod.Get, _channelsPath, testParams);

            _lastRequest.Headers.Should().ContainKey("Authorization");
            paginatedResponse.Should().NotBeNull();
            paginatedResponse.StatusCode.Should().Be(HttpStatusCode.OK); // 200
            paginatedResponse.Success.Should().BeTrue();
            paginatedResponse.ErrorCode.Should().Be(0);
            paginatedResponse.Response.ContentType.Should().Be(AblyHttpClient.GetHeaderValue(protocol));
            var items = paginatedResponse.Items;

            items.Should().HaveCount(2);
            foreach (var item in items)
            {
                (item as JObject)["channelId"].ToString().Should().StartWith(_channelNamePrefix);
            }
        }