Skip to content

Commit afb8c22

Browse files
Start on Grpc template test
1 parent c6d9fdb commit afb8c22

File tree

4 files changed

+94
-20
lines changed

4 files changed

+94
-20
lines changed

src/Middleware/NodeServices/src/Microsoft.AspNetCore.NodeServices.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<Description>Invoke Node.js modules at runtime in ASP.NET Core applications.</Description>
54
<TargetFramework>netcoreapp3.0</TargetFramework>

src/ProjectTemplates/test/GrpcTemplateTest.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public GrpcTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputHelper
2121
public ProjectFactoryFixture ProjectFactory { get; }
2222
public ITestOutputHelper Output { get; }
2323

24-
[Fact]
24+
[Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/7973")]
2525
public async Task GrpcTemplate()
2626
{
2727
Project = await ProjectFactory.GetOrCreateProject("grpc", Output);
@@ -35,18 +35,36 @@ public async Task GrpcTemplate()
3535
var buildResult = await Project.RunDotNetBuildAsync();
3636
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", Project, buildResult));
3737

38-
using (var aspNetProcess = Project.StartBuiltProjectAsync())
38+
using (var serverProcess = Project.StartBuiltServerAsync())
3939
{
4040
Assert.False(
41-
aspNetProcess.Process.HasExited,
42-
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", Project, aspNetProcess.Process));
41+
serverProcess.Process.HasExited,
42+
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built server", Project, serverProcess.Process));
43+
44+
using (var clientProcess = Project.StartBuiltClientAsync(serverProcess))
45+
{
46+
// Wait for the client to do its thing
47+
System.Threading.Thread.Sleep(100);
48+
Assert.False(
49+
clientProcess.Process.HasExited,
50+
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built client", Project, clientProcess.Process));
51+
}
4352
}
4453

45-
using (var aspNetProcess = Project.StartPublishedProjectAsync())
54+
using (var aspNetProcess = Project.StartPublishedServerAsync())
4655
{
4756
Assert.False(
4857
aspNetProcess.Process.HasExited,
49-
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", Project, aspNetProcess.Process));
58+
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published server", Project, aspNetProcess.Process));
59+
60+
using (var clientProcess = Project.StartPublishedClientAsync())
61+
{
62+
// Wait for the client to do its thing
63+
System.Threading.Thread.Sleep(100);
64+
Assert.False(
65+
clientProcess.Process.HasExited,
66+
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built client", Project, clientProcess.Process));
67+
}
5068
}
5169
}
5270
}

src/ProjectTemplates/test/Helpers/AspNetProcess.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,19 @@ public static class PageUrls
3333
public class AspNetProcess : IDisposable
3434
{
3535
private const string ListeningMessagePrefix = "Now listening on: ";
36-
private readonly Uri _listeningUri;
3736
private readonly HttpClient _httpClient;
3837
private readonly ITestOutputHelper _output;
3938

39+
internal readonly Uri ListeningUri;
4040
internal ProcessEx Process { get; }
4141

4242
public AspNetProcess(
4343
ITestOutputHelper output,
4444
string workingDirectory,
4545
string dllPath,
46-
IDictionary<string, string> environmentVariables)
46+
IDictionary<string, string> environmentVariables,
47+
bool useExec = true,
48+
bool hasListeningUri = true)
4749
{
4850
_output = output;
4951
_httpClient = new HttpClient(new HttpClientHandler()
@@ -60,17 +62,20 @@ public AspNetProcess(
6062
var now = DateTimeOffset.Now;
6163
new CertificateManager().EnsureAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1));
6264

63-
6465
output.WriteLine("Running ASP.NET application...");
6566

66-
Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), $"exec {dllPath}", envVars: environmentVariables);
67-
_listeningUri = GetListeningUri(output);
67+
var arguments = useExec ? $"exec {dllPath}" : "run";
68+
Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments, envVars: environmentVariables);
69+
if(hasListeningUri)
70+
{
71+
ListeningUri = GetListeningUri(output);
72+
}
6873
}
6974

7075
public void VisitInBrowser(IWebDriver driver)
7176
{
72-
_output.WriteLine($"Opening browser at {_listeningUri}...");
73-
driver.Navigate().GoToUrl(_listeningUri);
77+
_output.WriteLine($"Opening browser at {ListeningUri}...");
78+
driver.Navigate().GoToUrl(ListeningUri);
7479

7580
if (driver is EdgeDriver)
7681
{
@@ -86,7 +91,7 @@ public void VisitInBrowser(IWebDriver driver)
8691
{
8792
_output.WriteLine($"Clicking on link '{continueLink.Text}' to skip invalid certificate error page.");
8893
continueLink.Click();
89-
driver.Navigate().GoToUrl(_listeningUri);
94+
driver.Navigate().GoToUrl(ListeningUri);
9095
}
9196
else
9297
{
@@ -109,7 +114,7 @@ public async Task ContainsLinks(Page page)
109114
{
110115
var request = new HttpRequestMessage(
111116
HttpMethod.Get,
112-
new Uri(_listeningUri, page.Url));
117+
new Uri(ListeningUri, page.Url));
113118

114119
var response = await _httpClient.SendAsync(request);
115120

@@ -189,14 +194,14 @@ public Task AssertNotFound(string requestUrl)
189194

190195
internal Task<HttpResponseMessage> SendRequest(string path)
191196
{
192-
return _httpClient.GetAsync(new Uri(_listeningUri, path));
197+
return _httpClient.GetAsync(new Uri(ListeningUri, path));
193198
}
194199

195200
public async Task AssertStatusCode(string requestUrl, HttpStatusCode statusCode, string acceptContentType = null)
196201
{
197202
var request = new HttpRequestMessage(
198203
HttpMethod.Get,
199-
new Uri(_listeningUri, requestUrl));
204+
new Uri(ListeningUri, requestUrl));
200205

201206
if (!string.IsNullOrEmpty(acceptContentType))
202207
{

src/ProjectTemplates/test/Helpers/Project.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class Project
2828
public string TemplateBuildDir => Path.Combine(TemplateOutputDir, "bin", "Debug", DefaultFramework);
2929
public string TemplatePublishDir => Path.Combine(TemplateOutputDir, "bin", "Release", DefaultFramework, "publish");
3030

31+
private string TemplateServerDir => Path.Combine(TemplateOutputDir, $"{ProjectName}.Server");
32+
private string TemplateClientDir => Path.Combine(TemplateOutputDir, $"{ProjectName}.Client");
33+
public string TemplateClientDebugDir => Path.Combine(TemplateClientDir, "bin", "Debug", DefaultFramework);
34+
public string TemplateClientReleaseDir => Path.Combine(TemplateClientDir, "bin", "Release", DefaultFramework, "publish");
35+
public string TemplateServerReleaseDir => Path.Combine(TemplateServerDir, "bin", "Release", DefaultFramework, "publish");
36+
3137
public ITestOutputHelper Output { get; set; }
3238
public IMessageSink DiagnosticsMessageSink { get; set; }
3339

@@ -125,11 +131,57 @@ internal async Task<ProcessEx> RunDotNetBuildAsync(bool takeNodeLock = false)
125131
}
126132
}
127133

134+
internal AspNetProcess StartBuiltServerAsync()
135+
{
136+
var environment = new Dictionary<string, string>
137+
{
138+
["ASPNETCORE_ENVIRONMENT"] = "Development"
139+
};
140+
141+
var projectDll = Path.Combine(TemplateServerDir, $"{ProjectName}.Server.dll");
142+
return new AspNetProcess(Output, TemplateServerDir, projectDll, environment, useExec: false);
143+
}
144+
145+
internal AspNetProcess StartBuiltClientAsync(AspNetProcess serverProcess)
146+
{
147+
var environment = new Dictionary<string, string>
148+
{
149+
["ASPNETCORE_ENVIRONMENT"] = "Development"
150+
};
151+
152+
var projectDll = Path.Combine(TemplateClientDebugDir, $"{ProjectName}.Client.dll {serverProcess.ListeningUri.Port}");
153+
return new AspNetProcess(Output, TemplateOutputDir, projectDll, environment, hasListeningUri: false);
154+
}
155+
156+
internal AspNetProcess StartPublishedServerAsync()
157+
{
158+
var environment = new Dictionary<string, string>
159+
{
160+
["ASPNETCORE_URLS"] = _urls,
161+
};
162+
163+
var projectDll = $"{ProjectName}.Server.dll";
164+
return new AspNetProcess(Output, TemplateServerReleaseDir, projectDll, environment);
165+
}
166+
167+
internal AspNetProcess StartPublishedClientAsync()
168+
{
169+
var environment = new Dictionary<string, string>
170+
{
171+
["ASPNETCORE_URLS"] = _urls,
172+
};
173+
174+
var projectDll = $"{ProjectName}.Client.dll";
175+
return new AspNetProcess(Output, TemplateClientReleaseDir, projectDll, environment);
176+
}
177+
178+
private const string _urls = "http://127.0.0.1:0;https://127.0.0.1:0";
179+
128180
internal AspNetProcess StartBuiltProjectAsync()
129181
{
130182
var environment = new Dictionary<string, string>
131183
{
132-
["ASPNETCORE_URLS"] = $"http://127.0.0.1:0;https://127.0.0.1:0",
184+
["ASPNETCORE_URLS"] = _urls,
133185
["ASPNETCORE_ENVIRONMENT"] = "Development"
134186
};
135187

@@ -141,7 +193,7 @@ internal AspNetProcess StartPublishedProjectAsync()
141193
{
142194
var environment = new Dictionary<string, string>
143195
{
144-
["ASPNETCORE_URLS"] = $"http://127.0.0.1:0;https://127.0.0.1:0",
196+
["ASPNETCORE_URLS"] = _urls,
145197
};
146198

147199
var projectDll = $"{ProjectName}.dll";

0 commit comments

Comments
 (0)