1
+ using System ;
2
+ using GitVersion ;
3
+ using GitVersionCore . Tests ;
4
+ using NUnit . Framework ;
5
+ using Shouldly ;
6
+ using System . Collections . Generic ;
7
+
8
+ [ TestFixture ]
9
+ public class VsoAgentBuildNumberTests
10
+ {
11
+ string key = "BUILD_BUILDNUMBER" ;
12
+ string logPrefix = "##vso[build.updatebuildnumber]" ;
13
+ List < Tuple < string , string , string > > examples ;
14
+ VsoAgent versionBuilder = new VsoAgent ( ) ;
15
+
16
+ [ SetUp ]
17
+ public void SetUpVsoAgentBuildNumberTest ( )
18
+ {
19
+ examples = new List < Tuple < string , string , string > > ( ) ;
20
+ }
21
+
22
+ [ TearDown ]
23
+ public void TearDownVsoAgentBuildNumberTest ( )
24
+ {
25
+ examples = null ;
26
+ Environment . SetEnvironmentVariable ( key , null , EnvironmentVariableTarget . Process ) ;
27
+ }
28
+
29
+
30
+ [ Test ]
31
+ public void VsoAgentBuildNumberWithFullSemVer ( )
32
+ {
33
+ examples . Add ( new Tuple < string , string , string > ( "$(GitVersion.FullSemVer)" , "1.0.0" , "1.0.0" ) ) ;
34
+ examples . Add ( new Tuple < string , string , string > ( "$(GITVERSION_FULLSEMVER)" , "1.0.0" , "1.0.0" ) ) ;
35
+ examples . Add ( new Tuple < string , string , string > ( "$(GitVersion.FullSemVer)-Build.1234" , "1.0.0" , "1.0.0-Build.1234" ) ) ;
36
+ examples . Add ( new Tuple < string , string , string > ( "$(GITVERSION_FULLSEMVER)-Build.1234" , "1.0.0" , "1.0.0-Build.1234" ) ) ;
37
+
38
+ foreach ( var example in examples )
39
+ {
40
+ Environment . SetEnvironmentVariable ( key , example . Item1 , EnvironmentVariableTarget . Process ) ;
41
+ var vars = new TestableVersionVariables ( fullSemVer : example . Item2 ) ;
42
+
43
+ var logMessage = versionBuilder . GenerateSetVersionMessage ( vars ) ;
44
+ logMessage . ShouldBe ( logPrefix + example . Item3 ) ;
45
+ }
46
+ }
47
+
48
+
49
+ [ Test ]
50
+ public void VsoAgentBuildNumberWithSemVer ( )
51
+ {
52
+ examples . Add ( new Tuple < string , string , string > ( "$(GitVersion.SemVer)" , "1.0.0" , "1.0.0" ) ) ;
53
+ examples . Add ( new Tuple < string , string , string > ( "$(GITVERSION_SEMVER)" , "1.0.0" , "1.0.0" ) ) ;
54
+ examples . Add ( new Tuple < string , string , string > ( "$(GitVersion.SemVer)-Build.1234" , "1.0.0" , "1.0.0-Build.1234" ) ) ;
55
+ examples . Add ( new Tuple < string , string , string > ( "$(GITVERSION_SEMVER)-Build.1234" , "1.0.0" , "1.0.0-Build.1234" ) ) ;
56
+
57
+ foreach ( var example in examples )
58
+ {
59
+ Environment . SetEnvironmentVariable ( key , example . Item1 , EnvironmentVariableTarget . Process ) ;
60
+ var vars = new TestableVersionVariables ( semVer : example . Item2 ) ;
61
+
62
+ var logMessage = versionBuilder . GenerateSetVersionMessage ( vars ) ;
63
+ logMessage . ShouldBe ( logPrefix + example . Item3 ) ;
64
+ }
65
+ }
66
+
67
+ }
0 commit comments