1+ using Checkout . Common ;
2+ using Checkout . Issuing . ControlProfiles . Requests ;
3+ using Checkout . Issuing . ControlProfiles . Responses ;
4+ using Checkout . Payments ;
5+ using Moq ;
6+ using Shouldly ;
7+ using System . Threading ;
8+ using System . Threading . Tasks ;
9+ using Xunit ;
10+
11+ namespace Checkout . Issuing . ControlProfiles
12+ {
13+ public class ControlProfilesClientTest : UnitTestFixture
14+ {
15+ private readonly SdkAuthorization _authorization =
16+ new SdkAuthorization ( PlatformType . DefaultOAuth , ValidDefaultSk ) ;
17+
18+ private readonly Mock < IApiClient > _apiClient = new Mock < IApiClient > ( ) ;
19+ private readonly Mock < SdkCredentials > _sdkCredentials = new Mock < SdkCredentials > ( PlatformType . DefaultOAuth ) ;
20+ private readonly Mock < IHttpClientFactory > _httpClientFactory = new Mock < IHttpClientFactory > ( ) ;
21+ private readonly Mock < CheckoutConfiguration > _configuration ;
22+
23+ public ControlProfilesClientTest ( )
24+ {
25+ _sdkCredentials . Setup ( credentials => credentials . GetSdkAuthorization ( SdkAuthorizationType . OAuth ) )
26+ . Returns ( _authorization ) ;
27+
28+ _configuration = new Mock < CheckoutConfiguration > ( _sdkCredentials . Object ,
29+ Environment . Sandbox , _httpClientFactory . Object ) ;
30+ }
31+
32+ [ Fact ]
33+ private async Task ShouldCreateControlProfile ( )
34+ {
35+ ControlProfileRequest controlProfileRequest = new ControlProfileRequest ( ) ;
36+ ControlProfileResponse controlProfileResponse = new ControlProfileResponse ( ) ;
37+
38+ _apiClient . Setup ( apiClient =>
39+ apiClient . Post < ControlProfileResponse > ( "issuing/controls/control-profiles" , _authorization ,
40+ controlProfileRequest ,
41+ CancellationToken . None , null ) )
42+ . ReturnsAsync ( ( ) => controlProfileResponse ) ;
43+
44+ IIssuingClient client =
45+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
46+
47+ ControlProfileResponse response = await client . CreateControlProfile ( controlProfileRequest ) ;
48+
49+ response . ShouldNotBeNull ( ) ;
50+ response . ShouldBeSameAs ( controlProfileResponse ) ;
51+ }
52+
53+ [ Fact ]
54+ private async Task ShouldGetAllControlProfiles ( )
55+ {
56+ ControlProfilesResponse controlProfilesResponse = new ControlProfilesResponse ( ) ;
57+
58+ _apiClient . Setup ( apiClient =>
59+ apiClient . Get < ControlProfilesResponse > ( "issuing/controls/control-profiles" , _authorization ,
60+ CancellationToken . None ) )
61+ . ReturnsAsync ( ( ) => controlProfilesResponse ) ;
62+
63+ IIssuingClient client =
64+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
65+
66+ ControlProfilesResponse response = await client . GetAllControlProfiles ( "target_id" ) ;
67+
68+ response . ShouldNotBeNull ( ) ;
69+ response . ShouldBeSameAs ( controlProfilesResponse ) ;
70+ }
71+
72+ [ Fact ]
73+ private async Task ShouldGetControlProfileDetails ( )
74+ {
75+ ControlProfileResponse controlProfileResponse = new ControlProfileResponse ( ) ;
76+
77+ _apiClient . Setup ( apiClient =>
78+ apiClient . Get < ControlProfileResponse > ( "issuing/controls/control-profiles/control_profile_id" ,
79+ _authorization ,
80+ CancellationToken . None ) )
81+ . ReturnsAsync ( ( ) => controlProfileResponse ) ;
82+
83+ IIssuingClient client =
84+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
85+
86+ ControlProfileResponse response = await client . GetControlProfileDetails ( "control_profile_id" ) ;
87+
88+ response . ShouldNotBeNull ( ) ;
89+ response . ShouldBeSameAs ( controlProfileResponse ) ;
90+ }
91+
92+ [ Fact ]
93+ private async Task ShouldUpdateControlProfile ( )
94+ {
95+ ControlProfileRequest controlProfileRequest = new ControlProfileRequest ( ) ;
96+ ControlProfileResponse controlProfileResponse = new ControlProfileResponse ( ) ;
97+
98+ _apiClient . Setup ( apiClient =>
99+ apiClient . Patch < ControlProfileResponse > ( "issuing/controls/control-profiles/control_profile_id" ,
100+ _authorization ,
101+ controlProfileRequest ,
102+ CancellationToken . None ,
103+ null ) )
104+ . ReturnsAsync ( ( ) => controlProfileResponse ) ;
105+
106+ IIssuingClient client =
107+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
108+
109+ ControlProfileResponse response =
110+ await client . UpdateControlProfile ( "control_profile_id" , controlProfileRequest ) ;
111+
112+ response . ShouldNotBeNull ( ) ;
113+ response . ShouldBeSameAs ( controlProfileResponse ) ;
114+ }
115+
116+ [ Fact ]
117+ private async Task ShouldDeleteControlProfile ( )
118+ {
119+ VoidResponse removeControlProfileResponse = new VoidResponse ( ) ;
120+
121+ _apiClient . Setup ( apiClient =>
122+ apiClient . Delete < VoidResponse > ( "issuing/controls/control-profiles/control_profile_id" ,
123+ _authorization ,
124+ CancellationToken . None ) )
125+ . ReturnsAsync ( ( ) => removeControlProfileResponse ) ;
126+
127+ IIssuingClient client =
128+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
129+
130+ VoidResponse response = await client . RemoveControlProfile ( "control_profile_id" ) ;
131+
132+ response . ShouldNotBeNull ( ) ;
133+ response . ShouldBeSameAs ( removeControlProfileResponse ) ;
134+ }
135+
136+ [ Fact ]
137+ private async Task ShouldAddTargetToControlProfile ( )
138+ {
139+ Resource response = new Resource ( ) ;
140+
141+ _apiClient . Setup ( apiClient =>
142+ apiClient . Post < Resource > ( "issuing/controls/control-profiles/control_profile_id/add/target_id" ,
143+ _authorization ,
144+ null ,
145+ CancellationToken . None ,
146+ null ) )
147+ . ReturnsAsync ( ( ) => response ) ;
148+
149+ IIssuingClient client =
150+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
151+
152+ Resource result = await client . AddTargetToControlProfile ( "control_profile_id" , "target_id" ) ;
153+
154+ result . ShouldNotBeNull ( ) ;
155+ result . ShouldBeSameAs ( response ) ;
156+ }
157+
158+ [ Fact ]
159+ private async Task ShouldRemoveTargetFromControlProfile ( )
160+ {
161+ Resource response = new Resource ( ) ;
162+
163+ _apiClient . Setup ( apiClient =>
164+ apiClient . Post < Resource > ( "issuing/controls/control-profiles/control_profile_id/remove/target_id" ,
165+ _authorization ,
166+ null ,
167+ CancellationToken . None ,
168+ null ) )
169+ . ReturnsAsync ( ( ) => response ) ;
170+
171+ IIssuingClient client =
172+ new IssuingClient ( _apiClient . Object , _configuration . Object ) ;
173+
174+ Resource result = await client . RemoveTargetFromControlProfile ( "control_profile_id" , "target_id" ) ;
175+
176+ result . ShouldNotBeNull ( ) ;
177+ result . ShouldBeSameAs ( response ) ;
178+ }
179+ }
180+ }
0 commit comments