@@ -51,35 +51,18 @@ public void CacheFileExistsOnDisk()
51
51
CommitDate: 2015-11-10
52
52
" ;
53
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 ( ) ) )
54
+ var info = RepositoryScope ( ( fixture , vv , fs ) =>
60
55
{
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 ) ;
56
+ fs . WriteAllText ( vv . FileName , versionCacheFileContent ) ;
70
57
71
58
// I would rather see that VersionAndBranchFinder was non-static and could be reinstantiated to
72
59
// clear the in-memory cache, but that's not the case, so I have to perform this ugly hack. @asbjornu
73
60
VersionAndBranchFinder . VersionCacheVersions = new ConcurrentDictionary < string , VersionVariables > ( ) ;
74
61
75
- vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
62
+ vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fs ) ;
76
63
77
64
vv . AssemblySemVer . ShouldBe ( "4.10.3.0" ) ;
78
- }
79
-
80
- var info = infoBuilder . ToString ( ) ;
81
-
82
- Console . WriteLine ( info ) ;
65
+ } ) ;
83
66
84
67
info . ShouldContain ( "Deserializing version variables from cache file" , ( ) => info ) ;
85
68
}
@@ -88,29 +71,11 @@ public void CacheFileExistsOnDisk()
88
71
[ Test ]
89
72
public void CacheFileExistsInMemory ( )
90
73
{
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 ( ) ) )
74
+ var info = RepositoryScope ( ( fixture , vv , fs ) =>
97
75
{
98
- var fileSystem = new FileSystem ( ) ;
99
- fixture . Repository . MakeACommit ( ) ;
100
- var vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
101
-
76
+ vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fs ) ;
102
77
vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
103
-
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 ) ;
78
+ } ) ;
114
79
115
80
info . ShouldContain ( "yml not found" , ( ) => info ) ;
116
81
info . ShouldNotContain ( "Deserializing version variables from cache file" , ( ) => info ) ;
@@ -119,6 +84,13 @@ public void CacheFileExistsInMemory()
119
84
120
85
[ Test ]
121
86
public void CacheFileIsMissing ( )
87
+ {
88
+ var info = RepositoryScope ( ) ;
89
+ info . ShouldContain ( "yml not found" , ( ) => info ) ;
90
+ }
91
+
92
+
93
+ static string RepositoryScope ( Action < EmptyRepositoryFixture , VersionVariables , IFileSystem > fixtureAction = null )
122
94
{
123
95
var infoBuilder = new StringBuilder ( ) ;
124
96
Action < string > infoLogger = s => { infoBuilder . AppendLine ( s ) ; } ;
@@ -132,9 +104,14 @@ public void CacheFileIsMissing()
132
104
var vv = VersionAndBranchFinder . GetVersion ( fixture . RepositoryPath , null , false , fileSystem ) ;
133
105
134
106
vv . AssemblySemVer . ShouldBe ( "0.1.0.0" ) ;
107
+ vv . FileName . ShouldNotBeNullOrEmpty ( ) ;
108
+
109
+ if ( fixtureAction != null )
110
+ {
111
+ fixtureAction ( fixture , vv , fileSystem ) ;
112
+ }
135
113
}
136
114
137
- var info = infoBuilder . ToString ( ) ;
138
- info . ShouldContain ( "yml not found" , ( ) => info ) ;
115
+ return infoBuilder . ToString ( ) ;
139
116
}
140
117
}
0 commit comments