Skip to content

Commit 8547715

Browse files
authored
Update samples (#6693)
1 parent da260db commit 8547715

File tree

15 files changed

+61
-56
lines changed

15 files changed

+61
-56
lines changed

samples/public/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
<PropertyGroup>
44
<AspireTestingVersion>9.5.0</AspireTestingVersion>
5-
<CodeCoverageVersion>18.0.4</CodeCoverageVersion>
6-
<MSTestVersion>3.11.0</MSTestVersion>
5+
<CodeCoverageVersion>18.1.0</CodeCoverageVersion>
6+
<MSTestVersion>4.0.0</MSTestVersion>
77
<MSTestAOTVersion>1.0.0-alpha.25501.5</MSTestAOTVersion>
88
<PlaywrightVersion>1.55.0</PlaywrightVersion>
9-
<TestingPlatformVersion>1.9.0</TestingPlatformVersion>
10-
<VSTestVersion>17.13.0</VSTestVersion>
9+
<TestingPlatformVersion>2.0.0</TestingPlatformVersion>
10+
<VSTestVersion>18.0.0</VSTestVersion>
1111
<GenerateDocumentationFile>false</GenerateDocumentationFile>
1212
<NoWarn>$(NoWarn);SA0001;EnableGenerateDocumentationFile</NoWarn>
1313
</PropertyGroup>

samples/public/TestingPlatformExamples/TestingPlatformExplorer/In-process extensions/CompositeExtensionFactorySample.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using Microsoft.Testing.Platform.Extensions;
45
using Microsoft.Testing.Platform.Extensions.Messages;
56
using Microsoft.Testing.Platform.Extensions.OutputDevice;
67
using Microsoft.Testing.Platform.Extensions.TestHost;
78
using Microsoft.Testing.Platform.OutputDevice;
8-
using Microsoft.Testing.Platform.TestHost;
9+
using Microsoft.Testing.Platform.Services;
910

1011
namespace TestingPlatformExplorer.InProcess;
1112

@@ -47,47 +48,47 @@ public async Task ConsumeAsync(IDataProducer dataProducer, IData value, Cancella
4748
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayCompositeExtensionFactorySample]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is in progress")
4849
{
4950
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
50-
});
51+
}, cancellationToken);
5152
break;
5253
}
5354
case PassedTestNodeStateProperty _:
5455
{
5556
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayCompositeExtensionFactorySample]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is completed")
5657
{
5758
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
58-
});
59+
}, cancellationToken);
5960
break;
6061
}
6162
case FailedTestNodeStateProperty failedTestNodeStateProperty:
6263
{
6364
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayCompositeExtensionFactorySample]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is failed with '{failedTestNodeStateProperty?.Exception?.Message}'")
6465
{
6566
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Red }
66-
});
67+
}, cancellationToken);
6768
break;
6869
}
6970
case SkippedTestNodeStateProperty _:
7071
{
7172
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayCompositeExtensionFactorySample]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is skipped")
7273
{
7374
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.White }
74-
});
75+
}, cancellationToken);
7576
break;
7677
}
7778
default:
7879
break;
7980
}
8081
}
8182

82-
public async Task OnTestSessionStartingAsync(SessionUid sessionUid, CancellationToken cancellationToken)
83+
public async Task OnTestSessionStartingAsync(ITestSessionContext testSessionContext)
8384
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("[DisplayCompositeExtensionFactorySample]Hello from OnTestSessionStartingAsync")
8485
{
8586
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
86-
});
87+
}, testSessionContext.CancellationToken);
8788

88-
public async Task OnTestSessionFinishingAsync(SessionUid sessionUid, CancellationToken cancellationToken)
89+
public async Task OnTestSessionFinishingAsync(ITestSessionContext testSessionContext)
8990
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayCompositeExtensionFactorySample]Total received 'TestNodeUpdateMessage': {_testNodeUpdateMessageCount}")
9091
{
9192
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
92-
});
93+
}, testSessionContext.CancellationToken);
9394
}

samples/public/TestingPlatformExamples/TestingPlatformExplorer/In-process extensions/DisplayDataConsumer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using Microsoft.Testing.Platform.Extensions;
45
using Microsoft.Testing.Platform.Extensions.Messages;
56
using Microsoft.Testing.Platform.Extensions.OutputDevice;
6-
using Microsoft.Testing.Platform.Extensions.TestHost;
77
using Microsoft.Testing.Platform.OutputDevice;
88

