예제 #1
0
        public void Parse_ValidInput_ReturnsData()
        {
            // Arrange
            var target   = new DataAvailableNotificationParser();
            var contract = new DataAvailableNotificationContract
            {
                UUID             = "94681547-C70D-409C-9255-83B310AF7010",
                Recipient        = "F3FD4E86-BF06-456A-9CC5-6D38FB471DE3",
                MessageType      = "messageType",
                Origin           = "TimeSeries",
                RelativeWeight   = 5,
                SupportsBundling = true
            };

            // Act
            var actual = target.Parse(contract.ToByteArray());

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(contract.UUID, actual.Uuid.ToString().ToUpper(CultureInfo.InvariantCulture));
            Assert.Equal(contract.MessageType, actual.MessageType.Value);
            Assert.Equal(contract.Origin, actual.Origin.ToString());
            Assert.Equal(Guid.Parse(contract.Recipient), actual.Recipient.Value);
            Assert.Equal(contract.RelativeWeight, actual.RelativeWeight);
            Assert.Equal(contract.SupportsBundling, actual.SupportsBundling);
        }
예제 #2
0
        public void Parse_LegacyInput_ReturnsData()
        {
            // Arrange
            var target   = new DataAvailableNotificationParser();
            var contract = new DataAvailableNotificationContract
            {
                UUID             = "94681547-C70D-409C-9255-83B310AF7010",
                MessageType      = "messageType",
                Origin           = "TimeSeries",
                Recipient        = "recipient",
                RelativeWeight   = 5,
                SupportsBundling = true
            };

            // Act
            var actual = target.Parse(contract.ToByteArray());

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(contract.UUID, actual.Uuid.ToString().ToUpper(CultureInfo.InvariantCulture));
            Assert.Equal(contract.MessageType, actual.MessageType.Value);
            Assert.Equal(contract.Origin, actual.Origin.ToString());

#pragma warning disable CS0618
            var legacyVariant = (LegacyActorIdDto)actual.Recipient;
#pragma warning restore CS0618

            Assert.Equal(contract.Recipient, legacyVariant.LegacyValue);
            Assert.Equal(contract.RelativeWeight, actual.RelativeWeight);
            Assert.Equal(contract.SupportsBundling, actual.SupportsBundling);
        }
예제 #3
0
        public Task SendAsync(string correlationId, DataAvailableNotificationDto dataAvailableNotificationDto)
        {
            ArgumentNullException.ThrowIfNull(correlationId, nameof(correlationId));
            ArgumentNullException.ThrowIfNull(dataAvailableNotificationDto, nameof(dataAvailableNotificationDto));

            var sender = _messageBusFactory.GetSenderClient(_messageHubConfig.DataAvailableQueue);

#pragma warning disable CS0618
            var recipient = dataAvailableNotificationDto.Recipient is LegacyActorIdDto legacyActorIdDto
#pragma warning restore CS0618
                ? legacyActorIdDto.LegacyValue
                : dataAvailableNotificationDto.Recipient.Value.ToString();

            var contract = new DataAvailableNotificationContract
            {
                UUID             = dataAvailableNotificationDto.Uuid.ToString(),
                Recipient        = recipient,
                MessageType      = dataAvailableNotificationDto.MessageType.Value,
                Origin           = dataAvailableNotificationDto.Origin.ToString(),
                SupportsBundling = dataAvailableNotificationDto.SupportsBundling,
                RelativeWeight   = dataAvailableNotificationDto.RelativeWeight,
                DocumentType     = dataAvailableNotificationDto.DocumentType
            };

            var messageId = Guid.NewGuid().ToString();

            var message = new ServiceBusMessage(new BinaryData(contract.ToByteArray()))
            {
                MessageId = messageId, PartitionKey = dataAvailableNotificationDto.Origin.ToString()
            }
            .AddDataAvailableIntegrationEvents(correlationId);

            return(sender.PublishMessageAsync <ServiceBusMessage>(message));
        }
예제 #4
0
        private static ServiceBusReceivedMessage CreateMessages(DataAvailableNotificationDto dto)
        {
            var protobuf = new DataAvailableNotificationContract
            {
                UUID             = dto.Uuid.ToString(),
                Recipient        = dto.Recipient.Value.ToString(),
                Origin           = dto.Origin.ToString(),
                MessageType      = dto.MessageType.Value,
                RelativeWeight   = dto.RelativeWeight,
                SupportsBundling = dto.SupportsBundling
            };

            return(MockedMessage.Create(protobuf.ToByteArray()));
        }
예제 #5
0
        public void Parse_InvalidGuid_ThrowsException()
        {
            // Arrange
            var target   = new DataAvailableNotificationParser();
            var contract = new DataAvailableNotificationContract
            {
                UUID             = "invalid_guid",
                MessageType      = "messageType",
                Origin           = "TimeSeries",
                Recipient        = "recipient",
                RelativeWeight   = 5,
                SupportsBundling = true
            };

            // Act + Assert
            Assert.Throws <MessageHubException>(() => target.Parse(contract.ToByteArray()));
        }