Skip to content

Commit

Permalink
Use MSTest meta package (#1215)
Browse files Browse the repository at this point in the history
* Use MSTest meta package

This enables running MSTest Analyzers on test code to help avoid common test problems.

* Fix code coverage

* Fixes

Upgrade to latest and fix unnecessary type param

* Fix tests

* PR feedback

* Fix CC
  • Loading branch information
stan-sz authored Aug 22, 2024
1 parent 00edc78 commit 2dcd512
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: dotnet build --no-restore --configuration Debug

- name: Run tests
run: dotnet test --no-build --configuration Debug --collect:"XPlat Code Coverage"
run: dotnet test --no-build --configuration Debug --collect:"Code Coverage;Format=cobertura;CoverageFileName=coverage.cobertura.xml"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
Expand Down
6 changes: 1 addition & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.26.0" />
Expand All @@ -17,15 +15,13 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14" />
<PackageVersion Include="DotNet.Glob" Version="2.1.1" />
<PackageVersion Include="MinVer" Version="5.0.0" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="morelinq" Version="4.2.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.4.3" />
<PackageVersion Include="MSTest" Version="3.5.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Newtonsoft.Json.Schema" Version="3.0.16" />
<PackageVersion Include="NuGet.ProjectModel" Version="6.10.0" />
Expand Down
3 changes: 1 addition & 2 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>

<ItemGroup Label="Package References">
<PackageReference Include="MSTest.TestAdapter"/>
<PackageReference Include="MSTest.TestFramework"/>
<PackageReference Include="MSTest"/>
<PackageReference Include="Moq"/>
<PackageReference Include="FluentAssertions"/>
<PackageReference Include="Faker.net"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="coverlet.collector" PrivateAssets="all" />
<PackageReference Include="Docker.DotNet" />
<PackageReference Include="FluentAssertions.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="coverlet.collector" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Reactive" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
<PackageReference Include="packageurl-dotnet" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Microsoft.ComponentDetection.Detectors.Tests;
namespace Microsoft.ComponentDetection.Detectors.Tests;

using System;
using FluentAssertions;
Expand Down Expand Up @@ -31,13 +31,15 @@ public void ConstructorTest_NameVersion()

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
public void ConstructorTest_NameVersion_NullVersion()
{
var goComponent = new GoComponent(TestName, null);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
public void ConstructorTest_NameVersion_NullName()
{
var goComponent = new GoComponent(null, TestVersion);
Expand All @@ -55,20 +57,23 @@ public void ConstructorTest_NameVersionHash()

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
public void ConstructorTest_NameVersionHash_NullVersion()
{
var goComponent = new GoComponent(TestName, null, TestHash);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
public void ConstructorTest_NameVersionHash_NullName()
{
var goComponent = new GoComponent(null, TestVersion, TestHash);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")]
public void ConstructorTest_NameVersionHash_NullHash()
{
var goComponent = new GoComponent(TestName, TestVersion, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public async Task GenerateDependenciesFile_SuccessWithTimeoutVariableTimeoutAsyn

this.environmentVarServiceMock
.Setup(x => x.GetEnvironmentVariable(MavenCommandService.MvnCLIFileLevelTimeoutSecondsEnvVar))
.Returns("0");
.Returns("0")
.Callback(() => cts.Cancel());

this.commandLineMock.Setup(x => x.ExecuteCommandAsync(
MavenCommandService.PrimaryCommand,
Expand Down Expand Up @@ -260,7 +261,7 @@ public void ParseDependenciesFile_Success()

protected bool ShouldBeEquivalentTo<T>(IEnumerable<T> result, IEnumerable<T> expected)
{
result.Should<T>().BeEquivalentTo(expected);
result.Should().BeEquivalentTo(expected);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="coverlet.collector" PrivateAssets="all" />
<PackageReference Include="FluentAssertions.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NuGet.Versioning" />
<PackageReference Include="SemanticVersioning" />
<PackageReference Include="System.Reactive" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="coverlet.collector" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Serilog" />
<PackageReference Include="Spectre.Console.Cli" />
<PackageReference Include="Spectre.Console.Testing" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
</PropertyGroup>

<ItemGroup>
<!--<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<!--<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
IF TESTING LOCALLY, UNCOMMENT ABOVE AND COMMENT BELOW -->
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="MSTest" />
<PackageReference Include="Newtonsoft.Json.Schema" />
<PackageReference Include="packageurl-dotnet" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
Expand Down

0 comments on commit 2dcd512

Please sign in to comment.