@@ -20,6 +20,7 @@ namespace Microsoft.Azure.Devices.E2ETests
2020 public partial class MessageReceiveE2ETests : IDisposable
2121 {
2222 private static readonly string s_devicePrefix = $ "E2E_{ nameof ( MessageReceiveE2ETests ) } _";
23+
2324 private static readonly TestLogging s_log = TestLogging . GetInstance ( ) ;
2425 private static readonly TimeSpan s_oneMinute = TimeSpan . FromMinutes ( 1 ) ;
2526 private static readonly TimeSpan s_oneSecond = TimeSpan . FromSeconds ( 1 ) ;
@@ -220,30 +221,33 @@ public async Task Message_DeviceReceiveMessageOperationTimeout_MqttWs()
220221 await ReceiveMessageInOperationTimeoutAsync ( TestDeviceType . Sasl , Client . TransportType . Mqtt_WebSocket_Only ) . ConfigureAwait ( false ) ;
221222 }
222223
223- public static ( Message message , string messageId , string payload , string p1Value ) ComposeC2dTestMessage ( )
224+ public static ( Message message , string payload , string p1Value ) ComposeC2dTestMessage ( )
224225 {
225226 var payload = Guid . NewGuid ( ) . ToString ( ) ;
226227 var messageId = Guid . NewGuid ( ) . ToString ( ) ;
227228 var p1Value = Guid . NewGuid ( ) . ToString ( ) ;
229+ var userId = Guid . NewGuid ( ) . ToString ( ) ;
228230
229- s_log . WriteLine ( $ "{ nameof ( ComposeC2dTestMessage ) } : messageId='{ messageId } ' payload='{ payload } ' p1Value='{ p1Value } '") ;
231+ s_log . WriteLine ( $ "{ nameof ( ComposeC2dTestMessage ) } : messageId='{ messageId } ' userId=' { userId } ' payload='{ payload } ' p1Value='{ p1Value } '") ;
230232 var message = new Message ( Encoding . UTF8 . GetBytes ( payload ) )
231233 {
232234 MessageId = messageId ,
235+ UserId = userId ,
233236 Properties = { [ "property1" ] = p1Value }
234237 } ;
235238
236- return ( message , messageId , payload , p1Value ) ;
239+ return ( message , payload , p1Value ) ;
237240 }
238241
239- public static async Task VerifyReceivedC2DMessageAsync ( Client . TransportType transport , DeviceClient dc , string deviceId , string payload , string p1Value )
242+ public static async Task VerifyReceivedC2DMessageAsync ( Client . TransportType transport , DeviceClient dc , string deviceId , Message message , string payload )
240243 {
244+ string receivedMessageDestination = $ "/devices/{ deviceId } /messages/deviceBound";
245+
241246 var sw = new Stopwatch ( ) ;
242247 bool received = false ;
243248
244249 sw . Start ( ) ;
245250
246-
247251 while ( ! received && sw . ElapsedMilliseconds < FaultInjection . RecoveryTimeMilliseconds )
248252 {
249253 Client . Message receivedMessage = null ;
@@ -277,14 +281,19 @@ public static async Task VerifyReceivedC2DMessageAsync(Client.TransportType tran
277281 // ignore exception from CompleteAsync
278282 }
279283
284+ Assert . AreEqual ( receivedMessage . MessageId , message . MessageId , "Recieved message Id is not what was sent by service" ) ;
285+ Assert . AreEqual ( receivedMessage . UserId , message . UserId , "Recieved user Id is not what was sent by service" ) ;
286+ Assert . AreEqual ( receivedMessage . To , receivedMessageDestination , "Recieved message destination is not what was sent by service" ) ;
287+
280288 string messageData = Encoding . ASCII . GetString ( receivedMessage . GetBytes ( ) ) ;
281289 s_log . WriteLine ( $ "{ nameof ( VerifyReceivedC2DMessageAsync ) } : Received message: for { deviceId } : { messageData } ") ;
282290 if ( Equals ( payload , messageData ) )
283291 {
284292 Assert . AreEqual ( 1 , receivedMessage . Properties . Count , $ "The count of received properties did not match for device { deviceId } ") ;
285293 System . Collections . Generic . KeyValuePair < string , string > prop = receivedMessage . Properties . Single ( ) ;
286- Assert . AreEqual ( "property1" , prop . Key , $ "The key \" property1\" did not match for device { deviceId } ") ;
287- Assert . AreEqual ( p1Value , prop . Value , $ "The value of \" property1\" did not match for device { deviceId } ") ;
294+ string propertyKey = "property1" ;
295+ Assert . AreEqual ( propertyKey , prop . Key , $ "The key \" property1\" did not match for device { deviceId } ") ;
296+ Assert . AreEqual ( message . Properties [ propertyKey ] , prop . Value , $ "The value of \" property1\" did not match for device { deviceId } ") ;
288297 received = true ;
289298 }
290299 }
@@ -422,11 +431,11 @@ private async Task ReceiveSingleMessageAsync(TestDeviceType type, Client.Transpo
422431
423432 await serviceClient . OpenAsync ( ) . ConfigureAwait ( false ) ;
424433
425- ( Message msg , string messageId , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
434+ ( Message msg , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
426435 using ( msg )
427436 {
428437 await serviceClient . SendAsync ( testDevice . Id , msg ) . ConfigureAwait ( false ) ;
429- await VerifyReceivedC2DMessageAsync ( transport , deviceClient , testDevice . Id , payload , p1Value ) . ConfigureAwait ( false ) ;
438+ await VerifyReceivedC2DMessageAsync ( transport , deviceClient , testDevice . Id , msg , payload ) . ConfigureAwait ( false ) ;
430439 }
431440
432441 await deviceClient . CloseAsync ( ) . ConfigureAwait ( false ) ;
@@ -450,7 +459,7 @@ private async Task ReceiveSingleMessageWithCancellationTokenAsync(TestDeviceType
450459
451460 await serviceClient . OpenAsync ( ) . ConfigureAwait ( false ) ;
452461
453- ( Message msg , string messageId , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
462+ ( Message msg , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
454463 using ( msg )
455464 {
456465 await serviceClient . SendAsync ( testDevice . Id , msg ) . ConfigureAwait ( false ) ;
0 commit comments