@@ -22,13 +22,14 @@ public void Should_Initialize_When_Cache_Does_Not_Exist()
22
22
{
23
23
const string connectionsCachePath = @"c:\UserCachePath\" ;
24
24
25
- var environment = SubstituteFactory . CreateEnvironment ( ) ;
26
- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
27
-
28
25
var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
29
26
var credentialManager = Substitute . For < ICredentialManager > ( ) ;
30
27
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 ) ;
32
33
keychain . Initialize ( ) ;
33
34
34
35
fileSystem . Received ( 1 ) . FileExists ( @"c:\UserCachePath\connections.json" ) ;
@@ -53,19 +54,20 @@ public void Should_Initialize_When_Cache_Invalid()
53
54
const string connectionsCachePath = @"c:\UserCachePath\" ;
54
55
const string connectionsCacheFile = @"c:\UserCachePath\connections.json" ;
55
56
56
- var environment = SubstituteFactory . CreateEnvironment ( ) ;
57
- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
58
-
59
57
var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
60
58
FilesThatExist = new List < string > { connectionsCacheFile } ,
61
59
FileContents = new Dictionary < string , IList < string > > {
62
60
{ connectionsCacheFile , new List < string > { @"invalid json" } }
63
61
}
64
62
} ) ;
65
63
64
+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
65
+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
66
+ environment . FileSystem . Returns ( fileSystem ) ;
67
+
66
68
var credentialManager = Substitute . For < ICredentialManager > ( ) ;
67
69
68
- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
70
+ var keychain = new Keychain ( environment , credentialManager ) ;
69
71
keychain . Initialize ( ) ;
70
72
71
73
fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -92,19 +94,20 @@ public void Should_Initialize_When_Cache_Exists()
92
94
93
95
var hostUri = new UriString ( "https://github.com/" ) ;
94
96
95
- var environment = SubstituteFactory . CreateEnvironment ( ) ;
96
- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
97
-
98
97
var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
99
98
FilesThatExist = new List < string > { connectionsCacheFile } ,
100
99
FileContents = new Dictionary < string , IList < string > > {
101
100
{ connectionsCacheFile , new List < string > { @"[{""Host"":""https://github.com/"",""Username"":""SomeUser""}]" } }
102
101
}
103
102
} ) ;
104
103
104
+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
105
+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
106
+ environment . FileSystem . Returns ( fileSystem ) ;
107
+
105
108
var credentialManager = Substitute . For < ICredentialManager > ( ) ;
106
109
107
- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
110
+ var keychain = new Keychain ( environment , credentialManager ) ;
108
111
keychain . Initialize ( ) ;
109
112
110
113
fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -131,16 +134,17 @@ public void Should_Load_From_ConnectionManager()
131
134
132
135
var hostUri = new UriString ( "https://github.com/" ) ;
133
136
134
- var environment = SubstituteFactory . CreateEnvironment ( ) ;
135
- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
136
-
137
137
var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
138
138
FilesThatExist = new List < string > { connectionsCacheFile } ,
139
139
FileContents = new Dictionary < string , IList < string > > {
140
140
{ connectionsCacheFile , new List < string > { @"[{""Host"":""https://github.com/"",""Username"":""SomeUser""}]" } }
141
141
}
142
142
} ) ;
143
143
144
+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
145
+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
146
+ environment . FileSystem . Returns ( fileSystem ) ;
147
+
144
148
const string username = "SomeUser" ;
145
149
const string token = "SomeToken" ;
146
150
@@ -154,7 +158,7 @@ public void Should_Load_From_ConnectionManager()
154
158
return TaskEx . FromResult ( credential ) ;
155
159
} ) ;
156
160
157
- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
161
+ var keychain = new Keychain ( environment , credentialManager ) ;
158
162
keychain . Initialize ( ) ;
159
163
160
164
fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -188,20 +192,21 @@ public void Should_Delete_From_Cache_When_Load_Returns_Null_From_ConnectionManag
188
192
189
193
var hostUri = new UriString ( "https://github.com/" ) ;
190
194
191
- var environment = SubstituteFactory . CreateEnvironment ( ) ;
192
- environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
193
-
194
195
var fileSystem = SubstituteFactory . CreateFileSystem ( new CreateFileSystemOptions {
195
196
FilesThatExist = new List < string > { connectionsCacheFile } ,
196
197
FileContents = new Dictionary < string , IList < string > > {
197
198
{ connectionsCacheFile , new List < string > { @"[{""Host"":""https://github.com/"",""Username"":""SomeUser""}]" } }
198
199
}
199
200
} ) ;
200
201
202
+ var environment = SubstituteFactory . CreateEnvironment ( ) ;
203
+ environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
204
+ environment . FileSystem . Returns ( fileSystem ) ;
205
+
201
206
var credentialManager = Substitute . For < ICredentialManager > ( ) ;
202
207
credentialManager . Load ( hostUri ) . Returns ( info => TaskEx . FromResult < ICredential > ( null ) ) ;
203
208
204
- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
209
+ var keychain = new Keychain ( environment , credentialManager ) ;
205
210
keychain . Initialize ( ) ;
206
211
207
212
fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -243,17 +248,19 @@ public void Should_Connect_Set_Credentials_Token_And_Save()
243
248
244
249
var hostUri = new UriString ( "https://github.com/" ) ;
245
250
251
+ var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
252
+
246
253
var environment = SubstituteFactory . CreateEnvironment ( ) ;
247
254
environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
255
+ environment . FileSystem . Returns ( fileSystem ) ;
248
256
249
- var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
250
257
var credentialManager = Substitute . For < ICredentialManager > ( ) ;
251
258
252
259
credentialManager . Delete ( Args . UriString ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
253
260
254
261
credentialManager . Save ( Arg . Any < ICredential > ( ) ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
255
262
256
- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
263
+ var keychain = new Keychain ( environment , credentialManager ) ;
257
264
keychain . Initialize ( ) ;
258
265
259
266
fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
@@ -325,17 +332,19 @@ public void Should_Connect_Set_Credentials_And_Clear()
325
332
326
333
var hostUri = new UriString ( "https://github.com/" ) ;
327
334
335
+ var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
336
+
328
337
var environment = SubstituteFactory . CreateEnvironment ( ) ;
329
338
environment . UserCachePath . Returns ( info => connectionsCachePath . ToNPath ( ) ) ;
339
+ environment . FileSystem . Returns ( fileSystem ) ;
330
340
331
- var fileSystem = SubstituteFactory . CreateFileSystem ( ) ;
332
341
var credentialManager = Substitute . For < ICredentialManager > ( ) ;
333
342
334
343
credentialManager . Delete ( Args . UriString ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
335
344
336
345
credentialManager . Save ( Arg . Any < ICredential > ( ) ) . Returns ( info => TaskEx . FromResult ( 0 ) ) ;
337
346
338
- var keychain = new Keychain ( environment , fileSystem , credentialManager ) ;
347
+ var keychain = new Keychain ( environment , credentialManager ) ;
339
348
keychain . Initialize ( ) ;
340
349
341
350
fileSystem . Received ( 1 ) . FileExists ( connectionsCacheFile ) ;
0 commit comments