Skip to content

Commit 8769878

Browse files
authored
Update MSTest to 4.0.2 (#1584)
* Update MSTest to 4.0.2 * Delete test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestOnWindowsAttribute.cs * Delete test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestIfNotWindowsAttribute.cs * Remove expected exception usages * Suppress * OSCondition * OSCondition * OSCondition * Update GoComponentTests.cs * Update CommandLineInvocationServiceTests.cs * Update DockerServiceTests.cs * Update SafeFileEnumerableTests.cs
1 parent fca63b2 commit 8769878

File tree

8 files changed

+44
-86
lines changed

8 files changed

+44
-86
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<PackageReleaseNotes>https://github.com/microsoft/component-detection/releases</PackageReleaseNotes>
2424
<!-- https://github.com/NuGet/Home/issues/11822#issuecomment-1218230674 -->
2525
<NoWarn>$(NoWarn);NU1507</NoWarn>
26+
27+
<!-- MSTest analyzer for enabling parallelization. To be addressed later. -->
28+
<NoWarn>$(NoWarn);MSTEST0001</NoWarn>
2629
</PropertyGroup>
2730

2831
<ItemGroup Label="Package References">

Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<PackageVersion Include="MinVer" Version="6.0.0" />
2222
<PackageVersion Include="Moq" Version="4.18.4" />
2323
<PackageVersion Include="morelinq" Version="4.4.0" />
24-
<PackageVersion Include="MSTest.TestFramework" Version="3.11.1" />
25-
<PackageVersion Include="MSTest.Analyzers" Version="3.11.1" />
26-
<PackageVersion Include="MSTest.TestAdapter" Version="3.11.1" />
24+
<PackageVersion Include="MSTest.TestFramework" Version="4.0.2" />
25+
<PackageVersion Include="MSTest.Analyzers" Version="4.0.2" />
26+
<PackageVersion Include="MSTest.TestAdapter" Version="4.0.2" />
2727
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
2828
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
2929
<PackageVersion Include="Newtonsoft.Json.Schema" Version="4.0.1" />

test/Microsoft.ComponentDetection.Common.Tests/CommandLineInvocationServiceTests.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Microsoft.ComponentDetection.Common.Tests;
66
using System.Text;
77
using System.Threading.Tasks;
88
using AwesomeAssertions;
9-
using Microsoft.ComponentDetection.TestsUtilities;
109
using Microsoft.VisualStudio.TestTools.UnitTesting;
1110

1211
[TestClass]
@@ -22,28 +21,32 @@ public void TestInitialize()
2221
this.commandLineService = new CommandLineInvocationService();
2322
}
2423

25-
[SkipTestIfNotWindows]
24+
[TestMethod]
25+
[OSCondition(OperatingSystems.Windows)]
2626
public async Task ShowsCmdExeAsExecutableAsync()
2727
{
2828
var result = await this.commandLineService.CanCommandBeLocatedAsync("cmd.exe", default, "/C");
2929
result.Should().BeTrue();
3030
}
3131

32-
[SkipTestIfNotWindows]
32+
[TestMethod]
33+
[OSCondition(OperatingSystems.Windows)]
3334
public async Task FallbackWorksIfBadCommandsAreFirstAsync()
3435
{
3536
var result = await this.commandLineService.CanCommandBeLocatedAsync("57AB44A4-885A-47F4-866C-41417133B983", ["fakecommandexecutable.exe", "cmd.exe"], "/C");
3637
result.Should().BeTrue();
3738
}
3839

39-
[SkipTestIfNotWindows]
40+
[TestMethod]
41+
[OSCondition(OperatingSystems.Windows)]
4042
public async Task ReturnsFalseIfNoValidCommandIsFoundAsync()
4143
{
4244
var result = await this.commandLineService.CanCommandBeLocatedAsync("57AB44A4-885A-47F4-866C-41417133B983", ["fakecommandexecutable.exe"], "/C");
4345
result.Should().BeFalse();
4446
}
4547

46-
[SkipTestIfNotWindows]
48+
[TestMethod]
49+
[OSCondition(OperatingSystems.Windows)]
4750
public async Task ReturnsStandardOutputAsync()
4851
{
4952
var isLocated = await this.commandLineService.CanCommandBeLocatedAsync("cmd.exe", default, "/C");
@@ -54,7 +57,8 @@ public async Task ReturnsStandardOutputAsync()
5457
taskResult.StdOut.Replace(Environment.NewLine, string.Empty).Should().Be("Expected Output");
5558
}
5659

