当前位置: 首页>>代码示例>>C#>>正文


C# RestClient.GetAsync方法代码示例

本文整理汇总了C#中RestClient.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.GetAsync方法的具体用法?C# RestClient.GetAsync怎么用?C# RestClient.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestClient的用法示例。


在下文中一共展示了RestClient.GetAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAsyncReturnsHttpResponseExceptionTest

        public async Task GetAsyncReturnsHttpResponseExceptionTest()
        {
            var responseMessage = HttpClientHelper.SetupHttpResponseMessage(HttpStatusCode.NotFound, new JsonContent(new List<TestResponseClass>()));
            var fakeMessageHandler = new FakeHttpMessageHandler(responseMessage);
            var httpClient = HttpClientHelper.SetupHttpClient(fakeMessageHandler);
            var sut = new RestClient(httpClient);

            await sut.GetAsync<object>("GetAsync");
        }
开发者ID:intellectual-property-office,项目名称:Services,代码行数:9,代码来源:RestApiClientWrapperGetAsyncTests.cs

示例2: GetResource_RelativeRequestUriAndMissingBaseAddress_ThrowsImmediately

        public async Task GetResource_RelativeRequestUriAndMissingBaseAddress_ThrowsImmediately()
        {
            // Arrange
            var client = new RestClient();
            var task = client.GetAsync<Post>(new Uri("post/1", UriKind.Relative));

            // Assert
            await task.AssertThrows<InvalidOperationException>();
        }
开发者ID:stevenvolckaert,项目名称:autodesk-inventor-powertools,代码行数:9,代码来源:RestClientFixture.cs

示例3: GetAsyncReturnsCorrectClassTypeTest

        public async Task GetAsyncReturnsCorrectClassTypeTest()
        {
            var responseMessage = HttpClientHelper.SetupHttpResponseMessage(HttpStatusCode.OK, new JsonContent(new List<TestResponseClass>()));
            var fakeMessageHandler = new FakeHttpMessageHandler(responseMessage);
            var httpClient = HttpClientHelper.SetupHttpClient(fakeMessageHandler);
            var sut = new RestClient(httpClient);

            var result = await sut.GetAsync<TestResponseClass>("GetAsync");
            Assert.AreEqual(typeof(List<TestResponseClass>), result.GetType());
        }
开发者ID:intellectual-property-office,项目名称:Services,代码行数:10,代码来源:RestApiClientWrapperGetAsyncTests.cs

示例4: Should_get_bson

        public async Task Should_get_bson()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);

                var foos = await restClient.GetAsync<Foo>("/api/foos/{0}".FormatUri(1), MediaTypes.ApplicationBson);

                foos.ShouldNotBeNull();
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:11,代码来源:BsonTests.cs

示例5: Should_get_xml

        public async Task Should_get_xml()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);

                var foos = await restClient.GetAsync<List<Foo>>("/api/foos", MediaTypes.ApplicationXml);

                foos.Count.ShouldEqual(3);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:11,代码来源:Tests.cs

示例6: RestClientCallsCorrectRouteTest

        public async Task RestClientCallsCorrectRouteTest()
        {
            var responseMessage = HttpClientHelper.SetupHttpResponseMessage(HttpStatusCode.OK, new JsonContent(new List<TestResponseClass>()));
            var fakeMessageHandler = new FakeHttpMessageHandler(responseMessage);
            var httpClient = HttpClientHelper.SetupHttpClient(fakeMessageHandler, new Uri("http://localhost/WebApi/"));
            var sut = new RestClient(httpClient);

            await sut.GetAsync<TestResponseClass>("GetAsync");

            Assert.AreEqual(fakeMessageHandler.Request.RequestUri, "http://localhost/WebApi/GetAsync");
        }
开发者ID:intellectual-property-office,项目名称:Services,代码行数:11,代码来源:RestApiClientWrapperGetAsyncTests.cs

示例7: Should_get_bson_simple_type

        public async Task Should_get_bson_simple_type()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);

                var parameters = new Dictionary<string, string> { { "param", "a_param" } };
                var foo = await restClient.GetAsync<int>("/api/foos", null, parameters);

                foo.ShouldNotEqual(0);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:12,代码来源:BsonTests.cs

示例8: GetResourceList_Succeeds

        public void GetResourceList_Succeeds()
        {
            // Arrange
            var client = new RestClient(_baseAddress);

            // Act
            var response = client.GetAsync<IEnumerable<Post>>(new Uri("posts", UriKind.Relative)).Result;

            // Assert
            Assert.IsTrue(response.Succeeded);
            Assert.IsTrue(response.Data.Any());
        }
开发者ID:stevenvolckaert,项目名称:autodesk-inventor-powertools,代码行数:12,代码来源:RestClientFixture.cs

