|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; |
| 5 | + |
| 6 | +[TestClass] |
| 7 | +public class ForwardCompatibilityTests : AcceptanceTestBase<ForwardCompatibilityTests.TestAssetFixture> |
| 8 | +{ |
| 9 | + private const string AssetName = "ForwardCompatibilityTest"; |
| 10 | + |
| 11 | + [TestMethod] |
| 12 | + public async Task NewerPlatform_WithPreviousExtensions_ShouldExecuteTests() |
| 13 | + { |
| 14 | + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetCurrent); |
| 15 | + TestHostResult testHostResult = await testHost.ExecuteAsync("--crashdump --hangdump --report-trx --retry-failed-tests 3", cancellationToken: TestContext.CancellationToken); |
| 16 | + |
| 17 | + testHostResult.AssertExitCodeIs(ExitCodes.Success); |
| 18 | + testHostResult.AssertOutputContainsSummary(0, 1, 0); |
| 19 | + |
| 20 | + string testResultsPath = Path.Combine(testHost.DirectoryName, "TestResults"); |
| 21 | + Assert.IsTrue(Directory.Exists(testResultsPath), $"TestResults directory should exist at: {testResultsPath}"); |
| 22 | + |
| 23 | + string[] trxFiles = Directory.GetFiles(testResultsPath, "*.trx", SearchOption.TopDirectoryOnly); |
| 24 | + Assert.IsNotEmpty(trxFiles, $"At least one TRX file should be generated in: {testResultsPath}"); |
| 25 | + } |
| 26 | + |
| 27 | + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) |
| 28 | + { |
| 29 | + private const string PreviousExtensionVersion = "2.0.0"; |
| 30 | + |
| 31 | + private const string ForwardCompatibilityTestCode = """ |
| 32 | +#file ForwardCompatibilityTest.csproj |
| 33 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 34 | + <PropertyGroup> |
| 35 | + <TargetFrameworks>$TargetFrameworks$</TargetFrameworks> |
| 36 | + <ImplicitUsings>enable</ImplicitUsings> |
| 37 | + <Nullable>enable</Nullable> |
| 38 | + <OutputType>Exe</OutputType> |
| 39 | + <LangVersion>preview</LangVersion> |
| 40 | + </PropertyGroup> |
| 41 | +
|
| 42 | + <ItemGroup> |
| 43 | + <!-- Use the locally built (newer) version of the platform --> |
| 44 | + <PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" /> |
| 45 | +
|
| 46 | + <!-- Use previous version of all extensions to test forward compatibility --> |
| 47 | + <PackageReference Include="Microsoft.Testing.Extensions.CrashDump" Version="$PreviousExtensionVersion$" /> |
| 48 | + <PackageReference Include="Microsoft.Testing.Extensions.HangDump" Version="$PreviousExtensionVersion$" /> |
| 49 | + <PackageReference Include="Microsoft.Testing.Extensions.HotReload" Version="$PreviousExtensionVersion$" /> |
| 50 | + <PackageReference Include="Microsoft.Testing.Extensions.Retry" Version="$PreviousExtensionVersion$" /> |
| 51 | + <PackageReference Include="Microsoft.Testing.Extensions.Telemetry" Version="$PreviousExtensionVersion$" /> |
| 52 | + <PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$PreviousExtensionVersion$" /> |
| 53 | + </ItemGroup> |
| 54 | +</Project> |
| 55 | +
|
| 56 | +#file Program.cs |
| 57 | +using Microsoft.Testing.Extensions; |
| 58 | +using Microsoft.Testing.Extensions.TrxReport.Abstractions; |
| 59 | +using Microsoft.Testing.Platform.Builder; |
| 60 | +using Microsoft.Testing.Platform.Capabilities.TestFramework; |
| 61 | +using Microsoft.Testing.Platform.Extensions.Messages; |
| 62 | +using Microsoft.Testing.Platform.Extensions.TestFramework; |
| 63 | +using Microsoft.Testing.Platform.Services; |
| 64 | +
|
| 65 | +public class Program |
| 66 | +{ |
| 67 | + public static async Task<int> Main(string[] args) |
| 68 | + { |
| 69 | + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); |
| 70 | + builder.RegisterTestFramework( |
| 71 | + sp => new TestFrameworkCapabilities(new TrxReportCapability()), |
| 72 | + (_,__) => new DummyTestFramework()); |
| 73 | +
|
| 74 | + // Add all extensions to ensure forward compatibility |
| 75 | + builder.AddCrashDumpProvider(); |
| 76 | + builder.AddHangDumpProvider(); |
| 77 | + builder.AddHotReloadProvider(); |
| 78 | + builder.AddRetryProvider(); |
| 79 | + builder.AddAppInsightsTelemetryProvider(); |
| 80 | + builder.AddTrxReportProvider(); |
| 81 | +
|
| 82 | + using ITestApplication app = await builder.BuildAsync(); |
| 83 | + return await app.RunAsync(); |
| 84 | + } |
| 85 | +} |
| 86 | +
|
| 87 | +public class TrxReportCapability : ITrxReportCapability |
| 88 | +{ |
| 89 | + bool ITrxReportCapability.IsSupported { get; } = true; |
| 90 | + void ITrxReportCapability.Enable() |
| 91 | + { |
| 92 | + } |
| 93 | +} |
| 94 | +
|
| 95 | +public class DummyTestFramework : ITestFramework, IDataProducer |
| 96 | +{ |
| 97 | + public string Uid => nameof(DummyTestFramework); |
| 98 | +
|
| 99 | + public string Version => "2.0.0"; |
| 100 | +
|
| 101 | + public string DisplayName => nameof(DummyTestFramework); |
| 102 | +
|
| 103 | + public string Description => nameof(DummyTestFramework); |
| 104 | +
|
| 105 | + public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) }; |
| 106 | +
|
| 107 | + public Task<bool> IsEnabledAsync() => Task.FromResult(true); |
| 108 | +
|
| 109 | + public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) |
| 110 | + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); |
| 111 | +
|
| 112 | + public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) |
| 113 | + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); |
| 114 | +
|
| 115 | + public async Task ExecuteRequestAsync(ExecuteRequestContext context) |
| 116 | + { |
| 117 | + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, |
| 118 | + new TestNode() { Uid = "0", DisplayName = "ForwardCompatibilityTest", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); |
| 119 | + context.Complete(); |
| 120 | + } |
| 121 | +} |
| 122 | +"""; |
| 123 | + |
| 124 | + public string TargetAssetPath => GetAssetPath(AssetName); |
| 125 | + |
| 126 | + public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() |
| 127 | + { |
| 128 | + yield return (AssetName, AssetName, |
| 129 | + ForwardCompatibilityTestCode |
| 130 | + .PatchTargetFrameworks(TargetFrameworks.NetCurrent) |
| 131 | + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) |
| 132 | + .PatchCodeWithReplace("$PreviousExtensionVersion$", PreviousExtensionVersion)); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + public TestContext TestContext { get; set; } |
| 137 | +} |
0 commit comments