@@ -100,18 +100,108 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildI
100
100
fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.0.1+1""") ;
101
101
}
102
102
103
- private static void AddGenerateGitVersionInformationTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty )
103
+ [ Test ]
104
+ public void GenerateGitVersionInformationTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( )
105
+ {
106
+ var task = new GenerateGitVersionInformation { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
107
+
108
+ using var result = ExecuteMsBuildTask ( task ) ;
109
+
110
+ result . Success . ShouldBe ( true ) ;
111
+ result . Errors . ShouldBe ( 0 ) ;
112
+ result . Task . GitVersionInformationFilePath . ShouldNotBeNull ( ) ;
113
+
114
+ var fileContent = File . ReadAllText ( result . Task . GitVersionInformationFilePath ) ;
115
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
116
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""2""") ;
117
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""4""") ;
118
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.2.4""") ;
119
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.2.4+1""") ;
120
+ }
121
+
122
+ [ Test ]
123
+ public void GenerateGitVersionInformationTaskShouldCreateFileInBuildServerWhenIntermediateOutputPathDoesNotExist ( )
124
+ {
125
+ var task = new GenerateGitVersionInformation { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
126
+
127
+ using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
128
+
129
+ result . Success . ShouldBe ( true ) ;
130
+ result . Errors . ShouldBe ( 0 ) ;
131
+ result . Task . GitVersionInformationFilePath . ShouldNotBeNull ( ) ;
132
+
133
+ var fileContent = File . ReadAllText ( result . Task . GitVersionInformationFilePath ) ;
134
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
135
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""0""") ;
136
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""1""") ;
137
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.0.1""") ;
138
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.0.1+1""") ;
139
+ }
140
+
141
+ [ Test ]
142
+ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( )
143
+ {
144
+ const string taskName = nameof ( GenerateGitVersionInformation ) ;
145
+ const string outputProperty = nameof ( GenerateGitVersionInformation . GitVersionInformationFilePath ) ;
146
+ var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
147
+
148
+ using var result = ExecuteMsBuildExe ( project => AddGenerateGitVersionInformationTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
149
+
150
+ result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
151
+ result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
152
+ result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
153
+ result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
154
+ result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
155
+
156
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "GitVersionInformation.g.cs" ) ;
157
+ result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
158
+
159
+ var fileContent = File . ReadAllText ( generatedFilePath ) ;
160
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
161
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""2""") ;
162
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""4""") ;
163
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.2.4""") ;
164
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.2.4+1""") ;
165
+ }
166
+
167
+ [ Test ]
168
+ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( )
169
+ {
170
+ const string taskName = nameof ( GenerateGitVersionInformation ) ;
171
+ const string outputProperty = nameof ( GenerateGitVersionInformation . GitVersionInformationFilePath ) ;
172
+ var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
173
+
174
+ using var result = ExecuteMsBuildExeInAzurePipeline ( project => AddGenerateGitVersionInformationTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
175
+
176
+ result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
177
+ result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
178
+ result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
179
+ result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
180
+ result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
181
+
182
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "GitVersionInformation.g.cs" ) ;
183
+ result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
184
+
185
+ var fileContent = File . ReadAllText ( generatedFilePath ) ;
186
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
187
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""0""") ;
188
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""1""") ;
189
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.0.1""") ;
190
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.0.1+1""") ;
191
+ }
192
+
193
+ private static void AddGenerateGitVersionInformationTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty , string intermediateOutputPath = "$(MSBuildProjectDirectory)" )
104
194
{
105
195
var assemblyFileLocation = typeof ( GitVersionTaskBase ) . Assembly . Location ;
106
196
project . UsingTaskAssemblyFile ( taskName , assemblyFileLocation )
107
197
. Property ( "GenerateAssemblyInfo" , "false" )
108
198
. Target ( targetToRun , beforeTargets : "CoreCompile;GetAssemblyVersion;GenerateNuspec" )
109
- . Task ( taskName , parameters : new Dictionary < string , string >
199
+ . Task ( taskName , parameters : new Dictionary < string , string ? >
110
200
{
111
201
{ "SolutionDirectory" , "$(MSBuildProjectDirectory)" } ,
112
202
{ "VersionFile" , "$(MSBuildProjectDirectory)/gitversion.json" } ,
113
203
{ "ProjectFile" , "$(MSBuildProjectFullPath)" } ,
114
- { "IntermediateOutputPath" , "$(MSBuildProjectDirectory)" } ,
204
+ { "IntermediateOutputPath" , intermediateOutputPath } ,
115
205
{ "Language" , "$(Language)" }
116
206
} )
117
207
. TaskOutputProperty ( outputProperty , outputProperty )
0 commit comments