-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathDuplicateTestClassAttributeTests.cs
More file actions
72 lines (57 loc) · 2.59 KB
/
DuplicateTestClassAttributeTests.cs
File metadata and controls
72 lines (57 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
using Microsoft.Testing.Platform.Helpers;
namespace MSTest.Acceptance.IntegrationTests;
[TestClass]
public sealed class DuplicateTestClassAttributeTests : AcceptanceTestBase<DuplicateTestClassAttributeTests.TestAssetFixture>
{
public TestContext TestContext { get; set; }
[TestMethod]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
public async Task DuplicateTestClassAttribute_ShouldFail(string tfm)
{
var testHost = TestHost.LocateFrom(AssetFixture.DuplicateTestClassProjectPath, TestAssetFixture.DuplicateTestClassProjectName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIsNot(ExitCodes.Success);
testHostResult.AssertStandardErrorContains("Only one attribute of type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute' is allowed, but multiple were found.");
}
public sealed class TestAssetFixture() : TestAssetFixtureBase()
{
public const string DuplicateTestClassProjectName = "DuplicateTestClassAttribute";
public string DuplicateTestClassProjectPath => GetAssetPath(DuplicateTestClassProjectName);
public override (string ID, string Name, string Code) GetAssetsToGenerate() => (DuplicateTestClassProjectName, DuplicateTestClassProjectName,
DuplicateTestClassSourceCode
.PatchTargetFrameworks(TargetFrameworks.All)
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion));
private const string DuplicateTestClassSourceCode = """
#file DuplicateTestClassAttribute.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<EnableMSTestRunner>true</EnableMSTestRunner>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" />
</ItemGroup>
</Project>
#file UnitTest1.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
[MyTestClass]
public class TestClass2
{
[TestMethod]
public void Test1()
{
}
}
public class MyTestClassAttribute : TestClassAttribute
{
}
""";
}
}