-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWebHostFixture.cs
More file actions
41 lines (37 loc) · 1.11 KB
/
WebHostFixture.cs
File metadata and controls
41 lines (37 loc) · 1.11 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
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace Https.Tests
{
[CollectionDefinition(nameof(WebHostFixture))]
public class WebHostCollection : ICollectionFixture<WebHostFixture> { }
public class WebHostFixture : IDisposable
{
readonly IWebHost _webHost;
readonly Task _task;
readonly CancellationTokenSource _cts;
public string HttpUrl { get; }
public string HttpsUrl { get; }
public WebHostFixture()
{
_webHost = WebHost.CreateDefaultBuilder()
.UseUrls(
HttpUrl = "http://localhost:5000",
HttpsUrl = "https://localhost:5001"
)
.UseStartup<Startup>()
.Build();
_cts = new CancellationTokenSource();
_task = _webHost.RunAsync(_cts.Token);
}
public async void Dispose()
{
await _webHost.StopAsync();
_cts.Cancel();
_cts.Dispose();
}
}
}