1+ /*
2+ * Bandwidth
3+ *
4+ * Bandwidth's Communication APIs
5+ *
6+ * The version of the OpenAPI document: 1.0.0
7+ 8+ * Generated by: https://github.com/openapitools/openapi-generator.git
9+ */
10+
111using System ;
12+ using System . Net ;
13+ using System . Threading ;
214using System . Collections . Generic ;
315using Xunit ;
416
517using Bandwidth . Standard . Client ;
618using Bandwidth . Standard . Api ;
719using Bandwidth . Standard . Model ;
8- using System . Net ;
920
1021namespace Bandwidth . Standard . Test . Smoke
1122{
1223 /// <summary>
1324 /// Class for testing PhoneNumberLookupApi
1425 /// </summary>
26+ /// <remarks>
27+ /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
28+ /// Please update the test case below to test the API endpoint.
29+ /// </remarks>
1530 public class PhoneNumberLookupSmokeTests : IDisposable
1631 {
17- private string accountId ;
18- private string BW_NUMBER ;
19- private Configuration fakeConfiguration ;
20- private PhoneNumberLookupApi forbiddenInstance ;
2132 private PhoneNumberLookupApi instance ;
22- private string testRequestId ;
23- private PhoneNumberLookupApi unauthorizedInstance ;
33+ private string accountId ;
34+ private Configuration configuration ;
35+ private string bwNumber ;
36+ private Guid requestId ;
2437
2538 public PhoneNumberLookupSmokeTests ( )
2639 {
2740 accountId = Environment . GetEnvironmentVariable ( "BW_ACCOUNT_ID" ) ;
28- testRequestId = "test-request-id" ;
29- BW_NUMBER = Environment . GetEnvironmentVariable ( "BW_NUMBER" ) ;
41+ bwNumber = Environment . GetEnvironmentVariable ( "BW_NUMBER" ) ;
3042
3143 // Authorized API Client
32- fakeConfiguration = new Configuration ( ) ;
33- fakeConfiguration . BasePath = "https://voice.bandwidth.com/api/v2" ;
34- fakeConfiguration . Username = Environment . GetEnvironmentVariable ( "BW_USERNAME" ) ;
35- fakeConfiguration . Password = Environment . GetEnvironmentVariable ( "BW_PASSWORD" ) ;
36- instance = new PhoneNumberLookupApi ( fakeConfiguration ) ;
37-
38- // Unauthorized API Client
39- fakeConfiguration . Username = "badUsername" ;
40- fakeConfiguration . Password = "badPassword" ;
41- unauthorizedInstance = new PhoneNumberLookupApi ( fakeConfiguration ) ;
42-
43- // Forbidden API Client
44- fakeConfiguration . Username = Environment . GetEnvironmentVariable ( "BW_USERNAME_FORBIDDEN" ) ;
45- fakeConfiguration . Password = Environment . GetEnvironmentVariable ( "BW_PASSWORD_FORBIDDEN" ) ;
46- forbiddenInstance = new PhoneNumberLookupApi ( fakeConfiguration ) ;
44+ configuration = new Configuration ( ) ;
45+ configuration . Username = Environment . GetEnvironmentVariable ( "BW_USERNAME" ) ;
46+ configuration . Password = Environment . GetEnvironmentVariable ( "BW_PASSWORD" ) ;
47+ instance = new PhoneNumberLookupApi ( configuration ) ;
4748 }
4849
4950 public void Dispose ( )
@@ -61,111 +62,83 @@ public void InstanceTest()
6162 }
6263
6364 /// <summary>
64- /// Test successful GetLookupStatus request
65- /// </summary>
66- [ Fact ]
67- public void GetLookupStatusTest ( )
68- {
69- LookupRequest lookupRequest = new LookupRequest ( new List < string > { BW_NUMBER } ) ;
70- var response = instance . CreateLookupWithHttpInfo ( accountId , lookupRequest ) ;
71-
72- var lookupStatus = instance . GetLookupStatus ( accountId , response . Data . RequestId ) ;
73- Assert . IsType < LookupStatus > ( lookupStatus ) ;
74- Assert . Equal ( response . Data . RequestId , lookupStatus . RequestId ) ;
75- Assert . Equal ( BW_NUMBER , lookupStatus . Result [ 0 ] . E164Format ) ;
76- }
77-
78- /// <summary>
79- /// Test GetLookupStatus with an unauthorized client
80- /// </summary>
81- [ Fact ]
82- public void GetLookupStatusUnauthorizedRequest ( )
83- {
84- ApiException Exception = Assert . Throws < ApiException > ( ( ) => unauthorizedInstance . GetLookupStatus ( accountId , testRequestId ) ) ;
85- Assert . Equal ( 401 , Exception . ErrorCode ) ;
86- }
87-
88- /// <summary>
89- /// Test GetLookupStatus with a forbidden client
90- /// API throws a 401 rather than the expected 403
91- /// </summary>
92- [ Fact ]
93- public void GetLookupStatusForbiddenRequest ( )
94- {
95- ApiException Exception = Assert . Throws < ApiException > ( ( ) => forbiddenInstance . GetLookupStatus ( accountId , testRequestId ) ) ;
96- // Assert.Equal(403, Exception.ErrorCode);
97- Assert . Equal ( 401 , Exception . ErrorCode ) ;
98- }
99-
100- /// <summary>
101- /// Test successful CreateLookup request
102- /// </summary>
103- [ Fact ]
104- public void CreateLookupTest ( )
105- {
106- LookupRequest lookupRequest = new LookupRequest ( new List < string > { BW_NUMBER } ) ;
107- var response = instance . CreateLookupWithHttpInfo ( accountId , lookupRequest ) ;
108- Assert . IsType < ApiResponse < CreateLookupResponse > > ( response ) ;
109- Assert . Equal ( LookupStatusEnum . INPROGRESS , response . Data . Status ) ;
110- Assert . IsType < string > ( response . Data . RequestId ) ;
111- Assert . Matches ( "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" , response . Data . RequestId ) ;
112- Assert . Equal ( HttpStatusCode . Accepted , response . StatusCode ) ;
113-
114- var lookupStatus = instance . GetLookupStatus ( accountId , response . Data . RequestId ) ;
115- Assert . IsType < LookupStatus > ( lookupStatus ) ;
116- Assert . Equal ( response . Data . RequestId , lookupStatus . RequestId ) ;
117- Assert . Equal ( BW_NUMBER , lookupStatus . Result [ 0 ] . E164Format ) ;
118-
119- }
120-
121- /// <summary>
122- /// Test CreateLookup with a bad request
123- /// </summary>
124- [ Fact ]
125- public void CreateLookupBadRequest ( )
126- {
127- LookupRequest lookupRequest = new LookupRequest ( new List < string > { "not a number" } ) ;
128- ApiException exception = Assert . Throws < ApiException > ( ( ) => instance . CreateLookup ( accountId , lookupRequest ) ) ;
129- var error = new TnLookupRequestError ( exception . Message ) ;
130- Assert . IsType < TnLookupRequestError > ( error ) ;
131- Assert . Equal ( 400 , exception . ErrorCode ) ;
132-
133- }
134-
135- /// <summary>
136- /// Test CreateLookup with a duplicate phone number lookup
137- /// </summary>
138- [ Fact ]
139- public void CreateLookupDuplicateRequest ( )
140- {
141- LookupRequest lookupRequest = new LookupRequest ( new List < string > { BW_NUMBER , BW_NUMBER } ) ;
142- ApiException Exception = Assert . Throws < ApiException > ( ( ) => instance . CreateLookup ( accountId , lookupRequest ) ) ;
143- Assert . Equal ( 400 , Exception . ErrorCode ) ;
144- Assert . IsType < string > ( Exception . Message ) ;
145- }
146-
147- /// <summary>
148- /// Test CreateLookup with an unauthorized client
65+ /// Test CreateAsyncBulkLookup
14966 /// </summary>
15067 [ Fact ]
151- public void CreateLookupUnauthorizedRequest ( )
68+ public void CreateGetAsyncBulkLookupTest ( )
15269 {
153- LookupRequest lookupRequest = new LookupRequest ( new List < string > { BW_NUMBER } ) ;
154- ApiException Exception = Assert . Throws < ApiException > ( ( ) => unauthorizedInstance . CreateLookup ( accountId , lookupRequest ) ) ;
155- Assert . Equal ( 401 , Exception . ErrorCode ) ;
70+ AsyncLookupRequest asyncLookupRequest = new AsyncLookupRequest (
71+ phoneNumbers : new List < string > { bwNumber }
72+ ) ;
73+ var createResponse = instance . CreateAsyncBulkLookupWithHttpInfo ( accountId , asyncLookupRequest ) ;
74+ Assert . IsType < ApiResponse < CreateAsyncBulkLookupResponse > > ( createResponse ) ;
75+ Assert . Equal ( HttpStatusCode . Accepted , createResponse . StatusCode ) ;
76+ Assert . NotNull ( createResponse . Data ) ;
77+ Assert . IsType < CreateAsyncBulkLookupResponse > ( createResponse . Data ) ;
78+ Assert . NotNull ( createResponse . Data . Data ) ;
79+ Assert . IsType < CreateAsyncBulkLookupResponseData > ( createResponse . Data . Data ) ;
80+ CreateAsyncBulkLookupResponseData createData = createResponse . Data . Data ;
81+ Assert . IsType < Guid > ( createData . RequestId ) ;
82+ Assert . IsType < InProgressLookupStatusEnum > ( createData . Status ) ;
83+ requestId = createData . RequestId ;
84+
85+ Thread . Sleep ( 2000 ) ;
86+
87+ var getResponse = instance . GetAsyncBulkLookupWithHttpInfo ( accountId , requestId ) ;
88+ Assert . IsType < ApiResponse < GetAsyncBulkLookupResponse > > ( getResponse ) ;
89+ Assert . Equal ( HttpStatusCode . OK , getResponse . StatusCode ) ;
90+ Assert . NotNull ( getResponse . Data ) ;
91+ Assert . IsType < GetAsyncBulkLookupResponse > ( getResponse . Data ) ;
92+ Assert . NotNull ( getResponse . Data . Data ) ;
93+ Assert . IsType < GetAsyncBulkLookupResponseData > ( getResponse . Data . Data ) ;
94+ GetAsyncBulkLookupResponseData getData = getResponse . Data . Data ;
95+ Assert . Equal ( getData . RequestId , requestId ) ;
96+ Assert . IsType < InProgressLookupStatusEnum > ( getData . Status ) ;
97+ Assert . Equal ( InProgressLookupStatusEnum . COMPLETE , getData . Status ) ;
98+ Assert . IsType < List < LookupResult > > ( getData . Results ) ;
99+ Assert . NotEmpty ( getData . Results ) ;
100+ Assert . Equal ( bwNumber , getData . Results [ 0 ] . PhoneNumber ) ;
101+ Assert . IsType < LineTypeEnum > ( getData . Results [ 0 ] . LineType ) ;
102+ Assert . Equal ( LineTypeEnum . VOIP , getData . Results [ 0 ] . LineType ) ;
103+ Assert . Equal ( getData . Results [ 0 ] . MessagingProvider , "AdHoc P2P - Bandwidth - SVR" ) ;
104+ Assert . Equal ( getData . Results [ 0 ] . VoiceProvider , "BANDWIDTH" ) ;
105+ Assert . Equal ( getData . Results [ 0 ] . CountryCodeA3 , "USA" ) ;
106+ Assert . Equal ( getData . Results [ 0 ] . LatestMessageDeliveryStatus , LatestMessageDeliveryStatusEnum . ACTIVE ) ;
107+ Assert . IsType < DateTime > ( getData . Results [ 0 ] . InitialMessageDeliveryStatusDate ) ;
108+ Assert . IsType < DateTime > ( getData . Results [ 0 ] . LatestMessageDeliveryStatusDate ) ;
156109 }
157110
158111 /// <summary>
159- /// Test CreateLookup with a forbidden client
112+ /// Test CreateSyncLookup
160113 /// </summary>
161114 [ Fact ]
162- public void CreateLookupForbiddenRequest ( )
115+ public void CreateSyncLookupTest ( )
163116 {
164- LookupRequest lookupRequest = new LookupRequest ( new List < string > { BW_NUMBER } ) ;
165- ApiException Exception = Assert . Throws < ApiException > ( ( ) => forbiddenInstance . CreateLookup ( accountId , lookupRequest ) ) ;
166- //This API throws a 401 when a user provides valid credentials with the `TN Lookup` role disabled
167- // Assert.Equal(403, Exception.ErrorCode);
168- Assert . Equal ( 401 , Exception . ErrorCode ) ;
117+ SyncLookupRequest syncLookupRequest = new SyncLookupRequest (
118+ phoneNumbers : new List < string > { bwNumber }
119+ ) ;
120+ var response = instance . CreateSyncLookupWithHttpInfo ( accountId , syncLookupRequest ) ;
121+ Assert . IsType < ApiResponse < CreateSyncLookupResponse > > ( response ) ;
122+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
123+ Assert . NotNull ( response . Data ) ;
124+ Assert . IsType < CreateSyncLookupResponse > ( response . Data ) ;
125+ Assert . NotNull ( response . Data . Data ) ;
126+ Assert . IsType < CreateSyncLookupResponseData > ( response . Data . Data ) ;
127+ CreateSyncLookupResponseData data = response . Data . Data ;
128+ Assert . IsType < Guid > ( data . RequestId ) ;
129+ Assert . IsType < CompletedLookupStatusEnum > ( data . Status ) ;
130+ Assert . Equal ( CompletedLookupStatusEnum . COMPLETE , data . Status ) ;
131+ Assert . IsType < List < LookupResult > > ( data . Results ) ;
132+ Assert . NotEmpty ( data . Results ) ;
133+ Assert . Equal ( bwNumber , data . Results [ 0 ] . PhoneNumber ) ;
134+ Assert . IsType < LineTypeEnum > ( data . Results [ 0 ] . LineType ) ;
135+ Assert . Equal ( LineTypeEnum . VOIP , data . Results [ 0 ] . LineType ) ;
136+ Assert . Equal ( data . Results [ 0 ] . MessagingProvider , "AdHoc P2P - Bandwidth - SVR" ) ;
137+ Assert . Equal ( data . Results [ 0 ] . VoiceProvider , "BANDWIDTH" ) ;
138+ Assert . Equal ( data . Results [ 0 ] . CountryCodeA3 , "USA" ) ;
139+ Assert . Equal ( data . Results [ 0 ] . LatestMessageDeliveryStatus , LatestMessageDeliveryStatusEnum . ACTIVE ) ;
140+ Assert . IsType < DateTime > ( data . Results [ 0 ] . InitialMessageDeliveryStatusDate ) ;
141+ Assert . IsType < DateTime > ( data . Results [ 0 ] . LatestMessageDeliveryStatusDate ) ;
169142 }
170143 }
171144}
0 commit comments