Skip to content

Commit 45c99bb

Browse files
committed
Stop passing --urls to dotnet run
1 parent c64adde commit 45c99bb

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

Source/Boxed.DotnetNewTest/Project.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace Boxed.DotnetNewTest
22
{
3+
using System;
4+
35
/// <summary>
46
/// A project created from a project template.
57
/// </summary>
@@ -11,14 +13,20 @@ public class Project
1113
/// <param name="name">The name of the project.</param>
1214
/// <param name="directoryPath">The directory path to the project.</param>
1315
/// <param name="publishDirectoryPath">The publish directory path.</param>
16+
/// <param name="httpsPort">The HTTPS port.</param>
17+
/// <param name="httpPort">The HTTP port.</param>
1418
public Project(
1519
string name,
1620
string directoryPath,
17-
string publishDirectoryPath)
21+
string publishDirectoryPath,
22+
int httpsPort,
23+
int httpPort)
1824
{
1925
this.Name = name;
2026
this.DirectoryPath = directoryPath;
2127
this.PublishDirectoryPath = publishDirectoryPath;
28+
this.HttpsPort = httpsPort;
29+
this.HttpPort = httpPort;
2230
}
2331

2432
/// <summary>
@@ -35,5 +43,25 @@ public Project(
3543
/// Gets the publish directory path to the project.
3644
/// </summary>
3745
public string PublishDirectoryPath { get; }
46+
47+
/// <summary>
48+
/// Gets the HTTP port.
49+
/// </summary>
50+
public int HttpPort { get; }
51+
52+
/// <summary>
53+
/// Gets the HTTPS port.
54+
/// </summary>
55+
public int HttpsPort { get; }
56+
57+
/// <summary>
58+
/// Gets the HTTP URL.
59+
/// </summary>
60+
public Uri HttpUrl => new Uri($"http://localhost:{this.HttpPort}");
61+
62+
/// <summary>
63+
/// Gets the HTTPS URL.
64+
/// </summary>
65+
public Uri HttpsUrl => new Uri($"https://localhost:{this.HttpsPort}");
3866
}
3967
}

Source/Boxed.DotnetNewTest/ProjectExtensions.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,12 @@ public static async Task DotnetRunAsync(
249249
throw new ArgumentNullException(nameof(action));
250250
}
251251

252-
var httpPort = PortHelper.GetFreeTcpPort();
253-
var httpUrl = new Uri($"http://localhost:{httpPort}");
254-
255252
var httpClientHandler = new HttpClientHandler()
256253
{
257254
AllowAutoRedirect = false,
258255
ServerCertificateCustomValidationCallback = validateCertificate ?? DefaultValidateCertificate,
259256
};
260-
var httpClient = new HttpClient(httpClientHandler) { BaseAddress = httpUrl };
257+
var httpClient = new HttpClient(httpClientHandler) { BaseAddress = project.HttpUrl };
261258

262259
var projectFilePath = Path.Combine(project.DirectoryPath, projectRelativeDirectoryPath);
263260
var dotnetRun = await DotnetRunInternalAsync(
@@ -267,8 +264,7 @@ public static async Task DotnetRunAsync(
267264
projectFilePath,
268265
noRestore,
269266
timeout,
270-
showShellWindow,
271-
httpUrl)
267+
showShellWindow)
272268
.ConfigureAwait(false);
273269

274270
try
@@ -320,18 +316,13 @@ public static async Task DotnetRunAsync(
320316
throw new ArgumentNullException(nameof(action));
321317
}
322318

323-
var httpPort = PortHelper.GetFreeTcpPort();
324-
var httpsPort = PortHelper.GetFreeTcpPort();
325-
var httpUrl = new Uri($"http://localhost:{httpPort}");
326-
var httpsUrl = new Uri($"https://localhost:{httpsPort}");
327-
328319
var httpClientHandler = new HttpClientHandler()
329320
{
330321
AllowAutoRedirect = false,
331322
ServerCertificateCustomValidationCallback = validateCertificate ?? DefaultValidateCertificate,
332323
};
333-
var httpClient = new HttpClient(httpClientHandler) { BaseAddress = httpUrl };
334-
var httpsClient = new HttpClient(httpClientHandler) { BaseAddress = httpsUrl };
324+
var httpClient = new HttpClient(httpClientHandler) { BaseAddress = project.HttpUrl };
325+
var httpsClient = new HttpClient(httpClientHandler) { BaseAddress = project.HttpsUrl };
335326

336327
var projectFilePath = Path.Combine(project.DirectoryPath, projectRelativeDirectoryPath);
337328
var dotnetRun = await DotnetRunInternalAsync(
@@ -341,9 +332,7 @@ public static async Task DotnetRunAsync(
341332
projectFilePath,
342333
noRestore,
343334
timeout,
344-
showShellWindow,
345-
httpUrl,
346-
httpsUrl)
335+
showShellWindow)
347336
.ConfigureAwait(false);
348337

349338
try
@@ -426,18 +415,16 @@ private static async Task<IAsyncDisposable> DotnetRunInternalAsync(
426415
string directoryPath,
427416
bool? noRestore,
428417
TimeSpan? timeout,
429-
bool showShellWindow,
430-
params Uri[] urls)
418+
bool showShellWindow)
431419
{
432420
#pragma warning disable CA2000 // Dispose objects before losing scope. Object disposed below.
433421
var cancellationTokenSource = new CancellationTokenSource();
434422
#pragma warning restore CA2000 // Dispose objects before losing scope. Object disposed below.
435423
var noRestoreArgument = noRestore is null ? null : "--no-restore";
436-
var urlsParameter = string.Join(";", urls.Select(x => x.ToString()));
437424
var task = AssertStartAsync(
438425
directoryPath,
439426
"dotnet",
440-
$"run {noRestoreArgument} --urls {urlsParameter}",
427+
$"run {noRestoreArgument}",
441428
showShellWindow,
442429
cancellationTokenSource.Token);
443430

Source/Boxed.DotnetNewTest/TempDirectoryExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ public static async Task<Project> DotnetNewAsync(
4242
stringBuilder.Append($" --name \"{name}\"");
4343
}
4444

45+
var httpsPort = PortHelper.GetFreeTcpPort();
46+
var httpPort = PortHelper.GetFreeTcpPort();
47+
4548
if (arguments is not null)
4649
{
4750
foreach (var argument in arguments)
4851
{
49-
stringBuilder.Append($" --{argument.Key} \"{argument.Value}\"");
52+
stringBuilder.Append($" --{argument.Key} \"{Replace(argument.Value, httpsPort, httpPort)}\"");
5053
}
5154
}
5255

@@ -64,7 +67,12 @@ await ProcessExtensions
6467

6568
var projectDirectoryPath = name == null ? tempDirectory.DirectoryPath : Path.Combine(tempDirectory.DirectoryPath, name);
6669
var publishDirectoryPath = Path.Combine(projectDirectoryPath, "Publish");
67-
return new Project(name, projectDirectoryPath, publishDirectoryPath);
70+
return new Project(name, projectDirectoryPath, publishDirectoryPath, httpsPort, httpPort);
6871
}
72+
73+
private static string Replace(string value, int httpsPort, int httpPort) =>
74+
value
75+
.Replace("{HTTPS_PORT}", httpsPort.ToString())
76+
.Replace("{HTTP_PORT}", httpPort.ToString());
6977
}
7078
}

0 commit comments

Comments
 (0)