@@ -9,157 +9,190 @@ namespace GitVersion.MsBuild.Tests.Tasks;
9
9
[ TestFixture ]
10
10
public class UpdateAssemblyInfoTaskTest : TestTaskBase
11
11
{
12
- [ Test ]
13
- public void UpdateAssemblyInfoTaskShouldCreateFile ( )
12
+ private static readonly object [ ] Languages =
14
13
{
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 } ;
16
24
17
25
using var result = ExecuteMsBuildTask ( task ) ;
18
26
19
27
result . Success . ShouldBe ( true ) ;
20
28
result . Errors . ShouldBe ( 0 ) ;
21
29
result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
30
+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
22
31
23
32
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"")" ) ;
25
34
}
26
35
27
- [ Test ]
28
- public void UpdateAssemblyInfoTaskShouldCreateFileInBuildServer ( )
36
+ [ TestCaseSource ( nameof ( Languages ) ) ]
37
+ public void UpdateAssemblyInfoTaskShouldCreateFileInBuildServer ( string language )
29
38
{
30
- var task = new UpdateAssemblyInfo ( ) ;
39
+ var extension = FileHelper . GetFileExtension ( language ) ;
40
+ var task = new UpdateAssemblyInfo { Language = language } ;
31
41
32
42
using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
33
43
34
44
result . Success . ShouldBe ( true ) ;
35
45
result . Errors . ShouldBe ( 0 ) ;
36
46
result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
47
+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
37
48
38
49
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"")" ) ;
40
51
}
41
52
42
- [ Test ]
43
- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuild ( )
53
+ [ TestCaseSource ( nameof ( Languages ) ) ]
54
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuild ( string language )
44
55
{
45
56
const string taskName = nameof ( UpdateAssemblyInfo ) ;
46
57
const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
47
58
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 ) ;
49
62
50
63
result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
51
64
result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
52
65
result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
53
66
result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
54
67
result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
55
68
56
- var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , "AssemblyInfo.g.cs " ) ;
69
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , $ "AssemblyInfo.g.{ extension } ") ;
57
70
result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
58
71
59
72
var fileContent = File . ReadAllText ( generatedFilePath ) ;
60
- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.2.4.0"")] " ) ;
73
+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.2.4.0"")" ) ;
61
74
}
62
75
63
- [ Test ]
64
- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServer ( )
76
+ [ TestCaseSource ( nameof ( Languages ) ) ]
77
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServer ( string language )
65
78
{
66
79
const string taskName = nameof ( UpdateAssemblyInfo ) ;
67
80
const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
68
81
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 ) ;
70
85
71
86
result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
72
87
result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
73
88
result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
74
89
result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
75
90
result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
76
91
77
- var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , "AssemblyInfo.g.cs " ) ;
92
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , $ "AssemblyInfo.g.{ extension } ") ;
78
93
result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
79
94
80
95
var fileContent = File . ReadAllText ( generatedFilePath ) ;
81
- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.0.1.0"")] " ) ;
96
+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.0.1.0"")" ) ;
82
97
}
83
98
84
- [ Test ]
85
- public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( )
99
+ [ TestCaseSource ( nameof ( Languages ) ) ]
100
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( string language )
86
101
{
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" ) } ;
88
104
89
105
using var result = ExecuteMsBuildTask ( task ) ;
90
106
91
107
result . Success . ShouldBe ( true ) ;
92
108
result . Errors . ShouldBe ( 0 ) ;
93
109
result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
110
+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
94
111
95
112
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"")" ) ;
97
114
}
98
115
99
- [ Test ]
100
- public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer ( )
116
+ [ TestCaseSource ( nameof ( Languages ) ) ]
117
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer ( string language )
101
118
{
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" ) } ;
103
121
104
122
using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
105
123
106
124
result . Success . ShouldBe ( true ) ;
107
125
result . Errors . ShouldBe ( 0 ) ;
108
126
result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
127
+ result . Task . AssemblyInfoTempFilePath . ShouldMatch ( $@ "AssemblyInfo.*\.g\.{ extension } ") ;
109
128
110
129
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"")" ) ;
112
131
}
113
132
114
- [ Test ]
115
- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( )
133
+ [ TestCaseSource ( nameof ( Languages ) ) ]
134
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( string language )
116
135
{
117
136
const string taskName = nameof ( UpdateAssemblyInfo ) ;
118
137
const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
119
138
var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
120
139
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 ) ;
122
146
123
147
result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
124
148
result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
125
149
result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
126
150
result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
127
151
result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
128
152
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 } ") ;
130
154
result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
131
155
132
156
var fileContent = File . ReadAllText ( generatedFilePath ) ;
133
- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.2.4.0"")] " ) ;
157
+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.2.4.0"")" ) ;
134
158
}
135
159
136
- [ Test ]
137
- public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( )
160
+ [ TestCaseSource ( nameof ( Languages ) ) ]
161
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( string language )
138
162
{
139
163
const string taskName = nameof ( UpdateAssemblyInfo ) ;
140
164
const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
141
165
var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
142
166
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 ) ;
144
173
145
174
result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
146
175
result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
147
176
result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
148
177
result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
149
178
result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
150
179
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 } ") ;
152
181
result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
153
182
154
183
var fileContent = File . ReadAllText ( generatedFilePath ) ;
155
- fileContent . ShouldContain ( @"[ assembly: AssemblyVersion(""1.0.1.0"")] " ) ;
184
+ fileContent . ShouldContain ( @"assembly: AssemblyVersion(""1.0.1.0"")" ) ;
156
185
}
157
186
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)" )
159
190
{
160
191
var assemblyFileLocation = typeof ( GitVersionTaskBase ) . Assembly . Location ;
161
192
project . UsingTaskAssemblyFile ( taskName , assemblyFileLocation )
193
+ . Property ( "ManagePackageVersionsCentrally" , "false" )
162
194
. Property ( "GenerateAssemblyInfo" , "false" )
195
+ . Property ( "Language" , language )
163
196
. Target ( targetToRun , beforeTargets : "CoreCompile;GetAssemblyVersion;GenerateNuspec" )
164
197
. Task ( taskName , parameters : new Dictionary < string , string ? >
165
198
{
0 commit comments