本文整理汇总了C#中HttpRequest.field方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.field方法的具体用法?C# HttpRequest.field怎么用?C# HttpRequest.field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.field方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpRequestWithBody_Should_Not_Allow_Body_For_Request_With_Field
public static void HttpRequestWithBody_Should_Not_Allow_Body_For_Request_With_Field()
{
var Post = new HttpRequest(HttpMethod.Post, "http://localhost");
var Delete = new HttpRequest(HttpMethod.Delete, "http://localhost");
var Patch = new HttpRequest(new HttpMethod("PATCH"), "http://localhost");
var Put = new HttpRequest(HttpMethod.Put, "http://localhost");
var stream = new MemoryStream();
Post.field(stream);
Delete.field(stream);
Patch.field(stream);
Put.field(stream);
Action addBodyPost = () => Post.body("test");
Action addBodyDelete = () => Delete.body("test");
Action addBodyPatch = () => Patch.body("test");
Action addBodyPut = () => Put.body("test");
Action addObjectBodyPost = () => Post.body(1);
Action addObjectBodyDelete = () => Delete.body(1);
Action addObjectBodyPatch = () => Patch.body(1);
Action addObjectBodyPut = () => Put.body(1);
addBodyPost.ShouldThrow<InvalidOperationException>();
addBodyDelete.ShouldThrow<InvalidOperationException>();
addBodyPatch.ShouldThrow<InvalidOperationException>();
addBodyPut.ShouldThrow<InvalidOperationException>();
addObjectBodyPost.ShouldThrow<InvalidOperationException>();
addObjectBodyDelete.ShouldThrow<InvalidOperationException>();
addObjectBodyPatch.ShouldThrow<InvalidOperationException>();
addObjectBodyPut.ShouldThrow<InvalidOperationException>();
}
示例2: Http_Request_Shouldnt_Add_Fields_To_Get
public static void Http_Request_Shouldnt_Add_Fields_To_Get()
{
var Get = new HttpRequest(HttpMethod.Get, "http://localhost");
Action addStringField = () => Get.field("name", "value");
Action addKeyField = () => Get.field(new MemoryStream());
Action addStringFields = () => Get.fields(new Dictionary<string, object> {{"name", "value"}});
Action addKeyFields = () => Get.fields(new Dictionary<string, object> {{"key", new MemoryStream()}});
addStringField.ShouldThrow<InvalidOperationException>();
addKeyField.ShouldThrow<InvalidOperationException>();
addStringFields.ShouldThrow<InvalidOperationException>();
addKeyFields.ShouldThrow<InvalidOperationException>();
}
示例3: HttpRequestWithBody_Should_Not_Allow_Fields_For_Request_With_Body
public static void HttpRequestWithBody_Should_Not_Allow_Fields_For_Request_With_Body()
{
var Post = new HttpRequest(HttpMethod.Post, "http://localhost");
var Delete = new HttpRequest(HttpMethod.Delete, "http://localhost");
var Patch = new HttpRequest(new HttpMethod("PATCH"), "http://localhost");
var Put = new HttpRequest(HttpMethod.Put, "http://localhost");
var stream = new MemoryStream();
Post.body("test");
Delete.body("test");
Patch.body("test");
Put.body("lalala");
Action addFieldPost = () => Post.field("key", "value");
Action addFieldDelete = () => Delete.field("key", "value");
Action addFieldPatch = () => Patch.field("key", "value");
Action addFieldPut = () => Put.field("key", "value");
Action addStreamFieldPost = () => Post.field(stream);
Action addStreamFieldDelete = () => Delete.field(stream);
Action addStreamFieldPatch = () => Patch.field(stream);
Action addStreamFieldPut = () => Put.field(stream);
Action addFieldsPost = () => Post.fields(new Dictionary<string, object> {{"test", "test"}});
Action addFieldsDelete = () => Delete.fields(new Dictionary<string, object> {{"test", "test"}});
Action addFieldsPatch = () => Patch.fields(new Dictionary<string, object> {{"test", "test"}});
Action addFieldsPut = () => Put.fields(new Dictionary<string, object> {{"test", "test"}});
addFieldPost.ShouldThrow<InvalidOperationException>();
addFieldDelete.ShouldThrow<InvalidOperationException>();
addFieldPatch.ShouldThrow<InvalidOperationException>();
addFieldPut.ShouldThrow<InvalidOperationException>();
addStreamFieldPost.ShouldThrow<InvalidOperationException>();
addStreamFieldDelete.ShouldThrow<InvalidOperationException>();
addStreamFieldPatch.ShouldThrow<InvalidOperationException>();
addStreamFieldPut.ShouldThrow<InvalidOperationException>();
addFieldsPost.ShouldThrow<InvalidOperationException>();
addFieldsDelete.ShouldThrow<InvalidOperationException>();
addFieldsPatch.ShouldThrow<InvalidOperationException>();
addFieldsPut.ShouldThrow<InvalidOperationException>();
}
示例4: HttpRequest_With_Body_Should_Encode_File
public static void HttpRequest_With_Body_Should_Encode_File()
{
var Post = new HttpRequest(HttpMethod.Post, "http://localhost");
var Delete = new HttpRequest(HttpMethod.Delete, "http://localhost");
var Patch = new HttpRequest(new HttpMethod("PATCH"), "http://localhost");
var Put = new HttpRequest(HttpMethod.Put, "http://localhost");
var stream = new MemoryStream();
Post.field(stream);
Delete.field(stream);
Patch.field(stream);
Put.field(stream);
Post.Body.Should().NotBe(string.Empty);
Delete.Body.Should().NotBe(string.Empty);
Patch.Body.Should().NotBe(string.Empty);
Put.Body.Should().NotBe(string.Empty);
}
示例5: HttpRequest_With_Body_Should_Encode_Fields
public static void HttpRequest_With_Body_Should_Encode_Fields()
{
var Post = new HttpRequest(HttpMethod.Post, "http://localhost");
var Delete = new HttpRequest(HttpMethod.Delete, "http://localhost");
var Patch = new HttpRequest(new HttpMethod("PATCH"), "http://localhost");
var Put = new HttpRequest(HttpMethod.Put, "http://localhost");
Post.field("key", "value");
Delete.field("key", "value");
Patch.field("key", "value");
Put.field("key", "value");
Post.Body.Should().NotBeEmpty();
Delete.Body.Should().NotBeEmpty();
Patch.Body.Should().NotBeEmpty();
Put.Body.Should().NotBeEmpty();
}