Skip to content

Commit 3137cf2

Browse files
committed
Broken up the tests to avoid port conflicts.
1 parent ec5f862 commit 3137cf2

File tree

4 files changed

+113
-19
lines changed

4 files changed

+113
-19
lines changed

src/Mvc/test/Mvc.FunctionalTests/RealServerBackedIntegrationTests.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,4 @@ public async Task ServerReachableViaGenericHttpClient()
5454
// Assert
5555
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
5656
}
57-
58-
[Fact]
59-
public async Task ServerReachableViaGenericHttpClient_OnSpecificPort()
60-
{
61-
// Arrange
62-
var port = 7777;
63-
var baseAddress = new Uri($"http://localhost:{port}");
64-
65-
// Act
66-
Factory.UseKestrel(port);
67-
Factory.StartServer();
68-
69-
using var client = new HttpClient() { BaseAddress = baseAddress };
70-
71-
using var response = await client.GetAsync("/");
72-
73-
// Assert
74-
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
75-
}
7657
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Net.Http.Headers;
7+
8+
namespace Microsoft.AspNetCore.Mvc.FunctionalTests;
9+
10+
public class RealServerWithCustomConfigurationIntegrationTests : IClassFixture<KestrelBasedWapFactory>
11+
{
12+
private int _optionsConfiguredCounter = 0;
13+
14+
public KestrelBasedWapFactory Factory { get; }
15+
16+
public RealServerWithCustomConfigurationIntegrationTests(KestrelBasedWapFactory factory)
17+
{
18+
Factory = factory;
19+
Factory.UseKestrel(options => { _optionsConfiguredCounter++; });
20+
}
21+
22+
[Fact]
23+
public async Task ServerReachableViaGenericHttpClient()
24+
{
25+
// Arrange
26+
27+
// Act
28+
Assert.Equal(0, _optionsConfiguredCounter);
29+
Factory.StartServer();
30+
31+
using var client = Factory.CreateClient();
32+
33+
using var response = await client.GetAsync("/");
34+
35+
// Assert
36+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
37+
Assert.Equal(1, _optionsConfiguredCounter);
38+
}
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Net.Http.Headers;
7+
8+
namespace Microsoft.AspNetCore.Mvc.FunctionalTests;
9+
10+
public class RealServerWithDynamicPortIntegrationTests : IClassFixture<KestrelBasedWapFactory>
11+
{
12+
public KestrelBasedWapFactory Factory { get; }
13+
14+
public RealServerWithDynamicPortIntegrationTests(KestrelBasedWapFactory factory)
15+
{
16+
Factory = factory;
17+
18+
// Use dynamic port
19+
Factory.UseKestrel(0);
20+
}
21+
22+
[Fact]
23+
public async Task ServerReachableViaGenericHttpClient()
24+
{
25+
// Arrange
26+
using var client = new HttpClient();
27+
using var factoryClient = Factory.CreateClient();
28+
client.BaseAddress = factoryClient.BaseAddress;
29+
30+
// Act
31+
using var response = await client.GetAsync("/");
32+
33+
// Assert
34+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Net.Http.Headers;
7+
8+
namespace Microsoft.AspNetCore.Mvc.FunctionalTests;
9+
10+
public class RealServerWithSpecifiedPortBackedIntegrationTests : IClassFixture<KestrelBasedWapFactory>
11+
{
12+
private const int ServerPort = 7777;
13+
14+
public KestrelBasedWapFactory Factory { get; }
15+
16+
public RealServerWithSpecifiedPortBackedIntegrationTests(KestrelBasedWapFactory factory)
17+
{
18+
Factory = factory;
19+
Factory.UseKestrel(ServerPort);
20+
}
21+
22+
[Fact]
23+
public async Task ServerReachableViaGenericHttpClient_OnSpecificPort()
24+
{
25+
// Arrange
26+
var baseAddress = new Uri($"http://localhost:{ServerPort}");
27+
28+
// Act
29+
Factory.StartServer();
30+
31+
using var client = new HttpClient() { BaseAddress = baseAddress };
32+
33+
using var response = await client.GetAsync("/");
34+
35+
// Assert
36+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
37+
}
38+
}

0 commit comments

Comments
 (0)