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


C# TestContext.GetRestClient方法代码示例

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


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

示例1: RestClientGetRequestReturnsResponse

        public async Task RestClientGetRequestReturnsResponse()
        {
            var tc = new TestContext();

            var client = tc.GetRestClient();

            var anyRequest = new RestRequest
            {
                Method = Method.GET,
                Resource = AnyResource,
                RootElement = AnyRootElement
            };

            var successfulResponseMessage = CreateSuccessfulResponseMessage();
            tc.HttpClient.GetAsync(AnyRequestUri + anyRequest.Resource, CancellationToken.None)
                .Returns(Task.FromResult(successfulResponseMessage));

            var response =
                await client.ExecuteRequestAsync<AnyResponse>(anyRequest, AnyRequestUri, CancellationToken.None);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(AnyStringField, response.Data.AnyStringField);
            Assert.Equal(AnyIntField, response.Data.AnyIntField);
            Assert.Null(response.Exception);
            var unused = tc.HttpClient.Received(1).GetAsync(AnyRequestUri + anyRequest.Resource, CancellationToken.None);
        }
开发者ID:beomyeol,项目名称:reef,代码行数:26,代码来源:RestClientTests.cs

示例2: RestClientPostRequestReturnsResponse

        public async Task RestClientPostRequestReturnsResponse()
        {
            var tc = new TestContext();

            var client = tc.GetRestClient();

            var anyRequest = new RestRequest
            {
                Method = Method.POST,
                Resource = AnyResource,
                RootElement = AnyRootElement,
                Content = new StringContent(AnyPostContent, Encoding, MediaType)
            };

            var successfulResponseMessage = CreateSuccessfulResponseMessage();
            tc.HttpClient.PostAsync(AnyRequestUri + anyRequest.Resource,
                Arg.Is<StringContent>(
                    stringContent =>
                        stringContent.Headers.ContentType.MediaType == MediaType &&
                        stringContent.ReadAsStringAsync().Result == AnyPostContent),
                CancellationToken.None)
                .Returns(Task.FromResult(successfulResponseMessage));

            var response =
                await client.ExecuteRequestAsync<AnyResponse>(anyRequest, AnyRequestUri, CancellationToken.None);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(AnyStringField, response.Data.AnyStringField);
            Assert.Equal(AnyIntField, response.Data.AnyIntField);
            Assert.Null(response.Exception);
            var unused = tc.HttpClient.Received(1).PostAsync(AnyRequestUri + anyRequest.Resource,
                Arg.Is<StringContent>(
                    stringContent =>
                        stringContent.Headers.ContentType.MediaType == MediaType &&
                        stringContent.ReadAsStringAsync().Result == AnyPostContent),
                CancellationToken.None);
        }
开发者ID:beomyeol,项目名称:reef,代码行数:37,代码来源:RestClientTests.cs

示例3: RestClientRequestReturnsFailureResponse

        public async Task RestClientRequestReturnsFailureResponse()
        {
            var tc = new TestContext();

            var client = tc.GetRestClient();

            var anyRequest = new RestRequest
            {
                Method = Method.GET,
                Resource = AnyResource,
                RootElement = AnyRootElement
            };

            var successfulResponseMessage = CreateFailedResponseMessage();
            tc.HttpClient.GetAsync(AnyRequestUri + anyRequest.Resource, CancellationToken.None)
                .Returns(Task.FromResult(successfulResponseMessage));

            var response =
                await client.ExecuteRequestAsync<AnyResponse>(anyRequest, AnyRequestUri, CancellationToken.None);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.Null(response.Data);
            Assert.NotNull(response.Exception);
            Assert.IsType(typeof(HttpRequestException), response.Exception);
            var unused = tc.HttpClient.Received(1).GetAsync(AnyRequestUri + anyRequest.Resource, CancellationToken.None);
        }
开发者ID:beomyeol,项目名称:reef,代码行数:26,代码来源:RestClientTests.cs


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