本文整理汇总了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);
}
示例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);
}
示例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));
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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));
}
示例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));
}
示例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);
}