示例9: GetResourceList_Fails

        public async Task GetResourceList_Fails()
        {
            // Arrange
            var client = new RestClient(_incorrectBaseAddress);

            // Act
            var response = await client.GetAsync<IEnumerable<Post>>(new Uri("posts", UriKind.Relative));

            // Assert
            Assert.IsFalse(response.Succeeded);
            Assert.IsTrue(response.Data == null);
        }
开发者ID:stevenvolckaert,项目名称:autodesk-inventor-powertools,代码行数:12,代码来源:RestClientFixture.cs

示例10: Should_handle_not_found_when_getting_json

        public void Should_handle_not_found_when_getting_json()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);

                var aggregateException = Assert.Throws<AggregateException>(() => restClient.GetAsync<object>("/api/unknown", MediaTypes.ApplicationJson).Result);

                aggregateException.InnerException.ShouldBeType<ApiException>();
                var apiException = (ApiException)aggregateException.InnerException;
                apiException.HttpStatusCode.ShouldEqual(HttpStatusCode.NotFound);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:13,代码来源:Tests.cs

示例11: Should_handle_error_when_getting_xml

        public void Should_handle_error_when_getting_xml()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);
                const string ErrorMessage = "error";

                var aggregateException = Assert.Throws<AggregateException>(() => restClient.GetAsync<object>("/api/error/" + ErrorMessage, MediaTypes.ApplicationXml).Result);

                aggregateException.InnerException.ShouldBeType<ApiException>();
                var apiException = (ApiException)aggregateException.InnerException;
                apiException.ApiError.Message.ShouldEqual(ErrorMessage);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:14,代码来源:Tests.cs

示例12: GetAsync

        public async Task GetAsync()
        {
            var init = Substitute.For<IHttpInitializer>();
            var messager = new FakeMessageHandler(new HttpResponseMessage());
            init.HttpClient.Returns(new HttpClient(messager));
            var rest = new RestClient(init);
            var config = new HttpConfiguration(new Uri("http://happy.ca/"), "route", HttpRequest.Get);
            
            var ads = await rest.GetAsync(config, response => new List<Ad>{new Ad{AdID = Int32.MaxValue}});

            Assert.AreEqual(1, ads.Count(x=>x.AdID==Int32.MaxValue));
            Assert.AreEqual("http://happy.ca/route", messager.RequestMessage.RequestUri.AbsoluteUri);
            Assert.AreEqual(HttpMethod.Get, messager.RequestMessage.Method);
        }
开发者ID:TianyuanC,项目名称:dals,代码行数:14,代码来源:RestClientTests.cs

示例13: QueryAsync

        async static Task QueryAsync()
        {
            var client = new RestClient("http://catfacts-api.appspot.com/api");

            var response = await client.GetAsync<CatFactResponse>(
                    new RestRequest("facts")
                        .WithQueryParameter("number", 5)

                );

            Console.WriteLine("Retrieved " + response.Facts.Count + " cat facts.");
            Console.WriteLine(response.Facts[0]);

            Console.ReadKey();
        }
开发者ID:scottmeyer,项目名称:SlimRest,代码行数:15,代码来源:Program.cs

示例14: GetAsyncReturnsCorrectPopulatedClassTest

        public async Task GetAsyncReturnsCorrectPopulatedClassTest()
        {
            var testResponseClassList = new List<TestResponseClass>
            {
                new TestResponseClass {ResponseContent = "content1"},
                new TestResponseClass {ResponseContent = "content2"},
                new TestResponseClass {ResponseContent = "content3"}
            };

            var responseMessage = HttpClientHelper.SetupHttpResponseMessage(HttpStatusCode.OK, new JsonContent(testResponseClassList));
            var fakeMessageHandler = new FakeHttpMessageHandler(responseMessage);
            var httpClient = HttpClientHelper.SetupHttpClient(fakeMessageHandler);
            var sut = new RestClient(httpClient);

            var result = await sut.GetAsync<TestResponseClass>("GetAsync");
            var resultList = result.ToList();

            Assert.AreEqual(testResponseClassList[0].ResponseContent, resultList[0].ResponseContent);
            Assert.AreEqual(testResponseClassList[1].ResponseContent, resultList[1].ResponseContent);
            Assert.AreEqual(testResponseClassList[2].ResponseContent, resultList[2].ResponseContent);
        }
开发者ID:intellectual-property-office,项目名称:Services,代码行数:21,代码来源:RestApiClientWrapperGetAsyncTests.cs

示例15: Should_throw_exception_for_unkown_client_mediatype

        public void Should_throw_exception_for_unkown_client_mediatype()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);
                restClient.MediaTypeSerializers.Remove(restClient.MediaTypeSerializers.First(x => x is JsonMediaTypeSerializer));

                var aggregateException = Assert.Throws<AggregateException>(() =>
                {
                    var result = restClient.GetAsync<List<Foo>>("/api/foos", MediaTypes.ApplicationJson).Result;
                    return result;
                });

                aggregateException.InnerException.ShouldBeType<NotSupportedException>();
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:16,代码来源:Tests.cs


注:本文中的RestClient.GetAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。