@@ -99,7 +99,38 @@ public static void SetUpClass()
9999 public async Task TestSendMessages1 ( )
100100 {
101101 // Parameters for the API call
102- SendMessagesRequest body = APIHelper . JsonDeserialize < Models . SendMessagesRequest > ( "{ \" messages\" : [ { \" callback_url\" : \" https://my.callback.url.com\" , \" content\" : \" My first message\" , \" destination_number\" : \" +61491570156\" , \" delivery_report\" : true, \" format\" : \" SMS\" , \" message_expiry_timestamp\" : \" 2016-11-03T11:49:02.807Z\" , \" metadata\" : { \" key1\" : \" value1\" , \" key2\" : \" value2\" }, \" scheduled\" : \" 2016-11-03T11:49:02.807Z\" , \" source_number\" : \" +61491570157\" , \" source_number_type\" : \" INTERNATIONAL\" }, { \" callback_url\" : \" https://my.callback.url.com\" , \" content\" : \" My second message\" , \" destination_number\" : \" +61491570158\" , \" delivery_report\" : true, \" format\" : \" SMS\" , \" message_expiry_timestamp\" : \" 2016-11-03T11:49:02.807Z\" , \" metadata\" : { \" key1\" : \" value1\" , \" key2\" : \" value2\" }, \" scheduled\" : \" 2016-11-03T11:49:02.807Z\" , \" source_number\" : \" +61491570159\" , \" source_number_type\" : \" INTERNATIONAL\" } ]}" ) ;
102+ SendMessagesRequest body = new SendMessagesRequest ( )
103+ {
104+ Messages = new List < Message >
105+ {
106+ new Message ( )
107+ {
108+ CallbackUrl = "https://my.callback.url.com" ,
109+ Content = "My first message" ,
110+ DestinationNumber = "+61491570156" ,
111+ DeliveryReport = true ,
112+ Format = MessageFormat . SMS ,
113+ MessageExpiryTimestamp = new DateTime ( 2016 , 11 , 03 , 11 , 49 , 02 , DateTimeKind . Utc ) ,
114+ Metadata = new Dictionary < string , string > ( ) { { "key1" , "value1" } , { "key2" , "value2" } } ,
115+ Scheduled = new DateTime ( 2016 , 11 , 03 , 11 , 49 , 02 , DateTimeKind . Utc ) ,
116+ SourceNumber = "+61491570157" ,
117+ SourceNumberType = NumberType . INTERNATIONAL
118+ } ,
119+ new Message ( )
120+ {
121+ CallbackUrl = "https://my.callback.url.com" ,
122+ Content = "My second message" ,
123+ DestinationNumber = "+61491570158" ,
124+ DeliveryReport = true ,
125+ Format = MessageFormat . SMS ,
126+ MessageExpiryTimestamp = new DateTime ( 2016 , 11 , 03 , 11 , 49 , 02 , DateTimeKind . Utc ) ,
127+ Metadata = new Dictionary < string , string > ( ) { { "key1" , "value1" } , { "key2" , "value2" } } ,
128+ Scheduled = new DateTime ( 2016 , 11 , 03 , 11 , 49 , 02 , DateTimeKind . Utc ) ,
129+ SourceNumber = "+61491570159" ,
130+ SourceNumberType = NumberType . INTERNATIONAL
131+ }
132+ }
133+ } ;
103134
104135 // Perform API call
105136 SendMessagesResponse result = null ;
@@ -122,7 +153,7 @@ public async Task TestSendMessages1()
122153 // Test whether the captured response is as we expected
123154 Assert . IsNotNull ( result , "Result should exist" ) ;
124155
125- dynamic messages = result . Messages ; //JObject.Parse(TestHelper.ConvertStreamToString(httpCallBackHandler.Response.RawBody));
156+ dynamic messages = result . Messages ;
126157 int count = ( int ) messages . Count ;
127158
128159 Assert . AreEqual ( count , 2 ) ;
@@ -134,19 +165,19 @@ public async Task TestSendMessages1()
134165 AssertSendMessageResponseValid ( secondMessage , "SMS" , "My second message" , "https://my.callback.url.com" , true , "+61491570158" , "+61491570159" , "queued" ) ;
135166 }
136167
137- private void AssertSendMessageResponseValid ( dynamic message , string expectedFormat , string expectedContent , string expectedCallbackUrl ,
168+ private void AssertSendMessageResponseValid ( Message message , string expectedFormat , string expectedContent , string expectedCallbackUrl ,
138169 bool expectedDeliveryReport , string expectedDestinationNumber , string expectedSourceNumber , string expectedStatus )
139170 {
140- var format = ( string ) message . format ;
141- var content = ( string ) message . content ;
142- var callbackUrl = ( string ) message . callback_url ;
143- var deliveryReport = ( bool ) message . delivery_report ;
144- var destinationNumber = ( string ) message . destination_number ;
145- var sourceNumber = ( string ) message . source_number ;
146- var status = ( string ) message . status ;
147- var messageId = ( string ) message . message_id ;
148- var messageExpiry = ( string ) message . message_expiry_timestamp ;
149- var scheduled = ( string ) message . scheduled ;
171+ var format = message . Format . ToString ( ) ;
172+ var content = ( string ) message . Content ;
173+ var callbackUrl = ( string ) message . CallbackUrl ;
174+ var deliveryReport = ( bool ) message . DeliveryReport ;
175+ var destinationNumber = ( string ) message . DestinationNumber ;
176+ var sourceNumber = ( string ) message . SourceNumber ;
177+ var status = ( string ) message . Status . ToString ( ) ;
178+ var messageId = ( string ) message . MessageId ;
179+ var messageExpiry = message . MessageExpiryTimestamp ;
180+ var scheduled = message . Scheduled ;
150181
151182 Assert . AreEqual ( format , expectedFormat , "Format should match exactly (string literal match)" ) ;
152183 Assert . AreEqual ( content , expectedContent , "Content should match exactly (string literal match)" ) ;
@@ -158,35 +189,24 @@ private void AssertSendMessageResponseValid(dynamic message, string expectedForm
158189
159190 // note, these are non-deterministic, so we only check for their existence.
160191 Assert . IsNotEmpty ( messageId , "Message ID should not be empty." ) ;
161- Assert . IsNotEmpty ( messageExpiry , "Message Expiry should not be empty." ) ;
162- Assert . IsNotEmpty ( scheduled , "Scheduled time should not be empty." ) ;
163-
164- DateTime date ;
165- bool canParse = DateTime . TryParse ( messageExpiry , out date ) ;
166-
167- Assert . IsTrue ( canParse , "Message Expiry must be a valid DateTime" ) ;
192+ Assert . IsNotNull ( messageExpiry , "Message Expiry should not be empty." ) ;
193+ Assert . IsNotNull ( scheduled , "Scheduled time should not be empty." ) ;
168194
169- canParse = DateTime . TryParse ( scheduled , out date ) ;
170- Assert . IsTrue ( canParse , "Scheduled time must be a valid DateTime" ) ;
171-
172- JObject metadata = message . metadata as JObject ;
195+ var metadata = message . Metadata ;
173196
174197 Assert . IsNotNull ( metadata , "Metadata must not be null." ) ;
175198
176199 var metadataCount = metadata . Count ;
177200
178201 Assert . AreEqual ( metadataCount , 2 , "Metadata must have two children." ) ;
179202
180- var firstKey = ( ( dynamic ) metadata ) . key1 ;
181- var secondKey = ( ( dynamic ) metadata ) . key2 ;
182-
183- Assert . IsNotNull ( firstKey , "Metadata must contain key1." ) ;
184- Assert . IsNotNull ( secondKey , "Metadata must contain key2." ) ;
203+ Assert . IsTrue ( metadata . ContainsKey ( "key1" ) , "Metadata must contain key1." ) ;
204+ Assert . IsTrue ( metadata . ContainsKey ( "key2" ) , "Metadata must contain key2." ) ;
185205
186- var firstKeyValue = ( string ) firstKey ;
187- var secondKeyValue = ( string ) secondKey ;
206+ var firstKeyValue = metadata [ "key1" ] ;
207+ var secondKeyValue = metadata [ "key2" ] ;
188208
189- Assert . AreEqual ( firstKeyValue , "value1" , "key1 must equal value1." ) ;
209+ Assert . AreEqual ( firstKeyValue , "value1" , "key1 must equal value1." ) ;
190210 Assert . AreEqual ( secondKeyValue , "value2" , "key2 must equal value1." ) ;
191211 }
192212 }
0 commit comments