99
namespace TestingPlatformExplorer.InProcess;
@@ -41,31 +41,31 @@ public async Task ConsumeAsync(IDataProducer dataProducer, IData value, Cancella
4141
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayDataConsumer]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is in progress")
4242
{
4343
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
44-
});
44+
}, cancellationToken);
4545
break;
4646
}
4747
case PassedTestNodeStateProperty _:
4848
{
4949
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayDataConsumer]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is completed")
5050
{
5151
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
52-
});
52+
}, cancellationToken);
5353
break;
5454
}
5555
case FailedTestNodeStateProperty failedTestNodeStateProperty:
5656
{
5757
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayDataConsumer]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is failed with '{failedTestNodeStateProperty?.Exception?.Message}'")
5858
{
5959
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Red }
60-
});
60+
}, cancellationToken);
6161
break;
6262
}
6363
case SkippedTestNodeStateProperty _:
6464
{
6565
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"[DisplayDataConsumer]TestNode '{testNodeId}' with display name '{testNodeDisplayName}' is skipped")
6666
{
6767
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.White }
68-
});
68+
}, cancellationToken);
6969
break;
7070
}
7171
default:

samples/public/TestingPlatformExamples/TestingPlatformExplorer/In-process extensions/DisplayTestApplicationLifecycleCallbacks.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
using Microsoft.Testing.Platform.OutputDevice;
77

88
namespace TestingPlatformExplorer.InProcess;
9-
internal sealed class DisplayTestApplicationLifecycleCallbacks : ITestApplicationLifecycleCallbacks, IOutputDeviceDataProducer
9+
10+
internal sealed class DisplayTestApplicationLifecycleCallbacks : ITestHostApplicationLifetime, IOutputDeviceDataProducer
1011
{
1112
private readonly IOutputDevice _outputDevice;
1213

@@ -23,17 +24,17 @@ public DisplayTestApplicationLifecycleCallbacks(IOutputDevice outputDevice)
2324
_outputDevice = outputDevice;
2425
}
2526

26-
public async Task AfterRunAsync(int exitCode, CancellationToken cancellation)
27+
public async Task AfterRunAsync(int exitCode, CancellationToken cancellationToken)
2728
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"Hello from AfterRunAsync, exit code: {exitCode}")
2829
{
2930
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
30-
});
31+
}, cancellationToken);
3132

3233
public async Task BeforeRunAsync(CancellationToken cancellationToken)
3334
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("Hello from BeforeRunAsync")
3435
{
3536
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
36-
});
37+
}, cancellationToken);
3738

3839
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
3940
}

samples/public/TestingPlatformExamples/TestingPlatformExplorer/In-process extensions/DisplayTestSessionLifeTimeHandler.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
using Microsoft.Testing.Platform.Extensions.OutputDevice;
66
using Microsoft.Testing.Platform.Extensions.TestHost;
77
using Microsoft.Testing.Platform.OutputDevice;
8-
using Microsoft.Testing.Platform.TestHost;
8+
using Microsoft.Testing.Platform.Services;
99

1010
namespace TestingPlatformExplorer.InProcess;
11+
1112
internal sealed class DisplayTestSessionLifeTimeHandler : ITestSessionLifetimeHandler,
1213
IOutputDeviceDataProducer,
1314
IAsyncInitializableExtension,
@@ -31,32 +32,33 @@ public DisplayTestSessionLifeTimeHandler(IOutputDevice outputDevice)
3132

3233
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
3334

34-
public async Task OnTestSessionStartingAsync(SessionUid sessionUid, CancellationToken cancellationToken)
35+
public async Task OnTestSessionStartingAsync(ITestSessionContext testSessionContext)
3536
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("Hello from OnTestSessionStartingAsync")
3637
{
3738
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
38-
});
39+
}, testSessionContext.CancellationToken);
3940

40-
public async Task OnTestSessionFinishingAsync(SessionUid sessionUid, CancellationToken cancellationToken)
41+
public async Task OnTestSessionFinishingAsync(ITestSessionContext testSessionContext)
4142
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("Hello from OnTestSessionFinishingAsync")
4243
{
4344
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
44-
});
45+
}, testSessionContext.CancellationToken);
46+
4547
public async Task InitializeAsync()
4648
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("Hello from InitializeAsync")
4749
{
4850
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
49-
});
51+
}, CancellationToken.None);
5052

5153
public async Task CleanupAsync()
5254
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("Hello from CleanupAsync")
5355
{
5456
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
55-
});
57+
}, CancellationToken.None);
5658

5759
public async ValueTask DisposeAsync()
5860
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("Hello from DisposeAsync")
5961
{
6062
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.DarkGreen }
61-
});
63+
}, CancellationToken.None);
6264
}

