* 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
This commit is contained in:
stan-sz 2024-08-22 14:03:39 +02:00 коммит произвёл GitHub
Родитель 00edc78bf5
Коммит 2dcd512bfa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
10 изменённых файлов: 14 добавлений и 23 удалений

2
.github/workflows/build.yml поставляемый
Просмотреть файл

@ -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

Просмотреть файл

@ -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" />
@ -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" />

Просмотреть файл

@ -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"/>

Просмотреть файл

@ -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>

Просмотреть файл

@ -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" />

Просмотреть файл

@ -1,4 +1,4 @@
namespace Microsoft.ComponentDetection.Detectors.Tests;
namespace Microsoft.ComponentDetection.Detectors.Tests;
using System;
using FluentAssertions;
@ -31,6 +31,7 @@ public class GoComponentTests
[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);
@ -38,6 +39,7 @@ public class GoComponentTests
[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);
@ -55,6 +57,7 @@ public class GoComponentTests
[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);
@ -62,6 +65,7 @@ public class GoComponentTests
[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);
@ -69,6 +73,7 @@ public class GoComponentTests
[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);

Просмотреть файл

@ -185,7 +185,8 @@ public class MavenCommandServiceTests
this.environmentVarServiceMock
.Setup(x => x.GetEnvironmentVariable(MavenCommandService.MvnCLIFileLevelTimeoutSecondsEnvVar))
.Returns("0");
.Returns("0")
.Callback(() => cts.Cancel());
this.commandLineMock.Setup(x => x.ExecuteCommandAsync(
MavenCommandService.PrimaryCommand,
@ -260,7 +261,7 @@ public class MavenCommandServiceTests
protected bool ShouldBeEquivalentTo<T>(IEnumerable<T> result, IEnumerable<T> expected)
{
result.Should<T>().BeEquivalentTo(expected);
result.Should().BeEquivalentTo(expected);
return true;
}
}

Просмотреть файл

@ -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" />

Просмотреть файл

@ -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" />

Просмотреть файл

@ -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" />