@@ -9,157 +9,190 @@ namespace GitVersion.MsBuild.Tests.Tasks;
99[ TestFixture ]
1010public class UpdateAssemblyInfoTaskTest : TestTaskBase
1111{
12- [ Test ]
13- public void UpdateAssemblyInfoTaskShouldCreateFile ( )
12+ private static readonly object [ ] Languages =
1413 {
15- var task = new UpdateAssemblyInfo ( ) ;
14+ new object [ ] { "C#" } ,
15+ new object [ ] { "F#" } ,
16+ new object [ ] { "VB" } ,
17+ } ;
18+
19+ [ TestCaseSource ( nameof ( Languages ) ) ]
20+ public void UpdateAssemblyInfoTaskShouldCreateFile ( string language )
21+ {
22+ var extension = FileHelper . GetFileExtension ( language ) ;
23+ var task = new UpdateAssemblyInfo { Language = language } ;
1624
1725 using var result = ExecuteMsBuildTask ( task ) ;
1826
1927 result . Success . ShouldBe ( true ) ;
2028 result . Errors . ShouldBe ( 0 ) ;
2129 result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
30+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
2231
2332 var fileContent = File . ReadAllText ( result . Task . AssemblyInfoTempFilePath ) ;
24- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.2.4.0"")] " ) ;
33+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.2.4.0"")" ) ;
2534 }
2635
27- [ Test ]
28- public void UpdateAssemblyInfoTaskShouldCreateFileInBuildServer ( )
36+ [ TestCaseSource ( nameof ( Languages ) ) ]
37+ public void UpdateAssemblyInfoTaskShouldCreateFileInBuildServer ( string language )
2938 {
30- var task = new UpdateAssemblyInfo ( ) ;
39+ var extension = FileHelper . GetFileExtension ( language ) ;
40+ var task = new UpdateAssemblyInfo { Language = language } ;
3141
3242 using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
3343
3444 result . Success . ShouldBe ( true ) ;
3545 result . Errors . ShouldBe ( 0 ) ;
3646 result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
47+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
3748
3849 var fileContent = File . ReadAllText ( result . Task . AssemblyInfoTempFilePath ) ;
39- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.0.1.0"")] " ) ;
50+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.0.1.0"")" ) ;
4051 }
4152
42- [ Test ]
43- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuild ( )
53+ [ TestCaseSource ( nameof ( Languages ) ) ]
54+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuild ( string language )
4455 {
4556 const string taskName = nameof ( UpdateAssemblyInfo ) ;
4657 const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
4758
48- using var result = ExecuteMsBuildExe ( project => AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty ) ) ;
59+ var extension = FileHelper . GetFileExtension ( language ) ;
60+ using var result = ExecuteMsBuildExe ( project =>
61+ AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , language ) , language ) ;
4962
5063 result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
5164 result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
5265 result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
5366 result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
5467 result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
5568
56- var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , "AssemblyInfo.g.cs " ) ;
69+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , $ "AssemblyInfo.g.{ extension } ") ;
5770 result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
5871
5972 var fileContent = File . ReadAllText ( generatedFilePath ) ;
60- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.2.4.0"")] " ) ;
73+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.2.4.0"")" ) ;
6174 }
6275
63- [ Test ]
64- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServer ( )
76+ [ TestCaseSource ( nameof ( Languages ) ) ]
77+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServer ( string language )
6578 {
6679 const string taskName = nameof ( UpdateAssemblyInfo ) ;
6780 const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
6881
69- using var result = ExecuteMsBuildExeInAzurePipeline ( project => AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty ) ) ;
82+ var extension = FileHelper . GetFileExtension ( language ) ;
83+ using var result = ExecuteMsBuildExeInAzurePipeline ( project =>
84+ AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , language ) , language ) ;
7085
7186 result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
7287 result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
7388 result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
7489 result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
7590 result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
7691
77- var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , "AssemblyInfo.g.cs " ) ;
92+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , $ "AssemblyInfo.g.{ extension } ") ;
7893 result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
7994
8095 var fileContent = File . ReadAllText ( generatedFilePath ) ;
81- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.0.1.0"")] " ) ;
96+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.0.1.0"")" ) ;
8297 }
8398
84- [ Test ]
85- public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( )
99+ [ TestCaseSource ( nameof ( Languages ) ) ]
100+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( string language )
86101 {
87- var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
102+ var extension = FileHelper . GetFileExtension ( language ) ;
103+ var task = new UpdateAssemblyInfo { Language = language , IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
88104
89105 using var result = ExecuteMsBuildTask ( task ) ;
90106
91107 result . Success . ShouldBe ( true ) ;
92108 result . Errors . ShouldBe ( 0 ) ;
93109 result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
110+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
94111
95112 var fileContent = File . ReadAllText ( result . Task . AssemblyInfoTempFilePath ) ;
96- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.2.4.0"")] " ) ;
113+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.2.4.0"")" ) ;
97114 }
98115
99- [ Test ]
100- public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer ( )
116+ [ TestCaseSource ( nameof ( Languages ) ) ]
117+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer ( string language )
101118 {
102- var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
119+ var extension = FileHelper . GetFileExtension ( language ) ;
120+ var task = new UpdateAssemblyInfo { Language = language , IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
103121
104122 using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
105123
106124 result . Success . ShouldBe ( true ) ;
107125 result . Errors . ShouldBe ( 0 ) ;
108126 result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
127+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
109128
110129 var fileContent = File . ReadAllText ( result . Task . AssemblyInfoTempFilePath ) ;
111- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.0.1.0"")] " ) ;
130+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.0.1.0"")" ) ;
112131 }
113132
114- [ Test ]
115- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( )
133+ [ TestCaseSource ( nameof ( Languages ) ) ]
134+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( string language )
116135 {
117136 const string taskName = nameof ( UpdateAssemblyInfo ) ;
118137 const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
119138 var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
120139
121- using var result = ExecuteMsBuildExe ( project => AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
140+ var extension = FileHelper . GetFileExtension ( language ) ;
141+ using var result = ExecuteMsBuildExe ( project =>
142+ {
143+ var intermediateOutputPath = Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ;
144+ AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , language , intermediateOutputPath ) ;
145+ } , language ) ;
122146
123147 result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
124148 result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
125149 result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
126150 result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
127151 result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
128152
129- var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "AssemblyInfo.g.cs " ) ;
153+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , $ "AssemblyInfo.g.{ extension } ") ;
130154 result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
131155
132156 var fileContent = File . ReadAllText ( generatedFilePath ) ;
133- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.2.4.0"")] " ) ;
157+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.2.4.0"")" ) ;
134158 }
135159
136- [ Test ]
137- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( )
160+ [ TestCaseSource ( nameof ( Languages ) ) ]
161+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( string language )
138162 {
139163 const string taskName = nameof ( UpdateAssemblyInfo ) ;
140164 const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
141165 var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
142166
143- using var result = ExecuteMsBuildExeInAzurePipeline ( project => AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
167+ var extension = FileHelper . GetFileExtension ( language ) ;
168+ using var result = ExecuteMsBuildExeInAzurePipeline ( project =>
169+ {
170+ var intermediateOutputPath = Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ;
171+ AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , language , intermediateOutputPath ) ;
172+ } , language ) ;
144173
145174 result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
146175 result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
147176 result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
148177 result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
149178 result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
150179
151- var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "AssemblyInfo.g.cs " ) ;
180+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , $ "AssemblyInfo.g.{ extension } ") ;
152181 result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
153182
154183 var fileContent = File . ReadAllText ( generatedFilePath ) ;
155- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.0.1.0"")] " ) ;
184+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.0.1.0"")" ) ;
156185 }
157186
158- private static void AddUpdateAssemblyInfoTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty , string intermediateOutputPath = "$(MSBuildProjectDirectory)" )
187+ private static void AddUpdateAssemblyInfoTask ( ProjectCreator project , string targetToRun , string taskName ,
188+ string outputProperty , string language ,
189+ string intermediateOutputPath = "$(MSBuildProjectDirectory)" )
159190 {
160191 var assemblyFileLocation = typeof ( GitVersionTaskBase ) . Assembly . Location ;
161192 project . UsingTaskAssemblyFile ( taskName , assemblyFileLocation )
193+ . Property ( "ManagePackageVersionsCentrally" , "false" )
162194 . Property ( "GenerateAssemblyInfo" , "false" )
195+ . Property ( "Language" , language )
163196 . Target ( targetToRun , beforeTargets : "CoreCompile;GetAssemblyVersion;GenerateNuspec" )
164197 . Task ( taskName , parameters : new Dictionary < string , string ? >
165198 {
0 commit comments