1
+ using System . IO ;
2
+ using GitTools . Testing ;
1
3
using GitVersion ;
2
4
using GitVersion . Logging ;
3
5
using GitVersion . Model ;
@@ -17,11 +19,7 @@ public class ArgumentParserTests : TestBase
17
19
[ SetUp ]
18
20
public void SetUp ( )
19
21
{
20
- var sp = ConfigureServices ( services =>
21
- {
22
- services . AddSingleton < IArgumentParser , ArgumentParser > ( ) ;
23
- } ) ;
24
- argumentParser = sp . GetService < IArgumentParser > ( ) ;
22
+ argumentParser = GetArgumentParser ( ) ;
25
23
}
26
24
27
25
[ Test ]
@@ -257,19 +255,50 @@ public void CreateMulitpleAssemblyInfoProtected(string command)
257
255
[ Test ]
258
256
public void UpdateAssemblyInfoWithFilename ( )
259
257
{
260
- var arguments = argumentParser . ParseArguments ( "-updateAssemblyInfo CommonAssemblyInfo.cs" ) ;
258
+ using var repo = new EmptyRepositoryFixture ( ) ;
259
+
260
+ var assemblyFile = Path . Combine ( repo . RepositoryPath , "CommonAssemblyInfo.cs" ) ;
261
+ using var file = File . Create ( assemblyFile ) ;
262
+
263
+ var arguments = argumentParser . ParseArguments ( $ "-targetpath { repo . RepositoryPath } -updateAssemblyInfo CommonAssemblyInfo.cs") ;
261
264
arguments . UpdateAssemblyInfo . ShouldBe ( true ) ;
262
- arguments . UpdateAssemblyInfoFileName . ShouldContain ( "CommonAssemblyInfo.cs" ) ;
265
+ arguments . UpdateAssemblyInfoFileName . Count . ShouldBe ( 1 ) ;
266
+ arguments . UpdateAssemblyInfoFileName . ShouldContain ( x => Path . GetFileName ( x ) . Equals ( "CommonAssemblyInfo.cs" ) ) ;
263
267
}
264
268
265
269
[ Test ]
266
270
public void UpdateAssemblyInfoWithMultipleFilenames ( )
267
271
{
268
- var arguments = argumentParser . ParseArguments ( "-updateAssemblyInfo CommonAssemblyInfo.cs VersionAssemblyInfo.cs" ) ;
272
+ using var repo = new EmptyRepositoryFixture ( ) ;
273
+
274
+ var assemblyFile1 = Path . Combine ( repo . RepositoryPath , "CommonAssemblyInfo.cs" ) ;
275
+ using var file = File . Create ( assemblyFile1 ) ;
276
+
277
+ var assemblyFile2 = Path . Combine ( repo . RepositoryPath , "VersionAssemblyInfo.cs" ) ;
278
+ using var file2 = File . Create ( assemblyFile2 ) ;
279
+
280
+ var arguments = argumentParser . ParseArguments ( $ "-targetpath { repo . RepositoryPath } -updateAssemblyInfo CommonAssemblyInfo.cs VersionAssemblyInfo.cs") ;
269
281
arguments . UpdateAssemblyInfo . ShouldBe ( true ) ;
270
282
arguments . UpdateAssemblyInfoFileName . Count . ShouldBe ( 2 ) ;
271
- arguments . UpdateAssemblyInfoFileName . ShouldContain ( "CommonAssemblyInfo.cs" ) ;
272
- arguments . UpdateAssemblyInfoFileName . ShouldContain ( "VersionAssemblyInfo.cs" ) ;
283
+ arguments . UpdateAssemblyInfoFileName . ShouldContain ( x => Path . GetFileName ( x ) . Equals ( "CommonAssemblyInfo.cs" ) ) ;
284
+ arguments . UpdateAssemblyInfoFileName . ShouldContain ( x => Path . GetFileName ( x ) . Equals ( "VersionAssemblyInfo.cs" ) ) ;
285
+ }
286
+
287
+ [ Test ]
288
+ public void UpdateAssemblyInfoWithRelativeFilename ( )
289
+ {
290
+ using var repo = new EmptyRepositoryFixture ( ) ;
291
+
292
+ var assemblyFile = Path . Combine ( repo . RepositoryPath , "CommonAssemblyInfo.cs" ) ;
293
+ using var file = File . Create ( assemblyFile ) ;
294
+
295
+ var targetPath = Path . Combine ( repo . RepositoryPath , "subdir1" , "subdir2" ) ;
296
+ Directory . CreateDirectory ( targetPath ) ;
297
+
298
+ var arguments = argumentParser . ParseArguments ( $ "-targetpath { targetPath } -updateAssemblyInfo ..\\ ..\\ CommonAssemblyInfo.cs") ;
299
+ arguments . UpdateAssemblyInfo . ShouldBe ( true ) ;
300
+ arguments . UpdateAssemblyInfoFileName . Count . ShouldBe ( 1 ) ;
301
+ arguments . UpdateAssemblyInfoFileName . ShouldContain ( x => Path . GetFileName ( x ) . Equals ( "CommonAssemblyInfo.cs" ) ) ;
273
302
}
274
303
275
304
[ Test ]
@@ -301,14 +330,6 @@ public void OverrideconfigWithInvalidOption(string options)
301
330
exception . Message . ShouldContain ( "Could not parse /overrideconfig option" ) ;
302
331
}
303
332
304
- [ Test ]
305
- public void UpdateAssemblyInfoWithRelativeFilename ( )
306
- {
307
- var arguments = argumentParser . ParseArguments ( "-updateAssemblyInfo ..\\ ..\\ CommonAssemblyInfo.cs" ) ;
308
- arguments . UpdateAssemblyInfo . ShouldBe ( true ) ;
309
- arguments . UpdateAssemblyInfoFileName . ShouldContain ( "..\\ ..\\ CommonAssemblyInfo.cs" ) ;
310
- }
311
-
312
333
[ Test ]
313
334
public void EnsureAssemblyInfoTrueWhenFound ( )
314
335
{
@@ -466,5 +487,22 @@ public void CheckVerbosityParsing(string command, bool shouldThrow, Verbosity ex
466
487
arguments . Verbosity . ShouldBe ( expectedVerbosity ) ;
467
488
}
468
489
}
490
+
491
+ private static IArgumentParser GetArgumentParser ( IGlobbingResolver globbingResolver = null )
492
+ {
493
+ var sp = ConfigureServices ( services =>
494
+ {
495
+ services . AddSingleton < IArgumentParser , ArgumentParser > ( ) ;
496
+ if ( globbingResolver != null )
497
+ {
498
+ services . AddSingleton ( globbingResolver ) ;
499
+ }
500
+ else
501
+ {
502
+ services . AddSingleton < IGlobbingResolver , GlobbingResolver > ( ) ;
503
+ }
504
+ } ) ;
505
+ return sp . GetService < IArgumentParser > ( ) ;
506
+ }
469
507
}
470
508
}
0 commit comments