public void FromMessageTest() { // Arrange byte[] bytes = { 1, 2, 3, 4 }; string messageId = Guid.NewGuid().ToString(); string correlationId = Guid.NewGuid().ToString(); string contentType = "UTF-8"; string contentEncoding = "application/json"; var systemProperties = new Dictionary <string, string> { [SystemProperties.MessageId] = messageId, [SystemProperties.MsgCorrelationId] = correlationId, [SystemProperties.ContentType] = contentType, [SystemProperties.ContentEncoding] = contentEncoding, }; var properties = new Dictionary <string, string> { ["Prop1"] = "Value1", ["Prop2"] = "Value2" }; byte[] GetMessageBody(AmqpMessage sourceMessage) { using (var ms = new MemoryStream()) { sourceMessage.BodyStream.CopyTo(ms); return(ms.ToArray()); } } var message = new EdgeMessage(bytes, properties, systemProperties); var messageConverter = new AmqpMessageConverter(); // Act using (AmqpMessage amqpMessage = messageConverter.FromMessage(message)) { // Assert Assert.NotNull(amqpMessage); Assert.Equal(bytes, GetMessageBody(amqpMessage)); Assert.Equal(messageId, amqpMessage.Properties.MessageId.ToString()); Assert.Equal(correlationId, amqpMessage.Properties.CorrelationId.ToString()); Assert.Equal(contentEncoding, amqpMessage.Properties.ContentEncoding.ToString()); Assert.Equal(contentType, amqpMessage.Properties.ContentType.ToString()); Assert.Equal("Value1", amqpMessage.ApplicationProperties.Map["Prop1"].ToString()); Assert.Equal("Value2", amqpMessage.ApplicationProperties.Map["Prop2"].ToString()); } }
public void TestConnectionDeviceIdTest() { // Setup var systemProperties = new Dictionary <string, string> { [SystemProperties.ConnectionDeviceId] = "edgeDeviceId", [SystemProperties.ConnectionModuleId] = "$edgeHub", [SystemProperties.RpConnectionDeviceIdInternal] = "leafDevice1", [SystemProperties.RpConnectionModuleIdInternal] = "leafModule1", }; byte[] bytes = { 1, 2, 3, 4 }; var message = new EdgeMessage(bytes, new Dictionary <string, string>(), systemProperties); var messageConverter = new AmqpMessageConverter(); // Act using (AmqpMessage amqpMessage = messageConverter.FromMessage(message)) { // Assert Assert.Equal("leafDevice1", amqpMessage.MessageAnnotations.Map[Constants.MessageAnnotationsConnectionDeviceId]); Assert.Equal("leafModule1", amqpMessage.MessageAnnotations.Map[Constants.MessageAnnotationsConnectionModuleId]); } }
public void FromMessageTest_AllProperties() { // Arrange byte[] bytes = { 1, 2, 3, 4 }; string messageId = Guid.NewGuid().ToString(); string correlationId = Guid.NewGuid().ToString(); string contentType = "UTF-8"; string contentEncoding = "application/json"; string to = "d1"; string userId = "userId1"; var expiryTime = new DateTime(2018, 2, 3, 02, 03, 04, DateTimeKind.Utc); string creationTime = new DateTime(2018, 1, 1, 02, 03, 04, DateTimeKind.Utc).ToString("o"); var enqueuedTime = new DateTime(2018, 4, 5, 04, 05, 06, DateTimeKind.Utc); byte deliveryCount = 10; string lockToken = Guid.NewGuid().ToString(); ulong sequenceNumber = 100; string messageSchema = "testSchema"; string operation = "foo"; string inputName = "inputName"; string outputName = "outputName"; string connectionDeviceId = "edgeDevice1"; string connectionModuleId = "module1"; var systemProperties = new Dictionary <string, string> { [SystemProperties.MessageId] = messageId, [SystemProperties.MsgCorrelationId] = correlationId, [SystemProperties.ContentType] = contentType, [SystemProperties.ContentEncoding] = contentEncoding, [SystemProperties.To] = to, [SystemProperties.UserId] = userId, [SystemProperties.ExpiryTimeUtc] = expiryTime.ToString("o"), [SystemProperties.EnqueuedTime] = enqueuedTime.ToString("o"), [SystemProperties.DeliveryCount] = deliveryCount.ToString(), [SystemProperties.LockToken] = lockToken, [SystemProperties.SequenceNumber] = sequenceNumber.ToString(), [SystemProperties.MessageSchema] = messageSchema, [SystemProperties.CreationTime] = creationTime, [SystemProperties.Operation] = operation, [SystemProperties.InputName] = inputName, [SystemProperties.OutputName] = outputName, [SystemProperties.ConnectionDeviceId] = connectionDeviceId, [SystemProperties.ConnectionModuleId] = connectionModuleId }; var properties = new Dictionary <string, string> { ["Prop1"] = "Value1", ["Prop2"] = "Value2" }; byte[] GetMessageBody(AmqpMessage sourceMessage) { using (var ms = new MemoryStream()) { sourceMessage.BodyStream.CopyTo(ms); return(ms.ToArray()); } } var message = new EdgeMessage(bytes, properties, systemProperties); var messageConverter = new AmqpMessageConverter(); // Act using (AmqpMessage amqpMessage = messageConverter.FromMessage(message)) { // Assert Assert.NotNull(amqpMessage); Assert.Equal(bytes, GetMessageBody(amqpMessage)); Assert.Equal(messageId, amqpMessage.Properties.MessageId.ToString()); Assert.Equal(correlationId, amqpMessage.Properties.CorrelationId.ToString()); Assert.Equal(contentEncoding, amqpMessage.Properties.ContentEncoding.ToString()); Assert.Equal(contentType, amqpMessage.Properties.ContentType.ToString()); Assert.Equal(to, amqpMessage.Properties.To.ToString()); Assert.Equal(userId, Encoding.UTF8.GetString(amqpMessage.Properties.UserId.Array)); Assert.Equal(expiryTime, amqpMessage.Properties.AbsoluteExpiryTime.HasValue ? amqpMessage.Properties.AbsoluteExpiryTime.Value : DateTime.MinValue); Assert.Equal(enqueuedTime, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsEnqueuedTimeKey]); Assert.Equal(deliveryCount, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsDeliveryCountKey]); Assert.Equal(lockToken, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsLockTokenName]); Assert.Equal(sequenceNumber, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsSequenceNumberName]); Assert.Equal(inputName, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsInputNameKey]); Assert.Equal(connectionDeviceId, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsConnectionDeviceId]); Assert.Equal(connectionModuleId, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsConnectionModuleId]); Assert.Equal(messageSchema, amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesMessageSchemaKey]); Assert.Equal(creationTime, amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesCreationTimeKey]); Assert.Equal(operation, amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesOperationKey]); Assert.False(amqpMessage.ApplicationProperties.Map.TryGetValue(Amqp.Constants.MessagePropertiesOutputNameKey, out string _)); Assert.Equal("Value1", amqpMessage.ApplicationProperties.Map["Prop1"].ToString()); Assert.Equal("Value2", amqpMessage.ApplicationProperties.Map["Prop2"].ToString()); } }