9
9
10
10
#endregion
11
11
12
+ using System ;
13
+ using System . Collections . Concurrent ;
14
+ using System . Text ;
15
+
16
+ using GitVersion ;
17
+ using GitVersion . Helpers ;
18
+
12
19
using NUnit . Framework ;
13
20
14
21
using Shouldly ;
17
24
public class VersionAndBranchFinderTests
18
25
{
19
26
[ Test ]
20
- public void ExistingCacheFile ( )
27
+ public void CacheFileExistsOnDisk ( )
21
28
{
22
- var fileSystem = new TestFileSystem ( ) ;
23
- fileSystem . WriteAllText ( "existing\\ gitversion_cache\\ C7B23F8A47ECE0E14CBE2E22C04269CC5A88E275.yml" , @"
29
+ const string versionCacheFileContent = @"
24
30
Major: 4
25
31
Minor: 10
26
32
Patch: 3
@@ -43,21 +49,92 @@ public void ExistingCacheFile()
43
49
CommitsSinceVersionSource: 19
44
50
CommitsSinceVersionSourcePadded: 0019
45
51
CommitDate: 2015-11-10
46
- " ) ;
52
+ " ;
53
+
54
+ var infoBuilder = new StringBuilder ( ) ;
55
+ Action < string > infoLogger = s => { infoBuilder . AppendLine ( s ) ; } ;
56
+
57
+ Logger . SetLoggers ( infoLogger , null , null ) ;
58
+
59
+ using ( var fixture = new EmptyRepositoryFixture ( new Config ( ) ) )
60
+ {
61
+ var fileSystem = new FileSystem ( ) ;
62
+ fixture . Repository . MakeACommit ( ) ;
63
+ var vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
64
+
65
+ vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
66
+
67
+ vv . FileName . ShouldNotBeNullOrEmpty ( ) ;
68
+
69
+ fileSystem . WriteAllText ( vv . FileName , versionCacheFileContent ) ;
70
+
71
+ // I would rather see that VersionAndBranchFinder was non-static and could be reinstantiated to
72
+ // clear the in-memory cache, but that's not the case, so I have to perform this ugly hack. @asbjornu
73
+ VersionAndBranchFinder . VersionCacheVersions = new ConcurrentDictionary < string , VersionVariables > ( ) ;
74
+
75
+ vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
76
+
77
+ vv . AssemblySemVer . ShouldBe ( "4.10.3.0" ) ;
78
+ }
79
+
80
+ var info = infoBuilder . ToString ( ) ;
81
+
82
+ Console . WriteLine ( info ) ;
83
+
84
+ info . ShouldContain ( "Deserializing version variables from cache file" , ( ) => info ) ;
85
+ }
86
+
87
+
88
+ [ Test ]
89
+ public void CacheFileExistsInMemory ( )
90
+ {
91
+ var infoBuilder = new StringBuilder ( ) ;
92
+ Action < string > infoLogger = s => { infoBuilder . AppendLine ( s ) ; } ;
93
+
94
+ Logger . SetLoggers ( infoLogger , null , null ) ;
95
+
96
+ using ( var fixture = new EmptyRepositoryFixture ( new Config ( ) ) )
97
+ {
98
+ var fileSystem = new FileSystem ( ) ;
99
+ fixture . Repository . MakeACommit ( ) ;
100
+ var vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
47
101
48
- var vv = VersionAndBranchFinder . GetVersion ( "existing" , null , false , fileSystem ) ;
102
+ vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
49
103
50
- vv . AssemblySemVer . ShouldBe ( "4.10.3.0" ) ;
104
+ vv . FileName . ShouldNotBeNullOrEmpty ( ) ;
105
+
106
+ vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
107
+
108
+ vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
109
+ }
110
+
111
+ var info = infoBuilder . ToString ( ) ;
112
+
113
+ Console . WriteLine ( info ) ;
114
+
115
+ info . ShouldContain ( "yml not found" , ( ) => info ) ;
116
+ info . ShouldNotContain ( "Deserializing version variables from cache file" , ( ) => info ) ;
51
117
}
52
118
53
119
54
120
[ Test ]
55
- public void MissingCacheFile ( )
121
+ public void CacheFileIsMissing ( )
56
122
{
57
- var fileSystem = new TestFileSystem ( ) ;
123
+ var infoBuilder = new StringBuilder ( ) ;
124
+ Action < string > infoLogger = s => { infoBuilder . AppendLine ( s ) ; } ;
125
+
126
+ Logger . SetLoggers ( infoLogger , null , null ) ;
127
+
128
+ using ( var fixture = new EmptyRepositoryFixture ( new Config ( ) ) )
129
+ {
130
+ fixture . Repository . MakeACommit ( ) ;
131
+ var fileSystem = new FileSystem ( ) ;
132
+ var vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
58
133
59
- var vv = VersionAndBranchFinder . GetVersion ( "missing" , null , false , fileSystem ) ;
134
+ vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
135
+ }
60
136
61
- vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
137
+ var info = infoBuilder . ToString ( ) ;
138
+ info . ShouldContain ( "yml not found" , ( ) => info ) ;
62
139
}
63
140
}
0 commit comments