57-
[SkipTestIfNotWindows]
60+
[TestMethod]
61+
[OSCondition(OperatingSystems.Windows)]
5862
public async Task ExecutesCommandEvenWithLargeStdOutAsync()
5963
{
6064
var isLocated = await this.commandLineService.CanCommandBeLocatedAsync("cmd.exe", default, "/C");
@@ -76,7 +80,8 @@ public async Task ExecutesCommandEvenWithLargeStdOutAsync()
7680
taskResult.StdOut.Length < 100 ? $"Stdout was '{taskResult.StdOut}', which is shorter than 8100 chars" : $"Length was {taskResult.StdOut.Length}, which is less than 8100");
7781
}
7882

79-
[SkipTestIfNotWindows]
83+
[TestMethod]
84+
[OSCondition(OperatingSystems.Windows)]
8085
public async Task ExecutesCommandCapturingErrorOutputAsync()
8186
{
8287
var isLocated = await this.commandLineService.CanCommandBeLocatedAsync("cmd.exe", default, "/C");
@@ -95,7 +100,8 @@ public async Task ExecutesCommandCapturingErrorOutputAsync()
95100
taskResult.StdOut.Should().BeEmpty();
96101
}
97102

98-
[SkipTestIfNotWindows]
103+
[TestMethod]
104+
[OSCondition(OperatingSystems.Windows)]
99105
public async Task ExecutesInAWorkingDirectoryAsync()
100106
{
101107
var isLocated = await this.commandLineService.CanCommandBeLocatedAsync("cmd.exe", default, "/C");
@@ -108,7 +114,8 @@ public async Task ExecutesInAWorkingDirectoryAsync()
108114
taskResult.StdOut.Should().Contain(tempDirectoryPath);
109115
}
110116

111-
[SkipTestIfNotWindows]
117+
[TestMethod]
118+
[OSCondition(OperatingSystems.Windows)]
112119
public async Task ThrowsIfWorkingDirectoryDoesNotExistAsync()
113120
{
114121
var isLocated = await this.commandLineService.CanCommandBeLocatedAsync("cmd.exe", default, "/C");

test/Microsoft.ComponentDetection.Common.Tests/DockerServiceTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace Microsoft.ComponentDetection.Common.Tests;
55
using System.Threading.Tasks;
66
using AwesomeAssertions;
77
using Docker.DotNet.Models;
8-
using Microsoft.ComponentDetection.TestsUtilities;
98
using Microsoft.Extensions.Logging;
109
using Microsoft.VisualStudio.TestTools.UnitTesting;
1110
using Moq;
@@ -31,21 +30,24 @@ public async Task DockerService_CanPingDockerAsync()
3130
canPingDocker.Should().BeTrue();
3231
}
3332

34-
[SkipTestOnWindows]
33+
[TestMethod]
34+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
3535
public async Task DockerService_CanRunLinuxContainersAsync()
3636
{
3737
var isLinuxContainerModeEnabled = await this.dockerService.CanRunLinuxContainersAsync();
3838
isLinuxContainerModeEnabled.Should().BeTrue();
3939
}
4040

41-
[SkipTestOnWindows]
41+
[TestMethod]
42+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
4243
public async Task DockerService_CanPullImageAsync()
4344
{
4445
Func<Task> action = async () => await this.dockerService.TryPullImageAsync(TestImage);
4546
await action.Should().NotThrowAsync();
4647
}
4748

48-
[SkipTestOnWindows]
49+
[TestMethod]
50+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
4951
public async Task DockerService_CanInspectImageAsync()
5052
{
5153
await this.dockerService.TryPullImageAsync(TestImage);
@@ -54,7 +56,8 @@ public async Task DockerService_CanInspectImageAsync()
5456
details.Tags.Should().Contain("governancecontainerregistry.azurecr.io/testcontainers/hello-world:latest");
5557
}
5658

