1
1
using System . Collections . Generic ;
2
+ using System . Net ;
2
3
using System . Threading . Tasks ;
3
4
using EasyPost . Exceptions . API ;
4
5
using EasyPost . Exceptions . General ;
6
+ using EasyPost . Http ;
5
7
using EasyPost . Models . API ;
6
8
using EasyPost . Tests . _Utilities ;
7
9
using EasyPost . Tests . _Utilities . Attributes ;
@@ -53,18 +55,18 @@ public async Task TestCreate()
53
55
[ Fact ]
54
56
[ CrudOperations . Create ]
55
57
[ Testing . Parameters ]
56
- public async Task TestCreateWithCustomWorkflow ( )
58
+ public async Task TestCreateFedEx ( )
57
59
{
58
- UseVCR ( "create_with_custom_workflow " ) ;
60
+ UseVCR ( "create_fedex " ) ;
59
61
60
- // Carriers like FedEx and UPS should hit the `/carrier_accounts/register` endpoint
62
+ // FedEx should hit the `/carrier_accounts/register` endpoint
61
63
Dictionary < string , object > data = Fixtures . BasicCarrierAccount ;
62
64
63
65
Parameters . CarrierAccount . CreateFedEx parameters = Fixtures . Parameters . CarrierAccounts . CreateFedEx ( data ) ;
64
66
65
67
try
66
68
{
67
- // confirms we can pass in CreateFedEx and CreateUps parameters to the same Create method because they are children of the generic Create class
69
+ // confirms we can pass in CreateFedEx parameters to the same Create method because they are children of the generic Create class
68
70
CarrierAccount carrierAccount = await Client . CarrierAccount . Create ( parameters ) ;
69
71
CleanUpAfterTest ( carrierAccount . Id ) ;
70
72
}
@@ -81,24 +83,52 @@ public async Task TestCreateWithCustomWorkflow()
81
83
}
82
84
}
83
85
86
+ [ Fact ]
87
+ [ CrudOperations . Create ]
88
+ [ Testing . Parameters ]
89
+ public async Task TestCreateUps ( )
90
+ {
91
+ UseVCR ( "create_ups" ) ;
92
+
93
+ // UPS should hit the `/ups_oauth_registrations` endpoint
94
+ Dictionary < string , object > data = Fixtures . BasicCarrierAccount ;
95
+
96
+ Parameters . CarrierAccount . CreateUps parameters = Fixtures . Parameters . CarrierAccounts . CreateUps ( data ) ;
97
+
98
+ // confirms we can pass in CreateUps parameters to the same Create method because they are children of the generic Create class
99
+ CarrierAccount carrierAccount = await Client . CarrierAccount . Create ( parameters ) ;
100
+ CleanUpAfterTest ( carrierAccount . Id ) ;
101
+
102
+ Assert . IsType < CarrierAccount > ( carrierAccount ) ;
103
+ Assert . StartsWith ( "ca_" , carrierAccount . Id ) ;
104
+ }
105
+
84
106
[ Fact ]
85
107
[ CrudOperations . Create ]
86
108
[ Testing . Exception ]
87
- public async Task TestPreventUsersUsingGenericParameterSetWithCustomWorkflow ( )
109
+ public async Task TestPreventUsersUsingGenericParameterSetWithCustomCreateWorkflow ( )
88
110
{
89
- UseVCR ( "prevent_users_using_generic_parameter_set_with_custom_workflow " ) ;
111
+ UseVCR ( "prevent_users_using_generic_parameter_set_with_custom_create_workflow " ) ;
90
112
91
- // Generic Create parameter set configured for DHL
92
113
Dictionary < string , object > data = Fixtures . BasicCarrierAccount ;
93
114
94
- // Override the type to be a custom type
95
- data [ "type" ] = CarrierAccountType . FedEx . Name ;
96
- data [ "registration_data" ] = new Dictionary < string , object > ( ) ;
115
+ // Generic Create parameter set configured for DHL
116
+ Parameters . CarrierAccount . Create standardParameters = Fixtures . Parameters . CarrierAccounts . Create ( data ) ;
97
117
98
- Parameters . CarrierAccount . Create parameters = Fixtures . Parameters . CarrierAccounts . Create ( data ) ;
118
+ // Override the type to be a custom type
119
+ standardParameters . Type = CarrierAccountType . FedEx . Name ;
99
120
100
121
// should raise an exception because we're using a generic Create set with a custom workflow type (FedExAccount)
101
- await Assert . ThrowsAsync < InvalidParameterError > ( async ( ) => await Client . CarrierAccount . Create ( parameters ) ) ;
122
+ await Assert . ThrowsAsync < InvalidParameterError > ( async ( ) => await Client . CarrierAccount . Create ( standardParameters ) ) ;
123
+
124
+ // Specialized CreateFedEx parameter set configured for FedEx
125
+ Parameters . CarrierAccount . CreateFedEx fedExParameters = Fixtures . Parameters . CarrierAccounts . CreateFedEx ( data ) ;
126
+
127
+ // Override the type to be a standard type
128
+ fedExParameters . Type = "DhlExpressAccount" ;
129
+
130
+ // should raise an exception because we're using a FedEx-specific Create set with a standard workflow type (DhlExpressAccount)
131
+ await Assert . ThrowsAsync < InvalidParameterError > ( async ( ) => await Client . CarrierAccount . Create ( fedExParameters ) ) ;
102
132
}
103
133
104
134
[ Fact ]
@@ -112,7 +142,7 @@ public async Task TestUpdate()
112
142
113
143
Parameters . CarrierAccount . Create createParameters = Fixtures . Parameters . CarrierAccounts . Create ( data ) ;
114
144
115
- CarrierAccount carrierAccount = await Client . CarrierAccount . Create ( createParameters ) ;
145
+ CarrierAccount carrierAccount = await Client . CarrierAccount . Create ( createParameters ) ; // DHL Express
116
146
CleanUpAfterTest ( carrierAccount . Id ) ;
117
147
118
148
const string testDescription = "my custom description" ;
@@ -129,6 +159,72 @@ public async Task TestUpdate()
129
159
Assert . Equal ( testDescription , carrierAccount . Description ) ;
130
160
}
131
161
162
+ [ Fact ]
163
+ [ CrudOperations . Update ]
164
+ [ Testing . Parameters ]
165
+ public async Task TestUpdateUps ( )
166
+ {
167
+ UseVCR ( "update_ups" ) ;
168
+
169
+ Dictionary < string , object > data = Fixtures . BasicCarrierAccount ;
170
+
171
+ Parameters . CarrierAccount . CreateUps createParameters = Fixtures . Parameters . CarrierAccounts . CreateUps ( data ) ;
172
+
173
+ CarrierAccount carrierAccount = await Client . CarrierAccount . Create ( createParameters ) ;
174
+ CleanUpAfterTest ( carrierAccount . Id ) ;
175
+
176
+ const string testDescription = "my custom description" ;
177
+
178
+ Parameters . CarrierAccount . UpdateUps updateParameters = new ( )
179
+ {
180
+ Description = testDescription ,
181
+ } ;
182
+
183
+ carrierAccount = await Client . CarrierAccount . Update ( carrierAccount . Id , updateParameters ) ;
184
+
185
+ Assert . IsType < CarrierAccount > ( carrierAccount ) ;
186
+ Assert . StartsWith ( "ca_" , carrierAccount . Id ) ;
187
+ // Assert.Equal(testDescription, carrierAccount.Description); // TODO: Uncomment when the UPS update endpoint is fixed
188
+ }
189
+
190
+ [ Fact ]
191
+ [ CrudOperations . Create ]
192
+ [ Testing . Exception ]
193
+ public async Task TestPreventUsersUsingGenericParameterSetWithCustomUpdateWorkflow ( )
194
+ {
195
+ UseMockClient ( new List < TestUtils . MockRequest >
196
+ {
197
+ // Fake retrieving an existing UPS account
198
+ new (
199
+ new TestUtils . MockRequestMatchRules ( Method . Get , @"v2\/carrier_accounts\/ca_123$" ) ,
200
+ new TestUtils . MockRequestResponseInfo ( HttpStatusCode . OK , data : new CarrierAccount
201
+ {
202
+ Id = "ca_123" ,
203
+ Type = CarrierAccountType . Ups . Name ,
204
+ }
205
+ )
206
+ ) ,
207
+ new (
208
+ new TestUtils . MockRequestMatchRules ( Method . Get , @"v2\/carrier_accounts\/ca_456$" ) ,
209
+ new TestUtils . MockRequestResponseInfo ( HttpStatusCode . OK , data : new CarrierAccount
210
+ {
211
+ Id = "ca_456" ,
212
+ Type = CarrierAccountType . FedEx . Name ,
213
+ }
214
+ )
215
+ ) ,
216
+ } ) ;
217
+
218
+ Parameters . CarrierAccount . Update genericParameters = new ( ) ;
219
+ Parameters . CarrierAccount . UpdateUps upsParameters = new ( ) ;
220
+
221
+ // should raise an exception because we're using a generic Create set with a custom workflow type (UpsAccount)
222
+ await Assert . ThrowsAsync < InvalidParameterError > ( async ( ) => await Client . CarrierAccount . Update ( "ca_123" , genericParameters ) ) ;
223
+
224
+ // should raise an exception because we're using a UPS-specific Create set with a standard workflow type (FedExAccount)
225
+ await Assert . ThrowsAsync < InvalidParameterError > ( async ( ) => await Client . CarrierAccount . Update ( "ca_456" , upsParameters ) ) ;
226
+ }
227
+
132
228
#endregion
133
229
134
230
#endregion
0 commit comments