11using System ;
22using System . IO ;
33using GitVersion ;
4- using GitVersionTask . Tests . Mocks ;
5- using Microsoft . Build . Framework ;
64using NUnit . Framework ;
75
86[ TestFixture ]
@@ -14,207 +12,207 @@ public class InvalidFileCheckerTests : TestBase
1412 [ SetUp ]
1513 public void CreateTemporaryProject ( )
1614 {
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" ) ;
1917
20- Directory . CreateDirectory ( projectDirectory ) ;
18+ Directory . CreateDirectory ( projectDirectory ) ;
2119
22- File . Create ( projectFile ) . Close ( ) ;
20+ File . Create ( projectFile ) . Close ( ) ;
2321 }
2422
2523 [ TearDown ]
2624 public void Cleanup ( )
2725 {
28- Directory . Delete ( projectDirectory , true ) ;
26+ Directory . Delete ( projectDirectory , true ) ;
2927 }
3028
3129 [ Test ]
3230 public void VerifyIgnoreNonAssemblyInfoFile ( )
3331 {
34- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "SomeOtherFile.cs" ) ) )
32+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "SomeOtherFile.cs" ) ) )
3533 {
36- writer . Write ( @"
34+ writer . Write ( @"
3735using System;
3836using System.Reflection;
3937
4038[assembly: AssemblyVersion(""1.0.0.0"")]
41- " ) ;
39+ " ) ;
4240 }
4341
44- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } } , projectFile ) ;
42+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "SomeOtherFile.cs" } , projectFile ) ;
4543 }
4644
4745 [ 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 )
4947 {
50- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
48+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
5149 {
52- writer . Write ( @"
50+ writer . Write ( @"
5351using System;
5452using System.Reflection;
5553
5654[assembly:{0}(""1.0.0.0"")]
57- " , attribute ) ;
55+ " , attribute ) ;
5856 }
5957
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" ) ) ;
6260 }
6361
6462 [ 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 )
6664 {
67- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
65+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
6866 {
69- writer . Write ( @"
67+ writer . Write ( @"
7068using System;
7169using System.Reflection;
7270
7371[ assembly :
7472{0} ( ""1.0.0.0"")]
75- " , attribute ) ;
73+ " , attribute ) ;
7674 }
7775
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" ) ) ;
8078 }
8179
8280 [ Test ]
83- public void VerifyCommentWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
81+ public void VerifyCommentWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
8482 {
85- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
83+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
8684 {
87- writer . Write ( @"
85+ writer . Write ( @"
8886using System;
8987using System.Reflection;
9088
9189//[assembly: {0}(""1.0.0.0"")]
92- " , attribute ) ;
90+ " , attribute ) ;
9391 }
9492
95- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) ;
93+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) ;
9694 }
9795
9896 [ Test ]
99- public void VerifyStringWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
97+ public void VerifyStringWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
10098 {
101- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
99+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
102100 {
103- writer . Write ( @"
101+ writer . Write ( @"
104102using System;
105103using System.Reflection;
106104
107105public class Temp
108106{{
109107 static const string Foo = ""[assembly: {0}(""""1.0.0.0"""")]"";
110108}}
111- " , attribute ) ;
109+ " , attribute ) ;
112110 }
113111
114- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) ;
112+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) ;
115113 }
116114
117115 [ Test ]
118- public void VerifyIdentifierWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
116+ public void VerifyIdentifierWorksCSharp ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
119117 {
120- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
118+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.cs" ) ) )
121119 {
122- writer . Write ( @"
120+ writer . Write ( @"
123121using System;
124122using System.Reflection;
125123
126124public class {0}
127125{{
128126}}
129- " , attribute ) ;
127+ " , attribute ) ;
130128 }
131129
132- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } } , projectFile ) ;
130+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.cs" } , projectFile ) ;
133131 }
134132
135133 [ 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 )
137135 {
138- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
136+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
139137 {
140- writer . Write ( @"
138+ writer . Write ( @"
141139Imports System
142140Imports System.Reflection
143141
144142<Assembly:{0}(""1.0.0.0"")>
145- " , attribute ) ;
143+ " , attribute ) ;
146144 }
147145
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" ) ) ;
150148 }
151149
152150 [ 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 )
154152 {
155- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
153+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
156154 {
157- writer . Write ( @"
155+ writer . Write ( @"
158156Imports System
159157Imports System.Reflection
160158
161159< Assembly :
162160{0} ( ""1.0.0.0"")>
163- " , attribute ) ;
161+ " , attribute ) ;
164162 }
165163
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" ) ) ;
168166 }
169167
170168 [ Test ]
171- public void VerifyCommentWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
169+ public void VerifyCommentWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
172170 {
173- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
171+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
174172 {
175- writer . Write ( @"
173+ writer . Write ( @"
176174Imports System
177175Imports System.Reflection
178176
179177'<Assembly: {0}(""1.0.0.0"")>
180- " , attribute ) ;
178+ " , attribute ) ;
181179 }
182180
183- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) ;
181+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) ;
184182 }
185183
186184 [ Test ]
187- public void VerifyStringWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
185+ public void VerifyStringWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
188186 {
189- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
187+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
190188 {
191- writer . Write ( @"
189+ writer . Write ( @"
192190Imports System
193191Imports System.Reflection
194192
195193Public Class Temp
196194 static const string Foo = ""<Assembly: {0}(""""1.0.0.0"""")>"";
197195End Class
198- " , attribute ) ;
196+ " , attribute ) ;
199197 }
200198
201- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) ;
199+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) ;
202200 }
203201
204202 [ Test ]
205- public void VerifyIdentifierWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
203+ public void VerifyIdentifierWorksVisualBasic ( [ Values ( "AssemblyVersion" , "AssemblyFileVersion" , "AssemblyInformationalVersion" ) ] string attribute )
206204 {
207- using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
205+ using ( var writer = File . CreateText ( Path . Combine ( projectDirectory , "AssemblyInfo.vb" ) ) )
208206 {
209- writer . Write ( @"
207+ writer . Write ( @"
210208Imports System
211209Imports System.Reflection
212210
213211Public Class {0}
214212End Class
215- " , attribute ) ;
213+ " , attribute ) ;
216214 }
217215
218- InvalidFileChecker . CheckForInvalidFiles ( new ITaskItem [ ] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } } , projectFile ) ;
216+ InvalidFileChecker . CheckForInvalidFiles ( new [ ] { "AssemblyInfo.vb" } , projectFile ) ;
219217 }
220218}
0 commit comments