Skip to content

Commit

Permalink
Merge pull request #1260 from dpurge/bugfix/1257
Browse files Browse the repository at this point in the history
VsoAgentBuildNumberTests refactored with accordance to the remark from @asbjornu
  • Loading branch information
JakeGinnivan authored Dec 5, 2017
2 parents b166638 + bb7b195 commit e51c088
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions src/GitVersionCore.Tests/BuildServers/VsoAgentBuildNumberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,44 @@
using GitVersionCore.Tests;
using NUnit.Framework;
using Shouldly;
using System.Collections.Generic;

[TestFixture]
public class VsoAgentBuildNumberTests
{
string key = "BUILD_BUILDNUMBER";
string logPrefix = "##vso[build.updatebuildnumber]";
List<Tuple<string, string, string>> examples;
VsoAgent versionBuilder = new VsoAgent();

[SetUp]
public void SetUpVsoAgentBuildNumberTest()
{
examples = new List<Tuple<string, string, string>>();
}

[TearDown]
public void TearDownVsoAgentBuildNumberTest()
{
examples = null;
Environment.SetEnvironmentVariable(key, null, EnvironmentVariableTarget.Process);
}


[Test]
public void VsoAgentBuildNumberWithFullSemVer()
[TestCase("$(GitVersion.FullSemVer)", "1.0.0", "1.0.0")]
[TestCase("$(GITVERSION_FULLSEMVER)", "1.0.0", "1.0.0")]
[TestCase("$(GitVersion.FullSemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234")]
[TestCase("$(GITVERSION_FULLSEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234")]
public void VsoAgentBuildNumberWithFullSemVer(string buildNumberFormat, string myFullSemVer, string expectedBuildNumber)
{
examples.Add(new Tuple<string, string, string>("$(GitVersion.FullSemVer)", "1.0.0", "1.0.0"));
examples.Add(new Tuple<string, string, string>("$(GITVERSION_FULLSEMVER)", "1.0.0", "1.0.0"));
examples.Add(new Tuple<string, string, string>("$(GitVersion.FullSemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234"));
examples.Add(new Tuple<string, string, string>("$(GITVERSION_FULLSEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234"));

foreach (var example in examples)
{
Environment.SetEnvironmentVariable(key, example.Item1, EnvironmentVariableTarget.Process);
var vars = new TestableVersionVariables(fullSemVer: example.Item2);

var logMessage = versionBuilder.GenerateSetVersionMessage(vars);
logMessage.ShouldBe(logPrefix + example.Item3);
}
Environment.SetEnvironmentVariable(key, buildNumberFormat, EnvironmentVariableTarget.Process);
var vars = new TestableVersionVariables(fullSemVer: myFullSemVer);
var logMessage = versionBuilder.GenerateSetVersionMessage(vars);
logMessage.ShouldBe(logPrefix + expectedBuildNumber);
}


[Test]
public void VsoAgentBuildNumberWithSemVer()
[TestCase("$(GitVersion.SemVer)", "1.0.0", "1.0.0")]
[TestCase("$(GITVERSION_SEMVER)", "1.0.0", "1.0.0")]
[TestCase("$(GitVersion.SemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234")]
[TestCase("$(GITVERSION_SEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234")]
public void VsoAgentBuildNumberWithSemVer(string buildNumberFormat, string mySemVer, string expectedBuildNumber)
{
examples.Add(new Tuple<string, string, string>("$(GitVersion.SemVer)", "1.0.0", "1.0.0"));
examples.Add(new Tuple<string, string, string>("$(GITVERSION_SEMVER)", "1.0.0", "1.0.0"));
examples.Add(new Tuple<string, string, string>("$(GitVersion.SemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234"));
examples.Add(new Tuple<string, string, string>("$(GITVERSION_SEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234"));

foreach (var example in examples)
{
Environment.SetEnvironmentVariable(key, example.Item1, EnvironmentVariableTarget.Process);
var vars = new TestableVersionVariables(semVer: example.Item2);

var logMessage = versionBuilder.GenerateSetVersionMessage(vars);
logMessage.ShouldBe(logPrefix + example.Item3);
}
Environment.SetEnvironmentVariable(key, buildNumberFormat, EnvironmentVariableTarget.Process);
var vars = new TestableVersionVariables(semVer: mySemVer);
var logMessage = versionBuilder.GenerateSetVersionMessage(vars);
logMessage.ShouldBe(logPrefix + expectedBuildNumber);
}

}

0 comments on commit e51c088

Please sign in to comment.