samples/public/TestingPlatformExamples/TestingPlatformExplorer/Out-of-process extensions/MonitorTestHost.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public async Task BeforeTestHostProcessStartAsync(CancellationToken cancellation
3030
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData("BeforeTestHostProcessStartAsync")
3131
{
3232
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
33-
});
33+
}, cancellationToken);
3434

35-
public async Task OnTestHostProcessExitedAsync(ITestHostProcessInformation testHostProcessInformation, CancellationToken cancellation)
35+
public async Task OnTestHostProcessExitedAsync(ITestHostProcessInformation testHostProcessInformation, CancellationToken cancellationToken)
3636
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"OnTestHostProcessExitedAsync, test host exited with exit code {testHostProcessInformation.ExitCode}")
3737
{
3838
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
39-
});
39+
}, cancellationToken);
4040

41-
public async Task OnTestHostProcessStartedAsync(ITestHostProcessInformation testHostProcessInformation, CancellationToken cancellation)
41+
public async Task OnTestHostProcessStartedAsync(ITestHostProcessInformation testHostProcessInformation, CancellationToken cancellationToken)
4242
=> await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"OnTestHostProcessStartedAsync, test host started with PID {testHostProcessInformation.PID}")
4343
{
4444
ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green }
45-
});
45+
}, cancellationToken);
4646
}

samples/public/TestingPlatformExamples/TestingPlatformExplorer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
testApplicationBuilder.CommandLine.AddProvider(() => new TestingFrameworkCommandLineOptions());
2424

2525
// In-process extensions
26-
testApplicationBuilder.TestHost.AddTestApplicationLifecycleCallbacks(serviceProvider
26+
testApplicationBuilder.TestHost.AddTestHostApplicationLifetime(serviceProvider
2727
=> new DisplayTestApplicationLifecycleCallbacks(serviceProvider.GetOutputDevice()));
2828
testApplicationBuilder.TestHost.AddTestSessionLifetimeHandle(serviceProvider
2929
=> new DisplayTestSessionLifeTimeHandler(serviceProvider.GetOutputDevice()));

samples/public/TestingPlatformExamples/TestingPlatformExplorer/TestingFramework/TestingFramework.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
112112
Properties = new PropertyBag(DiscoveredTestNodeStateProperty.CachedInstance),
113113
};
114114

115-
TestMethodIdentifierProperty testMethodIdentifierProperty = new(test.DeclaringType!.Assembly!.FullName!,
115+
var testMethodIdentifierProperty = new TestMethodIdentifierProperty(test.DeclaringType!.Assembly!.FullName!,
116116
test.DeclaringType!.Namespace!,
117117
test.DeclaringType.Name!,
118118
test.Name,
119+
test.GetGenericArguments().Length,
119120
test.GetParameters().Select(x => x.ParameterType.FullName).ToArray()!,
120121
test.ReturnType.FullName!);
121122

@@ -137,11 +138,11 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
137138
{
138139
try
139140
{
140-
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"TestingFramework version '{Version}' running tests with parallelism of {_dopValue}") { ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green } });
141+
await _outputDevice.DisplayAsync(this, new FormattedTextOutputDeviceData($"TestingFramework version '{Version}' running tests with parallelism of {_dopValue}") { ForegroundColor = new SystemConsoleColor() { ConsoleColor = ConsoleColor.Green } }, context.CancellationToken);
141142

142143
StringBuilder reportBody = new();
143144
MethodInfo[] tests = GetTestsMethodFromAssemblies();
144-
List<Task> results = new();
145+
var results = new List<Task>();
145146
foreach (MethodInfo test in tests)
146147
{
147148
if (runTestExecutionRequest.Filter is TestNodeUidListFilter filter)

samples/public/TestingPlatformExamples/TestingPlatformExplorer/TestingPlatformExplorer.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
<ItemGroup>
1313
<!-- Update to the last version if needed -->
14-
<PackageReference Include="Microsoft.Testing.Platform" Version="1.4.0-preview.24415.5" />
14+
<PackageReference Include="Microsoft.Testing.Platform" Version="$(TestingPlatformVersion)" />
1515

1616
<!-- Needed to support the Trx capability -->
17-
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport.Abstractions" Version="1.4.0-preview.24415.5" />
17+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport.Abstractions" Version="$(TestingPlatformVersion)" />
1818

1919
<!-- Add the trx extension -->
20-
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.0-preview.24415.5" />
20+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$(TestingPlatformVersion)" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

samples/public/global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"msbuild-sdks": {
3-
"MSTest.Sdk": "3.11.0"
3+
"MSTest.Sdk": "4.0.0"
44
}
55
}

0 commit comments

Comments
 (0)