1- using System ;
1+ using System . Security . Cryptography ;
22using Mastercard . Developer . ClientEncryption . Core . Encryption ;
33using Mastercard . Developer . ClientEncryption . Core . Utils ;
4- using Mastercard . Developer . ClientEncryption . RestSharp . Interceptors ;
54using Mastercard . Developer . OAuth1Signer . Core . Utils ;
6- using Mastercard . Developer . OAuth1Signer . RestSharp . Authenticators ;
75using Microsoft . VisualStudio . TestTools . UnitTesting ;
86using Acme . App . MastercardApi . Client . Api ;
97using Acme . App . MastercardApi . Client . Client ;
108using Acme . App . MastercardApi . Client . Model ;
119using System . Security . Cryptography . X509Certificates ;
10+ using Mastercard . Developer . ClientEncryption . RestSharpV2 . Interceptors ;
1211using static Mastercard . Developer . ClientEncryption . Core . Encryption . FieldLevelEncryptionConfig ;
1312
1413namespace Mastercard . Developer . DigitalEnablement . Tests
@@ -23,7 +22,11 @@ public class TokenizeApiTest
2322 private const string SigningKeyAlias = "fake-key" ;
2423 private const string SigningKeyPassword = "fakepassword" ;
2524 private const string SigningKeyPkcs12FilePath = "./_Resources/fake-signing-key.p12" ;
25+ private const string BasePath = "https://sandbox.api.mastercard.com/mdes/" ;
2626
27+ private static RSA SigningKey { set ; get ; }
28+ private static ApiClient Client { set ; get ; }
29+
2730 // Encryption keys from https://developer.mastercard.com/page/digital-enablement-api-sandbox-configuration
2831 private const string EncryptionCertificateFilePath = "./_Resources/digital-enablement-sandbox-encryption-key.crt" ;
2932 private const string DecryptionKeyFilePath = "./_Resources/digital-enablement-sandbox-decryption-key.key" ;
@@ -36,7 +39,7 @@ public static void Before(TestContext context)
3639
3740 private static void SetupApiClient ( )
3841 {
39- var signingKey = AuthenticationUtils . LoadSigningKey ( SigningKeyPkcs12FilePath , SigningKeyAlias , SigningKeyPassword , X509KeyStorageFlags . MachineKeySet | X509KeyStorageFlags . Exportable ) ;
42+ SigningKey = AuthenticationUtils . LoadSigningKey ( SigningKeyPkcs12FilePath , SigningKeyAlias , SigningKeyPassword , X509KeyStorageFlags . MachineKeySet | X509KeyStorageFlags . Exportable ) ;
4043 var encryptionCertificate = EncryptionUtils . LoadEncryptionCertificate ( EncryptionCertificateFilePath ) ;
4144 var decryptionKey = EncryptionUtils . LoadDecryptionKey ( DecryptionKeyFilePath ) ;
4245
@@ -56,16 +59,17 @@ private static void SetupApiClient()
5659 . WithValueEncoding ( FieldValueEncoding . Hex )
5760 . Build ( ) ;
5861
59- var config = Configuration . Default ;
60- config . BasePath = "https://sandbox.api.mastercard.com/mdes/" ;
61- config . ApiClient . RestClient . Authenticator = new RestSharpOAuth1Authenticator ( ConsumerKey , signingKey , new Uri ( config . BasePath ) ) ;
62- config . ApiClient . EncryptionInterceptor = new RestSharpFieldLevelEncryptionInterceptor ( fieldLevelEncryptionConfig ) ;
62+ Client = new ApiClient ( SigningKey , BasePath , ConsumerKey )
63+ {
64+ EncryptionInterceptor = new RestSharpFieldLevelEncryptionInterceptor ( fieldLevelEncryptionConfig )
65+ } ;
6366 }
6467
6568 [ TestMethod ]
6669 public void TestTokenizeEndpoint ( )
6770 {
68- var tokenizeApi = new TokenizeApi ( Configuration . Default ) ;
71+ var tokenizeApi = new TokenizeApi ( ) ;
72+ tokenizeApi . Client = Client ;
6973 var response = tokenizeApi . CreateTokenize ( BuildTokenizeRequestSchema ( ) ) ;
7074 Assert . IsNotNull ( response ) ;
7175 Assert . AreEqual ( "APPROVED" , response . Decision ) ;
0 commit comments