forked from joncloud/https
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTest1.cs
More file actions
63 lines (53 loc) · 1.73 KB
/
UnitTest1.cs
File metadata and controls
63 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;
namespace Https.Tests
{
public class UnitTest1
{
[Fact]
public async Task Test1()
{
var webHost = WebHost.CreateDefaultBuilder()
.UseUrls("http://localhost:5000")
.UseStartup<Startup>()
.Build();
var task = webHost.RunAsync();
var args = new[]
{
"post", "http://localhost:5000", "--json", "foo=bar", "lorem=ipsum"
};
using (var stdin = new MemoryStream())
using (var stdout = new MemoryStream())
using (var stderr = new MemoryStream())
{
await new Program(() => stderr, () => stdin, () => stdout, false)
.RunAsync(args);
stdout.Position = 0;
var json = new StreamReader(stdout).ReadToEnd();
Assert.Equal("{\"foo\":\"bar\",\"lorem\":\"ipsum\"}", json);
stderr.Position = 0;
}
await webHost.StopAsync();
}
}
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Run(async (context) =>
{
if (!string.IsNullOrEmpty(context.Request.ContentType))
{
context.Response.ContentType = context.Request.ContentType;
}
await context.Request.Body.CopyToAsync(context.Response.Body);
});
}
}
}