-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTests.cs
110 lines (94 loc) · 2.43 KB
/
Tests.cs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
public class Tests
{
[Fact]
public Task ChallengeResult()
{
var result = new ChallengeResult(
"scheme",
new(
new Dictionary<string, string?>
{
{
"key", "value"
}
}));
return Verify(result);
}
[Fact]
public Task HttpContext()
{
var context = new DefaultHttpContext
{
Items = new Dictionary<object, object?>
{
{
"item1", "value1"
}
},
Connection =
{
Id = "ConnectionId"
}
};
return Verify(context);
}
[Fact]
public Task EmptyHttpContext() =>
Verify(new DefaultHttpContext());
[Fact]
public Task HeaderDictionary() =>
Verify(new HeaderDictionary
{
{"key", "value"}
});
[Fact]
public Task FileContentResult()
{
var result = new FileContentResult("the content"u8.ToArray(), "text/plain");
return Verify(result);
}
[Fact]
public Task FileStreamResult()
{
var stream = new MemoryStream("the content"u8.ToArray());
var result = new FileStreamResult(stream, "text/plain");
return Verify(result);
}
[Fact]
public Task PhysicalFileResult()
{
var result = new PhysicalFileResult("target.txt", "text/plain");
return Verify(result);
}
[Fact]
public Task VirtualFileResult()
{
var result = new VirtualFileResult("target.txt", "text/plain");
return Verify(result);
}
#region TestController
[Fact]
public async Task ControllerIntegrationTest()
{
var builder = WebApplication.CreateBuilder();
var controllers = builder.Services.AddControllers();
// custom extension
controllers.UseSpecificControllers(typeof(FooController));
await using var app = builder.Build();
app.MapControllers();
await app.StartAsync();
using var client = new HttpClient();
var result = client.GetStringAsync($"{app.Urls.First()}/Foo");
await Verify(result);
}
[ApiController]
[Route("[controller]")]
public class FooController :
ControllerBase
{
[HttpGet]
public string Get() =>
"Foo";
}
#endregion
}