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


C# RequestInfo.SetBodyParameterInfo方法代码示例

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


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

示例1: SetsContentNullIfBodyValueIsNull

 public void SetsContentNullIfBodyValueIsNull()
 {
     var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
     requestInfo.SetBodyParameterInfo<object>(BodySerializationMethod.Serialized, null);
     var content = this.requester.ConstructContent(requestInfo);
     Assert.Null(content);
 }
开发者ID:modulexcite,项目名称:RestEase,代码行数:7,代码来源:ContentConstructionTests.cs

示例2: SetsContentAsStringContentIfBodyIsString

        public void SetsContentAsStringContentIfBodyIsString()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.SetBodyParameterInfo(BodySerializationMethod.Serialized, "hello");
            var content = this.requester.ConstructContent(requestInfo);

            Assert.IsType<StringContent>(content);
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:8,代码来源:ContentConstructionTests.cs

示例3: SetsContentAsHttpContentIfBodyIsHttpContent

        public void SetsContentAsHttpContentIfBodyIsHttpContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            var content = new StringContent("test");
            requestInfo.SetBodyParameterInfo(BodySerializationMethod.Serialized, content);

            Assert.Equal(content, this.requester.ConstructContent(requestInfo));
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:8,代码来源:ContentConstructionTests.cs

示例4: UsesRequestBodySerializerIfContentBodyIsObjectAndMethodIsSerialized

        public void UsesRequestBodySerializerIfContentBodyIsObjectAndMethodIsSerialized()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            var body = new object();
            requestInfo.SetBodyParameterInfo(BodySerializationMethod.Serialized, body);

            var requestBodySerializer = new Mock<IRequestBodySerializer>();
            this.requester.RequestBodySerializer = requestBodySerializer.Object;

            requestBodySerializer.Setup(x => x.SerializeBody(body)).Returns(new StringContent("test")).Verifiable();
            var content = this.requester.ConstructContent(requestInfo);

            requestBodySerializer.Verify();
            Assert.IsType<StringContent>(content);
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:15,代码来源:ContentConstructionTests.cs

示例5: HeadersFromClassOverrideHeadersFromSerializer

        public void HeadersFromClassOverrideHeadersFromSerializer()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.ClassHeaders = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string, string>("Content-Type", "foo/bar"),
            };
            requestInfo.SetBodyParameterInfo<object>(BodySerializationMethod.Serialized, new object());

            var message = new HttpRequestMessage();
            message.Content = this.requester.ConstructContent(requestInfo);
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("Content-Type: foo/bar\r\n", message.Content.Headers.ToString());
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:15,代码来源:HeadersTests.cs

示例6: AppliesHeadersFromSerializer

        public void AppliesHeadersFromSerializer()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.SetBodyParameterInfo<object>(BodySerializationMethod.Serialized, new object());

            var message = new HttpRequestMessage();
            message.Content = this.requester.ConstructContent(requestInfo);
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("Content-Type: application/json; charset=utf-8\r\n", message.Content.Headers.ToString());
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:11,代码来源:HeadersTests.cs

示例7: UsesFormUrlEncodedSerializerIfBodyIsGenericDictionaryAndMethodIsUrlEncoded

        public void UsesFormUrlEncodedSerializerIfBodyIsGenericDictionaryAndMethodIsUrlEncoded()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            // ExpandoObject implements IDictionary<string, object> but not IDictionary
            dynamic body = new ExpandoObject();
            body.foo = "bar woo";
            body.many = new List<string>() { "one", "two" };
            requestInfo.SetBodyParameterInfo(BodySerializationMethod.UrlEncoded, body);

            var content = this.requester.ConstructContent(requestInfo);

            Assert.IsType<FormUrlEncodedContent>(content);
            var encodedContent = ((FormUrlEncodedContent)content).ReadAsStringAsync().Result;
            Assert.Equal("foo=bar+woo&many=one&many=two", encodedContent);
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:15,代码来源:ContentConstructionTests.cs

示例8: ThrowsIfBodyIsUrlEncodedAndBodyDoesNotImplementIDictionary

        public void ThrowsIfBodyIsUrlEncodedAndBodyDoesNotImplementIDictionary()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            var body = new object();
            requestInfo.SetBodyParameterInfo(BodySerializationMethod.UrlEncoded, body);

            Assert.Throws<ArgumentException>(() => this.requester.ConstructContent(requestInfo));
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:8,代码来源:ContentConstructionTests.cs

示例9: ThrowsIfBodySerializationMethodIsUnknown

        public void ThrowsIfBodySerializationMethodIsUnknown()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.SetBodyParameterInfo((BodySerializationMethod)100, new object());

            Assert.Throws<InvalidOperationException>(() => this.requester.ConstructContent(requestInfo));
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:7,代码来源:ContentConstructionTests.cs

示例10: UsesFormUrlEncodedSerializerIfBodyIsNonGenericDictionaryAndMethodIsUrlEncoded

        public void UsesFormUrlEncodedSerializerIfBodyIsNonGenericDictionaryAndMethodIsUrlEncoded()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            IDictionary body = new Dictionary<string, object>()
            {
                { "foo", "bar woo" },
                { "many", new List<string>() { "one", "two" } },
            };
            requestInfo.SetBodyParameterInfo(BodySerializationMethod.UrlEncoded, body);

            var content = this.requester.ConstructContent(requestInfo);

            Assert.IsType<FormUrlEncodedContent>(content);
            var encodedContent = ((FormUrlEncodedContent)content).ReadAsStringAsync().Result;
            Assert.Equal("foo=bar+woo&many=one&many=two", encodedContent);
        }
开发者ID:modulexcite,项目名称:RestEase,代码行数:16,代码来源:ContentConstructionTests.cs


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