44using NUnit . Framework ;
55using PatchKit . Api ;
66using PatchKit . Api . Models . Main ;
7+ using PatchKit . Unity . Patcher . AppData . Local ;
78using PatchKit . Unity . Patcher . AppData . Remote ;
89using PatchKit . Unity . Patcher . AppUpdater . Commands ;
910using PatchKit . Unity . Patcher . Cancellation ;
@@ -30,6 +31,15 @@ public void Execute_CachesKeyAndKeySecret()
3031 const string key = "this-key-should-be-cached" ;
3132 const string keySecret = "this-key-secret-should-be-cached" ;
3233
34+ var remoteMetaData = Substitute . For < IRemoteMetaData > ( ) ;
35+ remoteMetaData . GetAppInfo ( ) . Returns ( new App ( )
36+ {
37+ UseKeys = true
38+ } ) ;
39+ remoteMetaData . GetKeySecret ( key , Arg . Any < string > ( ) ) . Returns ( keySecret ) ;
40+
41+ var localMetaData = Substitute . For < ILocalMetaData > ( ) ;
42+
3343 for ( int i = 0 ; i < 2 ; i ++ )
3444 {
3545 var licenseDialog = Substitute . For < ILicenseDialog > ( ) ;
@@ -39,28 +49,22 @@ public void Execute_CachesKeyAndKeySecret()
3949 Type = LicenseDialogResultType . Confirmed
4050 } ) ;
4151
42- var remoteMetaData = Substitute . For < IRemoteMetaData > ( ) ;
43- remoteMetaData . GetAppInfo ( ) . Returns ( new App ( )
44- {
45- UseKeys = true
46- } ) ;
47- remoteMetaData . GetKeySecret ( key , Arg . Any < string > ( ) ) . Returns ( keySecret ) ;
48-
49- var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , _cache , _logger ) ;
52+ var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , localMetaData , _cache , _logger ) ;
5053 command . Prepare ( _statusMonitor ) ;
5154 command . Execute ( CancellationToken . Empty ) ;
5255
5356 if ( i == 0 )
5457 {
5558 licenseDialog . Received ( 1 ) . Display ( Arg . Any < LicenseDialogMessageType > ( ) ) ;
56- Assert . IsTrue ( _cache . Dictionary . ContainsValue ( key ) ) ;
59+ localMetaData . Received ( ) . SetProductKey ( key ) ;
60+ localMetaData . GetProductKey ( ) . Returns ( key ) ;
5761 Assert . IsTrue ( _cache . Dictionary . ContainsValue ( keySecret ) ) ;
5862 }
5963 else
6064 {
6165 licenseDialog . Received ( 1 ) . SetKey ( key ) ;
6266 licenseDialog . DidNotReceive ( ) . Display ( Arg . Any < LicenseDialogMessageType > ( ) ) ;
63- Assert . IsTrue ( _cache . Dictionary . ContainsValue ( key ) ) ;
67+ localMetaData . Received ( ) . SetProductKey ( key ) ;
6468 Assert . IsTrue ( _cache . Dictionary . ContainsValue ( keySecret ) ) ;
6569 }
6670 }
@@ -77,7 +81,9 @@ public void Execute_ProperlyHandlesSitauationWhenKeysAreNotUsed()
7781 UseKeys = false
7882 } ) ;
7983
80- var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , _cache , _logger ) ;
84+ var localMetaData = Substitute . For < ILocalMetaData > ( ) ;
85+
86+ var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , localMetaData , _cache , _logger ) ;
8187 command . Prepare ( _statusMonitor ) ;
8288 command . Execute ( CancellationToken . Empty ) ;
8389
@@ -106,6 +112,8 @@ public void Execute_DisplaysDialogMessageForApiError(int statusCode, LicenseDial
106112 {
107113 UseKeys = true
108114 } ) ;
115+
116+ var localMetaData = Substitute . For < ILocalMetaData > ( ) ;
109117
110118 bool firstAttempt = true ;
111119
@@ -120,7 +128,7 @@ public void Execute_DisplaysDialogMessageForApiError(int statusCode, LicenseDial
120128 throw new ApiResponseException ( statusCode ) ;
121129 } ) ;
122130
123- var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , _cache , _logger ) ;
131+ var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , localMetaData , _cache , _logger ) ;
124132 command . Prepare ( _statusMonitor ) ;
125133 command . Execute ( CancellationToken . Empty ) ;
126134
@@ -162,7 +170,9 @@ public void Execute_DisplaysProperDialogMessageForConnectionError()
162170 throw new ApiConnectionException ( new List < Exception > ( ) , new List < Exception > ( ) ) ;
163171 } ) ;
164172
165- var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , _cache , _logger ) ;
173+ var localMetaData = Substitute . For < ILocalMetaData > ( ) ;
174+
175+ var command = new ValidateLicenseCommand ( licenseDialog , remoteMetaData , localMetaData , _cache , _logger ) ;
166176 command . Prepare ( _statusMonitor ) ;
167177 command . Execute ( CancellationToken . Empty ) ;
168178
0 commit comments