|
| 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 | +using Microsoft.Testing.Platform.Acceptance.IntegrationTests; |
| 5 | +using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; |
| 6 | +using Microsoft.Testing.Platform.Helpers; |
| 7 | + |
| 8 | +namespace MSTest.Acceptance.IntegrationTests; |
| 9 | + |
| 10 | +[TestClass] |
| 11 | +public sealed class TupleDynamicDataTests : AcceptanceTestBase<TupleDynamicDataTests.TestAssetFixture> |
| 12 | +{ |
| 13 | + [TestMethod] |
| 14 | + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] |
| 15 | + public async Task CanUseLongTuplesAndValueTuplesForAllFrameworks(string tfm) |
| 16 | + { |
| 17 | + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); |
| 18 | + TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings"); |
| 19 | + |
| 20 | + // Assert |
| 21 | + testHostResult.AssertExitCodeIs(ExitCodes.Success); |
| 22 | + testHostResult.AssertOutputContains(""" |
| 23 | + 1, 2, 3, 4, 5, 6, 7, 8 |
| 24 | + 9, 10, 11, 12, 13, 14, 15, 16 |
| 25 | + 1, 2, 3, 4, 5, 6, 7, 8 |
| 26 | + 9, 10, 11, 12, 13, 14, 15, 16 |
| 27 | + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
| 28 | + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 |
| 29 | + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
| 30 | + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 |
| 31 | + """); |
| 32 | + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 8, skipped: 0); |
| 33 | + } |
| 34 | + |
| 35 | + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) |
| 36 | + { |
| 37 | + public const string ProjectName = "TupleDynamicDataTests"; |
| 38 | + |
| 39 | + public string ProjectPath => GetAssetPath(ProjectName); |
| 40 | + |
| 41 | + public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() |
| 42 | + { |
| 43 | + yield return (ProjectName, ProjectName, |
| 44 | + SourceCode |
| 45 | + .PatchTargetFrameworks(TargetFrameworks.All) |
| 46 | + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); |
| 47 | + } |
| 48 | + |
| 49 | + private const string SourceCode = """ |
| 50 | +#file TupleDynamicDataTests.csproj |
| 51 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 52 | +
|
| 53 | + <PropertyGroup> |
| 54 | + <OutputType>Exe</OutputType> |
| 55 | + <EnableMSTestRunner>true</EnableMSTestRunner> |
| 56 | + <TargetFrameworks>$TargetFrameworks$</TargetFrameworks> |
| 57 | + <LangVersion>preview</LangVersion> |
| 58 | + </PropertyGroup> |
| 59 | +
|
| 60 | + <ItemGroup> |
| 61 | + <PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" /> |
| 62 | + <PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" /> |
| 63 | + </ItemGroup> |
| 64 | +
|
| 65 | + <ItemGroup> |
| 66 | + <None Update="*.runsettings"> |
| 67 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
| 68 | + </None> |
| 69 | + </ItemGroup> |
| 70 | +</Project> |
| 71 | +
|
| 72 | +#file UnitTest1.cs |
| 73 | +using System; |
| 74 | +using System.Collections.Generic; |
| 75 | +using System.Text; |
| 76 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 77 | +
|
| 78 | +[TestClass] |
| 79 | +public class UnitTest1 |
| 80 | +{ |
| 81 | + private static readonly StringBuilder s_builder = new(); |
| 82 | +
|
| 83 | + [ClassCleanup] |
| 84 | + public static void ClassCleanup() |
| 85 | + { |
| 86 | + Console.WriteLine(s_builder.ToString()); |
| 87 | + } |
| 88 | +
|
| 89 | + [DynamicData(nameof(DataTuple8))] |
| 90 | + [DynamicData(nameof(DataValueTuple8))] |
| 91 | + [TestMethod] |
| 92 | + public void TestMethod1(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) |
| 93 | + { |
| 94 | + s_builder.AppendLine($"{p1}, {p2}, {p3}, {p4}, {p5}, {p6}, {p7}, {p8}"); |
| 95 | + } |
| 96 | +
|
| 97 | + [DynamicData(nameof(DataTuple10))] |
| 98 | + [DynamicData(nameof(DataValueTuple10))] |
| 99 | + [TestMethod] |
| 100 | + public void TestMethod1(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10) |
| 101 | + { |
| 102 | + s_builder.AppendLine($"{p1}, {p2}, {p3}, {p4}, {p5}, {p6}, {p7}, {p8}, {p9}, {p10}"); |
| 103 | + } |
| 104 | +
|
| 105 | + public static IEnumerable<Tuple<int, int, int, int, int, int, int, Tuple<int>>> DataTuple8 => |
| 106 | + [ |
| 107 | + (1, 2, 3, 4, 5, 6, 7, 8).ToTuple(), |
| 108 | + (9, 10, 11, 12, 13, 14, 15, 16).ToTuple(), |
| 109 | + ]; |
| 110 | +
|
| 111 | + public static IEnumerable<ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>>> DataValueTuple8 => |
| 112 | + [ |
| 113 | + (1, 2, 3, 4, 5, 6, 7, 8), |
| 114 | + (9, 10, 11, 12, 13, 14, 15, 16), |
| 115 | + ]; |
| 116 | +
|
| 117 | + public static IEnumerable<Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>> DataTuple10 => |
| 118 | + [ |
| 119 | + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).ToTuple(), |
| 120 | + (11, 12, 13, 14, 15, 16, 17, 18, 19, 20).ToTuple(), |
| 121 | + ]; |
| 122 | +
|
| 123 | + public static IEnumerable<ValueTuple<int, int, int, int, int, int, int, ValueTuple<int, int, int>>> DataValueTuple10 => |
| 124 | + [ |
| 125 | + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
| 126 | + (11, 12, 13, 14, 15, 16, 17, 18, 19, 20), |
| 127 | + ]; |
| 128 | +} |
| 129 | +
|
| 130 | +
|
| 131 | +#file my.runsettings |
| 132 | +<RunSettings> |
| 133 | + <MSTest> |
| 134 | + <CaptureTraceOutput>false</CaptureTraceOutput> |
| 135 | + </MSTest> |
| 136 | +</RunSettings> |
| 137 | +"""; |
| 138 | + } |
| 139 | +} |
0 commit comments