57-
[SkipTestOnWindows]
59+
[TestMethod]
60+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
5861
public async Task DockerService_PopulatesBaseImageAndLayerDetailsAsync()
5962
{
6063
await this.dockerService.TryPullImageAsync(TestImageWithBaseDetails);
@@ -74,7 +77,8 @@ public async Task DockerService_PopulatesBaseImageAndLayerDetailsAsync()
7477
details.Layers.Should().ContainSingle();
7578
}
7679

77-
[SkipTestOnWindows]
80+
[TestMethod]
81+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
7882
public async Task DockerService_CanCreateAndRunImageAsync()
7983
{
8084
var (stdout, stderr) = await this.dockerService.CreateAndRunContainerAsync(TestImage, []);

test/Microsoft.ComponentDetection.Common.Tests/SafeFileEnumerableTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Microsoft.ComponentDetection.Common.Tests;
66
using System.IO;
77
using AwesomeAssertions;
88
using Microsoft.ComponentDetection.Contracts;
9-
using Microsoft.ComponentDetection.TestsUtilities;
109
using Microsoft.Extensions.Logging;
1110
using Microsoft.VisualStudio.TestTools.UnitTesting;
1211
using Moq;
@@ -93,7 +92,7 @@ public void GetEnumerator_IgnoresSubDirectories()
9392
}
9493

9594
[TestMethod]
96-
[SkipTestOnWindows]
95+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
9796
public void GetEnumerator_CallsSymlinkCode()
9897
{
9998
var subDir = Directory.CreateSymbolicLink(Path.Combine(this.temporaryDirectory, "SubDir"), this.temporaryDirectory);
@@ -115,7 +114,7 @@ public void GetEnumerator_CallsSymlinkCode()
115114
}
116115

117116
[TestMethod]
118-
[SkipTestOnWindows]
117+
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows)]
119118
public void GetEnumerator_DuplicatePathIgnored()
120119
{
121120
var subDir = Directory.CreateDirectory(Path.Combine(this.temporaryDirectory, "SubDir"));

test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentTests.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,17 @@ public void ConstructorTest_NameVersion()
3131
}
3232

3333
[TestMethod]
34-
[ExpectedException(typeof(ArgumentNullException))]
35-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
3634
public void ConstructorTest_NameVersion_NullVersion()
3735
{
38-
var goComponent = new GoComponent(TestName, null);
36+
var action = () => new GoComponent(TestName, null);
37+
action.Should().ThrowExactly<ArgumentNullException>();
3938
}
4039

4140
[TestMethod]
42-
[ExpectedException(typeof(ArgumentNullException))]
43-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
4441
public void ConstructorTest_NameVersion_NullName()
4542
{
46-
var goComponent = new GoComponent(null, TestVersion);
43+
var action = () => new GoComponent(null, TestVersion);
44+
action.Should().ThrowExactly<ArgumentNullException>();
4745
}
4846

4947
[TestMethod]
@@ -57,27 +55,24 @@ public void ConstructorTest_NameVersionHash()
5755
}
5856

5957
[TestMethod]
60-
[ExpectedException(typeof(ArgumentNullException))]
61-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
6258
public void ConstructorTest_NameVersionHash_NullVersion()
6359
{
64-
var goComponent = new GoComponent(TestName, null, TestHash);
60+
var action = () => new GoComponent(TestName, null, TestHash);
61+
action.Should().ThrowExactly<ArgumentNullException>();
6562
}
6663

6764
[TestMethod]
68-
[ExpectedException(typeof(ArgumentNullException))]
69-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
7065
public void ConstructorTest_NameVersionHash_NullName()
7166
{
72-
var goComponent = new GoComponent(null, TestVersion, TestHash);
67+
var action = () => new GoComponent(null, TestVersion, TestHash);
68+
action.Should().ThrowExactly<ArgumentNullException>();
7369
}
7470

7571
[TestMethod]
76-
[ExpectedException(typeof(ArgumentNullException))]
77-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
7872
public void ConstructorTest_NameVersionHash_NullHash()
7973
{
80-
var goComponent = new GoComponent(TestName, TestVersion, null);
74+
var action = () => new GoComponent(TestName, TestVersion, null);
75+
action.Should().ThrowExactly<ArgumentNullException>();
8176
}
8277

8378
[TestMethod]

test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestIfNotWindowsAttribute.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestOnWindowsAttribute.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)