Skip to content

Commit 9deb917

Browse files
authored
Merge pull request #2 from dorssel/cobertura
Fix coverage output
2 parents 80d2427 + f9c5579 commit 9deb917

File tree

7 files changed

+129
-5
lines changed

7 files changed

+129
-5
lines changed

.github/workflows/dotnet.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ jobs:
5151
- name: Test
5252
run: |
5353
dotnet run --configuration Release --no-build --project Example
54-
dotnet test --configuration Release --no-build -p:TestingPlatformCommandLineArguments="--report-trx --coverage"
54+
dotnet test --configuration Release --no-build \
55+
-p:TestingPlatformCommandLineArguments="--report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml"
5556
5657
- name: Package
5758
run: dotnet pack --configuration Release --no-build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
.vscode/
77
bin/
88
obj/
9+
TestResults/
910

1011
*.user

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ SPDX-License-Identifier: MIT
88
<ItemGroup>
99
<!-- GitVersion.MsBuild -->
1010
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.12.6" />
11+
<!-- UnitTests -->
12+
<PackageVersion Include="Moq" Version="4.20.72" />
1113
</ItemGroup>
1214
</Project>

GitVersion.MsBuild/GenerateGitVersionInformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class GenerateGitVersionInformation
2020
[Required]
2121
public string Language { get; set; } = "C#";
2222

23-
public string? UseProjectNamespaceForGitVersionInformation { get; set; } = string.Empty;
23+
public string? UseProjectNamespaceForGitVersionInformation { get; set; }
2424

2525
public string RootNamespace { get; set; } = string.Empty;
2626

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: MIT
66

77
# GitVersion.MsBuild (netstandard2.0, Visual Studio compatible)
88

9-
[![Build](https://github.com/dorssel/gitversion-msbuild/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ABuild+branch%3Amain)
9+
[![Build](https://github.com/dorssel/gitversion-msbuild/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ABuild+branch%3Amain)
1010
[![CodeQL](https://github.com/dorssel/gitversion-msbuild/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ACodeQL+branch%3Amain)
1111
[![Lint](https://github.com/dorssel/gitversion-msbuild/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ALint+branch%3Amain)
1212
[![REUSE status](https://api.reuse.software/badge/github.com/dorssel/gitversion-msbuild)](https://api.reuse.software/info/github.com/dorssel/gitversion-msbuild)

UnitTests/TaskTests.cs

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// SPDX-License-Identifier: MIT
44

55
using System.Reflection;
6+
using Dorssel.GitVersion.MsBuild;
7+
using Microsoft.Build.Framework;
8+
using Moq;
69

710
namespace UnitTests;
811

@@ -25,15 +28,131 @@ static string GetVersionFile()
2528
throw new FileNotFoundException("gitversion.json");
2629
}
2730

31+
[TestMethod]
32+
public void GetVersion_Normal()
33+
{
34+
var buildEngine = new Mock<IBuildEngine>();
35+
var task = new GetVersion
36+
{
37+
BuildEngine = buildEngine.Object,
38+
VersionFile = GetVersionFile(),
39+
SolutionDirectory = TestContext.TestRunDirectory!
40+
};
41+
var result = task.Execute();
42+
Assert.IsTrue(result);
43+
}
44+
2845
[TestMethod]
2946
public void GenerateGitVersionInformation_WithIntermediateOutputPath()
3047
{
31-
var task = new Dorssel.GitVersion.MsBuild.GenerateGitVersionInformation
48+
var buildEngine = new Mock<IBuildEngine>();
49+
var task = new GenerateGitVersionInformation
50+
{
51+
BuildEngine = buildEngine.Object,
52+
VersionFile = GetVersionFile(),
53+
SolutionDirectory = TestContext.TestRunDirectory!,
54+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!)
55+
};
56+
var result = task.Execute();
57+
Assert.IsTrue(result);
58+
}
59+
60+
[TestMethod]
61+
public void GenerateGitVersionInformation_UnknownLanguage()
62+
{
63+
var buildEngine = new Mock<IBuildEngine>();
64+
var task = new GenerateGitVersionInformation
65+
{
66+
BuildEngine = buildEngine.Object,
67+
VersionFile = GetVersionFile(),
68+
SolutionDirectory = TestContext.TestRunDirectory!,
69+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
70+
Language = "Unknown"
71+
};
72+
var result = task.Execute();
73+
Assert.IsFalse(result);
74+
}
75+
76+
[TestMethod]
77+
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_Invalid()
78+
{
79+
var buildEngine = new Mock<IBuildEngine>();
80+
var task = new GenerateGitVersionInformation
3281
{
82+
BuildEngine = buildEngine.Object,
3383
VersionFile = GetVersionFile(),
34-
IntermediateOutputPath = TestContext.TestRunDirectory!
84+
SolutionDirectory = TestContext.TestRunDirectory!,
85+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
86+
UseProjectNamespaceForGitVersionInformation = "invalid"
3587
};
3688
var result = task.Execute();
3789
Assert.IsTrue(result);
3890
}
91+
92+
[TestMethod]
93+
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_False()
94+
{
95+
var buildEngine = new Mock<IBuildEngine>();
96+
var task = new GenerateGitVersionInformation
97+
{
98+
BuildEngine = buildEngine.Object,
99+
VersionFile = GetVersionFile(),
100+
SolutionDirectory = TestContext.TestRunDirectory!,
101+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
102+
UseProjectNamespaceForGitVersionInformation = "false"
103+
};
104+
var result = task.Execute();
105+
Assert.IsTrue(result);
106+
}
107+
108+
[TestMethod]
109+
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_True()
110+
{
111+
var buildEngine = new Mock<IBuildEngine>();
112+
var task = new GenerateGitVersionInformation
113+
{
114+
BuildEngine = buildEngine.Object,
115+
VersionFile = GetVersionFile(),
116+
SolutionDirectory = TestContext.TestRunDirectory!,
117+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
118+
UseProjectNamespaceForGitVersionInformation = "true",
119+
RootNamespace = "Test.Namespace"
120+
};
121+
var result = task.Execute();
122+
Assert.IsTrue(result);
123+
}
124+
125+
[TestMethod]
126+
public void GenerateGitVersionInformation_RootNamespace_Empty()
127+
{
128+
var buildEngine = new Mock<IBuildEngine>();
129+
var task = new GenerateGitVersionInformation
130+
{
131+
BuildEngine = buildEngine.Object,
132+
VersionFile = GetVersionFile(),
133+
SolutionDirectory = TestContext.TestRunDirectory!,
134+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
135+
UseProjectNamespaceForGitVersionInformation = "true",
136+
ProjectFile = "TestProject.csproj"
137+
};
138+
var result = task.Execute();
139+
Assert.IsTrue(result);
140+
}
141+
142+
[TestMethod]
143+
public void GenerateGitVersionInformation_Twice()
144+
{
145+
var buildEngine = new Mock<IBuildEngine>();
146+
var task = new GenerateGitVersionInformation
147+
{
148+
BuildEngine = buildEngine.Object,
149+
VersionFile = GetVersionFile(),
150+
SolutionDirectory = TestContext.TestRunDirectory!,
151+
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!)
152+
};
153+
var result = task.Execute();
154+
Assert.IsTrue(result);
155+
result = task.Execute();
156+
Assert.IsTrue(result);
157+
}
39158
}

UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SPDX-License-Identifier: MIT
2121

2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.Build.Utilities.Core" />
24+
<PackageReference Include="Moq" />
2425
</ItemGroup>
2526

2627
</Project>

0 commit comments

Comments
 (0)