Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ jobs:
- name: Test
run: |
dotnet run --configuration Release --no-build --project Example
dotnet test --configuration Release --no-build -p:TestingPlatformCommandLineArguments="--report-trx --coverage"
dotnet test --configuration Release --no-build \
-p:TestingPlatformCommandLineArguments="--report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml"
- name: Package
run: dotnet pack --configuration Release --no-build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
.vscode/
bin/
obj/
TestResults/

*.user
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ SPDX-License-Identifier: MIT
<ItemGroup>
<!-- GitVersion.MsBuild -->
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.12.6" />
<!-- UnitTests -->
<PackageVersion Include="Moq" Version="4.20.72" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion GitVersion.MsBuild/GenerateGitVersionInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GenerateGitVersionInformation
[Required]
public string Language { get; set; } = "C#";

public string? UseProjectNamespaceForGitVersionInformation { get; set; } = string.Empty;
public string? UseProjectNamespaceForGitVersionInformation { get; set; }

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: MIT

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

[![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)
[![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)
[![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)
[![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)
[![REUSE status](https://api.reuse.software/badge/github.com/dorssel/gitversion-msbuild)](https://api.reuse.software/info/github.com/dorssel/gitversion-msbuild)
Expand Down
123 changes: 121 additions & 2 deletions UnitTests/TaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// SPDX-License-Identifier: MIT

using System.Reflection;
using Dorssel.GitVersion.MsBuild;
using Microsoft.Build.Framework;
using Moq;

namespace UnitTests;

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

[TestMethod]
public void GetVersion_Normal()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GetVersion
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_WithIntermediateOutputPath()
{
var task = new Dorssel.GitVersion.MsBuild.GenerateGitVersionInformation
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!)
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UnknownLanguage()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
Language = "Unknown"
};
var result = task.Execute();
Assert.IsFalse(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_Invalid()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
IntermediateOutputPath = TestContext.TestRunDirectory!
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "invalid"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_False()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "false"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_True()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "true",
RootNamespace = "Test.Namespace"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_RootNamespace_Empty()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "true",
ProjectFile = "TestProject.csproj"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_Twice()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!)
};
var result = task.Execute();
Assert.IsTrue(result);
result = task.Execute();
Assert.IsTrue(result);
}
}
1 change: 1 addition & 0 deletions UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SPDX-License-Identifier: MIT

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" />
<PackageReference Include="Moq" />
</ItemGroup>

</Project>
Loading