Skip to content

Commit b9b020b

Browse files
committed
Fix playground
1 parent 982b20d commit b9b020b

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

samples/Playground/Playground.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@
3434
</None>
3535
</ItemGroup>
3636

37+
<ItemGroup>
38+
<ProjectCapability Include="DiagnoseCapabilities" />
39+
<ProjectCapability Include="TestingPlatformServer" />
40+
<ProjectCapability Include="TestContainer" />
41+
</ItemGroup>
42+
3743
</Project>

samples/Playground/Program.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
using System.Reflection;
55

66
using Microsoft.Testing.Platform.Builder;
7+
using Microsoft.Testing.Platform.ServerMode.IntegrationTests.Messages.V100;
78
using Microsoft.VisualStudio.TestTools.UnitTesting;
89

10+
using MSTest.Acceptance.IntegrationTests.Messages.V100;
11+
912
namespace Playground;
1013

1114
public class Program
@@ -15,8 +18,12 @@ public static async Task<int> Main(string[] args)
1518
// Opt-out telemetry
1619
Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
1720

18-
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
19-
testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);
21+
if (Environment.GetEnvironmentVariable("TESTSERVERMODE") != "1")
22+
{
23+
// To attach to the children
24+
// Microsoft.Testing.TestInfrastructure.DebuggerUtility.AttachCurrentProcessToParentVSProcess();
25+
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
26+
testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);
2027

2128
// Enable Trx
2229
// testApplicationBuilder.AddTrxReportProvider();
@@ -40,10 +47,7 @@ public static async Task<int> Main(string[] args)
4047
});
4148
await discoveryResponse.WaitCompletionAsync();
4249

43-
ResponseListener runRequest = await client.RunTestsAsync(Guid.NewGuid(), testNodeUpdates.Select(x => x.Node).ToArray(), node =>
44-
{
45-
return Task.CompletedTask;
46-
});
50+
ResponseListener runRequest = await client.RunTestsAsync(Guid.NewGuid(), testNodeUpdates.Select(x => x.Node).ToArray(), node => Task.CompletedTask);
4751
await runRequest.WaitCompletionAsync();
4852

4953
await client.ExitAsync();

samples/Playground/ServerMode/TestingPlatformClientFactory.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ public static IProcessHandle Start(ProcessConfiguration config, bool cleanDefaul
258258
ProcessHandleInfo processHandleInfo = new();
259259
ProcessHandle processHandle = new(process, processHandleInfo);
260260

261-
process.Exited += (s, e) => config.OnExit?.Invoke(processHandle, process.ExitCode);
261+
if (config.OnExit != null)
262+
{
263+
process.Exited += (s, e) => config.OnExit.Invoke(processHandle, process.ExitCode);
264+
}
262265

263266
if (config.OnStandardOutput != null)
264267
{
@@ -345,16 +348,12 @@ internal ProcessHandle(Process process, ProcessHandleInfo processHandleInfo)
345348

346349
public async Task<int> WaitForExitAsync()
347350
{
348-
if (_disposed)
351+
if (!_disposed)
349352
{
350-
return _exitCode;
353+
await _process.WaitForExitAsync();
351354
}
352-
#if NETCOREAPP
353-
await _process.WaitForExitAsync();
354-
#else
355-
_process.WaitForExit();
356-
#endif
357-
return await Task.FromResult(_process.ExitCode);
355+
356+
return _exitCode;
358357
}
359358

360359
public void WaitForExit() => _process.WaitForExit();
@@ -413,11 +412,7 @@ private static void KillSafe(Process process)
413412
{
414413
try
415414
{
416-
#if NETCOREAPP
417415
process.Kill(true);
418-
#else
419-
process.Kill();
420-
#endif
421416
}
422417
catch (InvalidOperationException)
423418
{

samples/Playground/Tests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ namespace Playground;
1212
[TestClass]
1313
public class TestClass
1414
{
15+
public TestContext TestContext { get; set; } = null!;
16+
1517
[TestMethod]
1618
public void Test()
1719
{
1820
}
21+
22+
[TestMethod]
23+
public void Test2()
24+
{
25+
}
26+
27+
[TestMethod]
28+
public void Test3()
29+
{
30+
}
1931
}

0 commit comments

Comments
 (0)