Skip to content

Commit a007698

Browse files
committed
Adds tests for forms and xml
1 parent feb9892 commit a007698

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

tests/https.Tests/IntegrationTests.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.IO;
2+
using System.Text;
23
using System.Threading.Tasks;
4+
using System.Xml;
5+
using System.Xml.Linq;
36
using Xunit;
47

58
namespace Https.Tests
@@ -11,7 +14,21 @@ public IntegrationTests(WebHostFixture fixture) =>
1114
_fixture = fixture;
1215

1316
[Fact]
14-
public async Task MirrorTests()
17+
public async Task MirrorTest_ShouldReflectFormUrlEncoded()
18+
{
19+
var args = new[]
20+
{
21+
"post", $"{_fixture.Url}/Mirror", "--form", "foo=bar", "lorem=ipsum"
22+
};
23+
24+
var result = await Https.ExecuteAsync(args);
25+
26+
var actual = new StreamReader(result.StdOut).ReadToEnd();
27+
Assert.Equal("foo=bar&lorem=ipsum", actual);
28+
}
29+
30+
[Fact]
31+
public async Task MirrorTest_ShouldReflectJson()
1532
{
1633
var args = new[]
1734
{
@@ -20,8 +37,32 @@ public async Task MirrorTests()
2037

2138
var result = await Https.ExecuteAsync(args);
2239

23-
var json = new StreamReader(result.StdOut).ReadToEnd();
24-
Assert.Equal("{\"foo\":\"bar\",\"lorem\":\"ipsum\"}", json);
40+
var actual = new StreamReader(result.StdOut).ReadToEnd();
41+
Assert.Equal("{\"foo\":\"bar\",\"lorem\":\"ipsum\"}", actual);
42+
}
43+
44+
[Fact]
45+
public async Task MirrorTest_ShouldReflectXml()
46+
{
47+
var args = new[]
48+
{
49+
"post", $"{_fixture.Url}/Mirror", "--xml=root", "foo=bar", "lorem=ipsum"
50+
};
51+
52+
var result = await Https.ExecuteAsync(args);
53+
54+
var expected = new XDocument(
55+
new XElement(
56+
"root",
57+
new XElement("foo", "bar"),
58+
new XElement("lorem", "ipsum")
59+
)
60+
).ToString();
61+
var actual = XDocument.Load(
62+
new StreamReader(result.StdOut)
63+
).ToString();
64+
65+
Assert.Equal(expected, actual);
2566
}
2667

2768
[Fact]

0 commit comments

Comments
 (0)