4
4
using System . Diagnostics ;
5
5
using System . Linq ;
6
6
7
+ using Microsoft . AspNetCore ;
7
8
using Microsoft . AspNetCore . Hosting ;
8
9
using Microsoft . AspNetCore . Hosting . Server . Features ;
9
10
using Microsoft . AspNetCore . Mvc . Testing ;
10
11
using Microsoft . AspNetCore . TestHost ;
11
12
using Microsoft . Extensions . DependencyInjection ;
12
13
13
- public class SeleniumServerFactory < TStartup > : WebApplicationFactory < TStartup >
14
+ public sealed class SeleniumServerFactory < TStartup > : WebApplicationFactory < TStartup >
14
15
where TStartup : class
15
16
{
16
17
private readonly Process process ;
@@ -20,6 +21,7 @@ public class SeleniumServerFactory<TStartup> : WebApplicationFactory<TStartup>
20
21
public SeleniumServerFactory ( )
21
22
{
22
23
this . ClientOptions . BaseAddress = new Uri ( "https://localhost" ) ; // will follow redirects by default
24
+ this . CreateServer ( this . CreateWebHostBuilder ( ) ) ;
23
25
24
26
this . process = new Process
25
27
{
@@ -33,11 +35,10 @@ public SeleniumServerFactory()
33
35
this . process . Start ( ) ;
34
36
}
35
37
36
- public string RootUri { get ; set ; } // Save this use by tests
38
+ public string RootUri { get ; set ; }
37
39
38
40
protected override TestServer CreateServer ( IWebHostBuilder builder )
39
41
{
40
- // Real TCP port
41
42
this . host = builder . Build ( ) ;
42
43
this . host . Start ( ) ;
43
44
this . RootUri = this . host . ServerFeatures . Get < IServerAddressesFeature > ( ) . Addresses . LastOrDefault ( ) ; // Last is https://localhost:5001!
@@ -46,6 +47,13 @@ protected override TestServer CreateServer(IWebHostBuilder builder)
46
47
return new TestServer ( new WebHostBuilder ( ) . UseStartup < FakeStartup > ( ) ) ;
47
48
}
48
49
50
+ protected override IWebHostBuilder CreateWebHostBuilder ( )
51
+ {
52
+ var builder = WebHost . CreateDefaultBuilder ( Array . Empty < string > ( ) ) ;
53
+ builder . UseStartup < TStartup > ( ) ;
54
+ return builder ;
55
+ }
56
+
49
57
protected override void Dispose ( bool disposing )
50
58
{
51
59
base . Dispose ( disposing ) ;
0 commit comments