Skip to content

Commit 12e1959

Browse files
committed
Adds tests for various http methods
1 parent a7621c0 commit 12e1959

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/https.Tests/MethodTests.cs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.IO;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
using System.Xml.Linq;
5+
using Xunit;
6+
7+
namespace Https.Tests
8+
{
9+
[Collection(nameof(WebHostFixture))]
10+
public class MethodTests
11+
{
12+
readonly WebHostFixture _fixture;
13+
public MethodTests(WebHostFixture fixture) =>
14+
_fixture = fixture;
15+
16+
[Fact]
17+
public async Task MethodTest_ShouldHandleHead()
18+
{
19+
var args = new[]
20+
{
21+
"head", $"{_fixture.HttpUrl}/Mirror"
22+
};
23+
24+
var result = await Https.ExecuteAsync(args);
25+
26+
var actual = new StreamReader(result.StdOut).ReadToEnd();
27+
Assert.Equal("", actual);
28+
Assert.Equal(0, result.ExitCode);
29+
}
30+
31+
// Most of these methods probably should be tested differently,
32+
// but apparently they work through HttpClient and ASP.NET Core.
33+
[InlineData(nameof(HttpMethod.Delete))]
34+
[InlineData(nameof(HttpMethod.Get))]
35+
[InlineData(nameof(HttpMethod.Options))]
36+
[InlineData(nameof(HttpMethod.Patch))]
37+
[InlineData(nameof(HttpMethod.Post))]
38+
[InlineData(nameof(HttpMethod.Put))]
39+
[InlineData(nameof(HttpMethod.Trace))]
40+
[Theory]
41+
public async Task MethodTest_ShouldHandleMethod(string method)
42+
{
43+
var args = new[]
44+
{
45+
method, $"{_fixture.HttpUrl}/Mirror", "--form", "foo=bar", "lorem=ipsum"
46+
};
47+
48+
var result = await Https.ExecuteAsync(args);
49+
50+
var actual = new StreamReader(result.StdOut).ReadToEnd();
51+
Assert.Equal("foo=bar&lorem=ipsum", actual);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)