@@ -20,6 +20,7 @@ namespace Microsoft.Azure.Devices.E2ETests
20
20
public partial class MessageReceiveE2ETests : IDisposable
21
21
{
22
22
private static readonly string s_devicePrefix = $ "E2E_{ nameof ( MessageReceiveE2ETests ) } _";
23
+
23
24
private static readonly TestLogging s_log = TestLogging . GetInstance ( ) ;
24
25
private static readonly TimeSpan s_oneMinute = TimeSpan . FromMinutes ( 1 ) ;
25
26
private static readonly TimeSpan s_oneSecond = TimeSpan . FromSeconds ( 1 ) ;
@@ -220,30 +221,33 @@ public async Task Message_DeviceReceiveMessageOperationTimeout_MqttWs()
220
221
await ReceiveMessageInOperationTimeoutAsync ( TestDeviceType . Sasl , Client . TransportType . Mqtt_WebSocket_Only ) . ConfigureAwait ( false ) ;
221
222
}
222
223
223
- public static ( Message message , string messageId , string payload , string p1Value ) ComposeC2dTestMessage ( )
224
+ public static ( Message message , string payload , string p1Value ) ComposeC2dTestMessage ( )
224
225
{
225
226
var payload = Guid . NewGuid ( ) . ToString ( ) ;
226
227
var messageId = Guid . NewGuid ( ) . ToString ( ) ;
227
228
var p1Value = Guid . NewGuid ( ) . ToString ( ) ;
229
+ var userId = Guid . NewGuid ( ) . ToString ( ) ;
228
230
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 } '") ;
230
232
var message = new Message ( Encoding . UTF8 . GetBytes ( payload ) )
231
233
{
232
234
MessageId = messageId ,
235
+ UserId = userId ,
233
236
Properties = { [ "property1" ] = p1Value }
234
237
} ;
235
238
236
- return ( message , messageId , payload , p1Value ) ;
239
+ return ( message , payload , p1Value ) ;
237
240
}
238
241
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 )
240
243
{
244
+ string receivedMessageDestination = $ "/devices/{ deviceId } /messages/deviceBound";
245
+
241
246
var sw = new Stopwatch ( ) ;
242
247
bool received = false ;
243
248
244
249
sw . Start ( ) ;
245
250
246
-
247
251
while ( ! received && sw . ElapsedMilliseconds < FaultInjection . RecoveryTimeMilliseconds )
248
252
{
249
253
Client . Message receivedMessage = null ;
@@ -277,14 +281,19 @@ public static async Task VerifyReceivedC2DMessageAsync(Client.TransportType tran
277
281
// ignore exception from CompleteAsync
278
282
}
279
283
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
+
280
288
string messageData = Encoding . ASCII . GetString ( receivedMessage . GetBytes ( ) ) ;
281
289
s_log . WriteLine ( $ "{ nameof ( VerifyReceivedC2DMessageAsync ) } : Received message: for { deviceId } : { messageData } ") ;
282
290
if ( Equals ( payload , messageData ) )
283
291
{
284
292
Assert . AreEqual ( 1 , receivedMessage . Properties . Count , $ "The count of received properties did not match for device { deviceId } ") ;
285
293
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 } ") ;
288
297
received = true ;
289
298
}
290
299
}
@@ -422,11 +431,11 @@ private async Task ReceiveSingleMessageAsync(TestDeviceType type, Client.Transpo
422
431
423
432
await serviceClient . OpenAsync ( ) . ConfigureAwait ( false ) ;
424
433
425
- ( Message msg , string messageId , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
434
+ ( Message msg , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
426
435
using ( msg )
427
436
{
428
437
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 ) ;
430
439
}
431
440
432
441
await deviceClient . CloseAsync ( ) . ConfigureAwait ( false ) ;
@@ -450,7 +459,7 @@ private async Task ReceiveSingleMessageWithCancellationTokenAsync(TestDeviceType
450
459
451
460
await serviceClient . OpenAsync ( ) . ConfigureAwait ( false ) ;
452
461
453
- ( Message msg , string messageId , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
462
+ ( Message msg , string payload , string p1Value ) = ComposeC2dTestMessage ( ) ;
454
463
using ( msg )
455
464
{
456
465
await serviceClient . SendAsync ( testDevice . Id , msg ) . ConfigureAwait ( false ) ;
0 commit comments