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