1+ using System . IO ;
2+ using System . Linq ;
3+ using System . Reflection ;
4+ using GitVersion ;
5+ using GitVersion . Helpers ;
6+ using GitVersionCore . Tests ;
7+ using NUnit . Framework ;
8+ using Shouldly ;
9+ using YamlDotNet . Serialization ;
10+
11+ [ TestFixture ]
12+ public class ConfigProviderTests
13+ {
14+ string gitDirectory ;
15+ IFileSystem fileSystem ;
16+
17+ [ SetUp ]
18+ public void Setup ( )
19+ {
20+ fileSystem = new TestFileSystem ( ) ;
21+ gitDirectory = "c:\\ MyGitRepo\\ .git" ;
22+ }
23+
24+ [ Test ]
25+ public void CanReadDocument ( )
26+ {
27+ const string text = @"
28+ assembly-versioning-scheme: MajorMinor
29+ develop-branch-tag: alpha
30+ release-branch-tag: rc
31+ next-version: 2.0.0
32+ tag-prefix: '[vV|version-]'
33+ " ;
34+ SetupConfigFileContent ( text ) ;
35+
36+ var config = ConfigurationProvider . Provide ( gitDirectory , fileSystem ) ;
37+ config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinor ) ;
38+ config . DevelopBranchTag . ShouldBe ( "alpha" ) ;
39+ config . ReleaseBranchTag . ShouldBe ( "rc" ) ;
40+ config . NextVersion . ShouldBe ( "2.0.0" ) ;
41+ config . TagPrefix . ShouldBe ( "[vV|version-]" ) ;
42+ }
43+
44+ [ Test ]
45+ public void CanReadOldDocument ( )
46+ {
47+ const string text = @"assemblyVersioningScheme: MajorMinor" ;
48+ SetupConfigFileContent ( text ) ;
49+ var config = ConfigurationProvider . Provide ( gitDirectory , fileSystem ) ;
50+ config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinor ) ;
51+ }
52+
53+ [ Test ]
54+ public void CanReadDefaultDocument ( )
55+ {
56+ const string text = "" ;
57+ SetupConfigFileContent ( text ) ;
58+ var config = ConfigurationProvider . Provide ( gitDirectory , fileSystem ) ;
59+ config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinorPatch ) ;
60+ config . DevelopBranchTag . ShouldBe ( "unstable" ) ;
61+ config . ReleaseBranchTag . ShouldBe ( "beta" ) ;
62+ config . TagPrefix . ShouldBe ( "[vV]" ) ;
63+ config . NextVersion . ShouldBe ( null ) ;
64+ }
65+
66+ [ Test ]
67+ public void VerifyInit ( )
68+ {
69+ var config = typeof ( Config ) ;
70+ var aliases = config . GetProperties ( ) . Select ( p => ( ( YamlAliasAttribute ) p . GetCustomAttribute ( typeof ( YamlAliasAttribute ) ) ) . Alias ) ;
71+ var writer = new StringWriter ( ) ;
72+
73+ ConfigReader . WriteSample ( writer ) ;
74+ var initFile = writer . GetStringBuilder ( ) . ToString ( ) ;
75+
76+ foreach ( var alias in aliases )
77+ {
78+ initFile . ShouldContain ( alias ) ;
79+ }
80+ }
81+
82+ [ Test ]
83+ public void VerifyAliases ( )
84+ {
85+ var config = typeof ( Config ) ;
86+ var propertiesMissingAlias = config . GetProperties ( ) . Where ( p => p . GetCustomAttribute ( typeof ( YamlAliasAttribute ) ) == null ) . Select ( p => p . Name ) ;
87+
88+ propertiesMissingAlias . ShouldBeEmpty ( ) ;
89+ }
90+
91+ void SetupConfigFileContent ( string text )
92+ {
93+ fileSystem . WriteAllText ( Path . Combine ( Directory . GetParent ( gitDirectory ) . FullName , "GitVersionConfig.yaml" ) , text ) ;
94+ }
95+ }
0 commit comments