@@ -22,7 +22,7 @@ public async Task LoginTokenIsSavedToCache()
2222 . Returns ( new ApplicationAuthorization ( "123abc" ) ) ;
2323
2424 var keychain = Substitute . For < IKeychain > ( ) ;
25- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
25+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
2626
2727 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
2828 await target . Login ( host , client , "foo" , "bar" ) ;
@@ -40,7 +40,7 @@ public async Task LoggedInUserIsReturned()
4040 client . User . Current ( ) . Returns ( user ) ;
4141
4242 var keychain = Substitute . For < IKeychain > ( ) ;
43- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
43+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
4444
4545 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
4646 var result = await target . Login ( host , client , "foo" , "bar" ) ;
@@ -63,7 +63,7 @@ public async Task DeletesExistingAuthenticationIfNullTokenReturned()
6363 client . User . Current ( ) . Returns ( user ) ;
6464
6565 var keychain = Substitute . For < IKeychain > ( ) ;
66- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
66+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
6767
6868 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
6969 var result = await target . Login ( host , client , "foo" , "bar" ) ;
@@ -85,8 +85,8 @@ public async Task TwoFactorExceptionIsPassedToHandler()
8585 . Returns ( new ApplicationAuthorization ( "123abc" ) ) ;
8686
8787 var keychain = Substitute . For < IKeychain > ( ) ;
88- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
89- tfa . HandleTwoFactorException ( exception ) . Returns ( new TwoFactorChallengeResult ( "123456" ) ) ;
88+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
89+ tfa . Value . HandleTwoFactorException ( exception ) . Returns ( new TwoFactorChallengeResult ( "123456" ) ) ;
9090
9191 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
9292 await target . Login ( host , client , "foo" , "bar" ) ;
@@ -112,8 +112,8 @@ public async Task Failed2FACodeResultsInRetry()
112112 . Returns ( new ApplicationAuthorization ( "123abc" ) ) ;
113113
114114 var keychain = Substitute . For < IKeychain > ( ) ;
115- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
116- tfa . HandleTwoFactorException ( exception ) . Returns (
115+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
116+ tfa . Value . HandleTwoFactorException ( exception ) . Returns (
117117 new TwoFactorChallengeResult ( "111111" ) ,
118118 new TwoFactorChallengeResult ( "123456" ) ) ;
119119
@@ -147,8 +147,8 @@ public async Task HandlerNotifiedOfExceptionIn2FAChallengeResponse()
147147 . Returns < ApplicationAuthorization > ( _ => { throw loginAttemptsException ; } ) ;
148148
149149 var keychain = Substitute . For < IKeychain > ( ) ;
150- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
151- tfa . HandleTwoFactorException ( twoFaException ) . Returns (
150+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
151+ tfa . Value . HandleTwoFactorException ( twoFaException ) . Returns (
152152 new TwoFactorChallengeResult ( "111111" ) ,
153153 new TwoFactorChallengeResult ( "123456" ) ) ;
154154
@@ -160,7 +160,7 @@ await client.Authorization.Received(1).GetOrCreateApplicationAuthentication(
160160 "secret" ,
161161 Arg . Any < NewAuthorization > ( ) ,
162162 "111111" ) ;
163- tfa . Received ( 1 ) . ChallengeFailed ( loginAttemptsException ) ;
163+ tfa . Value . Received ( 1 ) . ChallengeFailed ( loginAttemptsException ) ;
164164 }
165165
166166 [ Fact ]
@@ -177,8 +177,8 @@ public async Task RequestResendCodeResultsInRetryingLogin()
177177 client . User . Current ( ) . Returns ( user ) ;
178178
179179 var keychain = Substitute . For < IKeychain > ( ) ;
180- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
181- tfa . HandleTwoFactorException ( exception ) . Returns (
180+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
181+ tfa . Value . HandleTwoFactorException ( exception ) . Returns (
182182 TwoFactorChallengeResult . RequestResendCode ,
183183 new TwoFactorChallengeResult ( "123456" ) ) ;
184184
@@ -202,7 +202,7 @@ public async Task UsesUsernameAndPasswordInsteadOfAuthorizationTokenWhenEnterpri
202202 client . User . Current ( ) . Returns ( user ) ;
203203
204204 var keychain = Substitute . For < IKeychain > ( ) ;
205- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
205+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
206206
207207 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
208208 await target . Login ( enterprise , client , "foo" , "bar" ) ;
@@ -220,7 +220,7 @@ public async Task ErasesLoginWhenUnauthorized()
220220 . Returns < ApplicationAuthorization > ( _ => { throw new AuthorizationException ( ) ; } ) ;
221221
222222 var keychain = Substitute . For < IKeychain > ( ) ;
223- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
223+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
224224
225225 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
226226 await Assert . ThrowsAsync < AuthorizationException > ( async ( ) => await target . Login ( enterprise , client , "foo" , "bar" ) ) ;
@@ -238,7 +238,7 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrown()
238238 . Returns < ApplicationAuthorization > ( _ => { throw new InvalidOperationException ( ) ; } ) ;
239239
240240 var keychain = Substitute . For < IKeychain > ( ) ;
241- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
241+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
242242
243243 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
244244 await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) => await target . Login ( host , client , "foo" , "bar" ) ) ;
@@ -260,8 +260,8 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrownIn2FA()
260260 client . User . Current ( ) . Returns ( user ) ;
261261
262262 var keychain = Substitute . For < IKeychain > ( ) ;
263- var tfa = Substitute . For < ITwoFactorChallengeHandler > ( ) ;
264- tfa . HandleTwoFactorException ( exception ) . Returns ( new TwoFactorChallengeResult ( "123456" ) ) ;
263+ var tfa = new Lazy < ITwoFactorChallengeHandler > ( ( ) => Substitute . For < ITwoFactorChallengeHandler > ( ) ) ;
264+ tfa . Value . HandleTwoFactorException ( exception ) . Returns ( new TwoFactorChallengeResult ( "123456" ) ) ;
265265
266266 var target = new LoginManager ( keychain , tfa , "id" , "secret" ) ;
267267 await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) => await target . Login ( host , client , "foo" , "bar" ) ) ;
0 commit comments