1
1
using System ;
2
2
using System . IO ;
3
3
using GitVersion ;
4
- using GitVersionTask . Tests . Mocks ;
5
- using Microsoft . Build . Framework ;
6
4
using NUnit . Framework ;
7
5
8
6
[ TestFixture ]
@@ -14,207 +12,207 @@ public class InvalidFileCheckerTests : TestBase
14
12
[ SetUp ]
15
13
public void CreateTemporaryProject ( )
16
14
{
17
- projectDirectory = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
18
- projectFile = Path . Combine ( projectDirectory , "Fake.csproj" ) ;
15
+ projectDirectory = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
16
+ projectFile = Path . Combine ( projectDirectory , "Fake.csproj" ) ;
19
17
20
- Directory . CreateDirectory ( projectDirectory ) ;
18
+ Directory . CreateDirectory ( projectDirectory ) ;
21
19
22
- File . Create ( projectFile ) . Close ( ) ;
20
+ File . Create ( projectFile ) . Close ( ) ;
23
21
}
24
22
25
23
[ TearDown ]
26
24
public void Cleanup ( )
27
25
{
28
- Directory . Delete ( projectDirectory , true ) ;
26
+ Directory . Delete ( projectDirectory , true ) ;
29
27
}
30
28
31
29
[ Test ]
32
30
public void VerifyIgnoreNonAssemblyInfoFile ( )
33
31
{
34
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "SomeOtherFile.cs" ) ) )
32
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "SomeOtherFile.cs" ) ) )
35
33
{
36
- writer . Write ( @"
34
+ writer . Write ( @"
37
35
using System;
38
36
using System.Reflection;
39
37
40
38
[assembly: AssemblyVersion(""1.0.0.0"")]
41
- " ) ;
39
+ " ) ;
42
40
}
43
41
44
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } } , projectFile ) ;
42
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "SomeOtherFile.cs" } , projectFile ) ;
45
43
}
46
44
47
45
[ Test ]
48
- public void VerifyAttributeFoundCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System.Reflection.AssemblyVersion" ) ] string attribute )
46
+ public void VerifyAttributeFoundCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System.Reflection.AssemblyVersion" ) ] string attribute )
49
47
{
50
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
48
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
51
49
{
52
- writer . Write ( @"
50
+ writer . Write ( @"
53
51
using System;
54
52
using System.Reflection;
55
53
56
54
[assembly:{0}(""1.0.0.0"")]
57
- " , attribute ) ;
55
+ " , attribute ) ;
58
56
}
59
57
60
- var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) , attribute ) ;
61
- Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs" ) ) ;
58
+ var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) , attribute ) ;
59
+ Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs" ) ) ;
62
60
}
63
61
64
62
[ Test ]
65
- public void VerifyUnformattedAttributeFoundCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System . Reflection . AssemblyVersion" ) ] string attribute )
63
+ public void VerifyUnformattedAttributeFoundCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System . Reflection . AssemblyVersion" ) ] string attribute )
66
64
{
67
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
65
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
68
66
{
69
- writer . Write ( @"
67
+ writer . Write ( @"
70
68
using System;
71
69
using System.Reflection;
72
70
73
71
[ assembly :
74
72
{0} ( ""1.0.0.0"")]
75
- " , attribute ) ;
73
+ " , attribute ) ;
76
74
}
77
75
78
- var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) , attribute ) ;
79
- Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs" ) ) ;
76
+ var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) , attribute ) ;
77
+ Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs" ) ) ;
80
78
}
81
79
82
80
[ Test ]
83
- public void VerifyCommentWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
81
+ public void VerifyCommentWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
84
82
{
85
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
83
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
86
84
{
87
- writer . Write ( @"
85
+ writer . Write ( @"
88
86
using System;
89
87
using System.Reflection;
90
88
91
89
//[assembly: {0}(""1.0.0.0"")]
92
- " , attribute ) ;
90
+ " , attribute ) ;
93
91
}
94
92
95
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) ;
93
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) ;
96
94
}
97
95
98
96
[ Test ]
99
- public void VerifyStringWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
97
+ public void VerifyStringWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
100
98
{
101
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
99
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
102
100
{
103
- writer . Write ( @"
101
+ writer . Write ( @"
104
102
using System;
105
103
using System.Reflection;
106
104
107
105
public class Temp
108
106
{{
109
107
static const string Foo = ""[assembly: {0}(""""1.0.0.0"""")]"";
110
108
}}
111
- " , attribute ) ;
109
+ " , attribute ) ;
112
110
}
113
111
114
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) ;
112
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) ;
115
113
}
116
114
117
115
[ Test ]
118
- public void VerifyIdentifierWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
116
+ public void VerifyIdentifierWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
119
117
{
120
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
118
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
121
119
{
122
- writer . Write ( @"
120
+ writer . Write ( @"
123
121
using System;
124
122
using System.Reflection;
125
123
126
124
public class {0}
127
125
{{
128
126
}}
129
- " , attribute ) ;
127
+ " , attribute ) ;
130
128
}
131
129
132
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) ;
130
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) ;
133
131
}
134
132
135
133
[ Test ]
136
- public void VerifyAttributeFoundVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System.Reflection.AssemblyVersion" ) ] string attribute )
134
+ public void VerifyAttributeFoundVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System.Reflection.AssemblyVersion" ) ] string attribute )
137
135
{
138
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
136
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
139
137
{
140
- writer . Write ( @"
138
+ writer . Write ( @"
141
139
Imports System
142
140
Imports System.Reflection
143
141
144
142
<Assembly:{0}(""1.0.0.0"")>
145
- " , attribute ) ;
143
+ " , attribute ) ;
146
144
}
147
145
148
- var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) , attribute ) ;
149
- Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb" ) ) ;
146
+ var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) , attribute ) ;
147
+ Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb" ) ) ;
150
148
}
151
149
152
150
[ Test ]
153
- public void VerifyUnformattedAttributeFoundVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System . Reflection . AssemblyVersion" ) ] string attribute )
151
+ public void VerifyUnformattedAttributeFoundVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" , "System . Reflection . AssemblyVersion" ) ] string attribute )
154
152
{
155
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
153
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
156
154
{
157
- writer . Write ( @"
155
+ writer . Write ( @"
158
156
Imports System
159
157
Imports System.Reflection
160
158
161
159
< Assembly :
162
160
{0} ( ""1.0.0.0"")>
163
- " , attribute ) ;
161
+ " , attribute ) ;
164
162
}
165
163
166
- var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) , attribute ) ;
167
- Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb" ) ) ;
164
+ var ex = Assert . Throws < WarningException > ( ( ) => InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) , attribute ) ;
165
+ Assert . That ( ex . Message , Is . EqualTo ( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb" ) ) ;
168
166
}
169
167
170
168
[ Test ]
171
- public void VerifyCommentWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
169
+ public void VerifyCommentWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
172
170
{
173
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
171
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
174
172
{
175
- writer . Write ( @"
173
+ writer . Write ( @"
176
174
Imports System
177
175
Imports System.Reflection
178
176
179
177
'<Assembly: {0}(""1.0.0.0"")>
180
- " , attribute ) ;
178
+ " , attribute ) ;
181
179
}
182
180
183
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) ;
181
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) ;
184
182
}
185
183
186
184
[ Test ]
187
- public void VerifyStringWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
185
+ public void VerifyStringWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
188
186
{
189
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
187
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
190
188
{
191
- writer . Write ( @"
189
+ writer . Write ( @"
192
190
Imports System
193
191
Imports System.Reflection
194
192
195
193
Public Class Temp
196
194
static const string Foo = ""<Assembly: {0}(""""1.0.0.0"""")>"";
197
195
End Class
198
- " , attribute ) ;
196
+ " , attribute ) ;
199
197
}
200
198
201
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) ;
199
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) ;
202
200
}
203
201
204
202
[ Test ]
205
- public void VerifyIdentifierWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
203
+ public void VerifyIdentifierWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
206
204
{
207
- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
205
+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
208
206
{
209
- writer . Write ( @"
207
+ writer . Write ( @"
210
208
Imports System
211
209
Imports System.Reflection
212
210
213
211
Public Class {0}
214
212
End Class
215
- " , attribute ) ;
213
+ " , attribute ) ;
216
214
}
217
215
218
- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) ;
216
+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) ;
219
217
}
220
218
}
0 commit comments