@@ -22,13 +22,14 @@ public void Should_Initialize_When_Cache_Does_Not_Exist()
2222 {
2323 const string connectionsCachePath = @"c:\UserCachePath\" ;
2424
25- var environment = SubstituteFactory . CreateEnvironment ( ) ;
26- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
27-
2825 var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
2926 var credentialManager = Substitute . For < ICredentialManager > ( ) ;
3027
31- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
28+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
29+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
30+ environment . FileSystem . Returns ( fileSystem ) ;
31+
32+ var keychain = new Keychain ( environment , credentialManager ) ;
3233 keychain . Initialize ( ) ;
3334
3435 fileSystem . Received ( 1 ) . FileExists ( @"c:\UserCachePath\connections.json" ) ;
@@ -53,19 +54,20 @@ public void Should_Initialize_When_Cache_Invalid()
5354 const string connectionsCachePath = @"c:\UserCachePath\" ;
5455 const string connectionsCacheFile = @"c:\UserCachePath\connections.json" ;
5556
56- var environment = SubstituteFactory . CreateEnvironment ( ) ;
57- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
58-
5957 var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
6058 FilesThatExist = new List < string > { connectionsCacheFile } ,
6159 FileContents = new Dictionary < string , IList < string > > {
6260 { connectionsCacheFile , new List < string > { @"invalid json" } }
6361 }
6462 } ) ;
6563
64+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
65+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
66+ environment . FileSystem . Returns ( fileSystem ) ;
67+
6668 var credentialManager = Substitute . For < ICredentialManager > ( ) ;
6769
68- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
70+ var keychain = new Keychain ( environment , credentialManager ) ;
6971 keychain . Initialize ( ) ;
7072
7173 fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -92,19 +94,20 @@ public void Should_Initialize_When_Cache_Exists()
9294
9395 var hostUri = new UriString ( "https://github.com/" ) ;
9496
95- var environment = SubstituteFactory . CreateEnvironment ( ) ;
96- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
97-
9897 var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
9998 FilesThatExist = new List < string > { connectionsCacheFile } ,
10099 FileContents = new Dictionary < string , IList < string > > {
101100 { connectionsCacheFile , new List < string > { @"[{""Host"":""https://github.com/"",""Username"":""SomeUser""}]" } }
102101 }
103102 } ) ;
104103
104+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
105+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
106+ environment . FileSystem . Returns ( fileSystem ) ;
107+
105108 var credentialManager = Substitute . For < ICredentialManager > ( ) ;
106109
107- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
110+ var keychain = new Keychain ( environment , credentialManager ) ;
108111 keychain . Initialize ( ) ;
109112
110113 fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -131,16 +134,17 @@ public void Should_Load_From_ConnectionManager()
131134
132135 var hostUri = new UriString ( "https://github.com/" ) ;
133136
134- var environment = SubstituteFactory . CreateEnvironment ( ) ;
135- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
136-
137137 var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
138138 FilesThatExist = new List < string > { connectionsCacheFile } ,
139139 FileContents = new Dictionary < string , IList < string > > {
140140 { connectionsCacheFile , new List < string > { @"[{""Host"":""https://github.com/"",""Username"":""SomeUser""}]" } }
141141 }
142142 } ) ;
143143
144+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
145+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
146+ environment . FileSystem . Returns ( fileSystem ) ;
147+
144148 const string username = "SomeUser" ;
145149 const string token = "SomeToken" ;
146150
@@ -154,7 +158,7 @@ public void Should_Load_From_ConnectionManager()
154158 return TaskEx . FromResult ( credential ) ;
155159 } ) ;
156160
157- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
161+ var keychain = new Keychain ( environment , credentialManager ) ;
158162 keychain . Initialize ( ) ;
159163
160164 fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -188,20 +192,21 @@ public void Should_Delete_From_Cache_When_Load_Returns_Null_From_ConnectionManag
188192
189193 var hostUri = new UriString ( "https://github.com/" ) ;
190194
191- var environment = SubstituteFactory . CreateEnvironment ( ) ;
192- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
193-
194195 var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
195196 FilesThatExist = new List < string > { connectionsCacheFile } ,
196197 FileContents = new Dictionary < string , IList < string > > {
197198 { connectionsCacheFile , new List < string > { @"[{""Host"":""https://github.com/"",""Username"":""SomeUser""}]" } }
198199 }
199200 } ) ;
200201
202+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
203+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
204+ environment . FileSystem . Returns ( fileSystem ) ;
205+
201206 var credentialManager = Substitute . For < ICredentialManager > ( ) ;
202207 credentialManager . Load ( hostUri ) . Returns ( info => TaskEx . FromResult < ICredential > ( null ) ) ;
203208
204- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
209+ var keychain = new Keychain ( environment , credentialManager ) ;
205210 keychain . Initialize ( ) ;
206211
207212 fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -243,17 +248,19 @@ public void Should_Connect_Set_Credentials_Token_And_Save()
243248
244249 var hostUri = new UriString ( "https://github.com/" ) ;
245250
251+ var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
252+
246253 var environment = SubstituteFactory . CreateEnvironment ( ) ;
247254 environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
255+ environment . FileSystem . Returns ( fileSystem ) ;
248256
249- var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
250257 var credentialManager = Substitute . For < ICredentialManager > ( ) ;
251258
252259 credentialManager . Delete ( Args . UriString ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
253260
254261 credentialManager . Save ( Arg . Any < ICredential > ( ) ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
255262
256- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
263+ var keychain = new Keychain ( environment , credentialManager ) ;
257264 keychain . Initialize ( ) ;
258265
259266 fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -325,17 +332,19 @@ public void Should_Connect_Set_Credentials_And_Clear()
325332
326333 var hostUri = new UriString ( "https://github.com/" ) ;
327334
335+ var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
336+
328337 var environment = SubstituteFactory . CreateEnvironment ( ) ;
329338 environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
339+ environment . FileSystem . Returns ( fileSystem ) ;
330340
331- var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
332341 var credentialManager = Substitute . For < ICredentialManager > ( ) ;
333342
334343 credentialManager . Delete ( Args . UriString ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
335344
336345 credentialManager . Save ( Arg . Any < ICredential > ( ) ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
337346
338- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
347+ var keychain = new Keychain ( environment , credentialManager ) ;
339348 keychain . Initialize ( ) ;
340349
341350 fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
0 commit comments