Ejemplo n.º 1
0
        /// <summary>
        ///     The actions for the recipient are the following:
        ///     1. Query the message headers.
        ///     2. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example
        ///     time limit)
        ///     3. Fetch the response from the AR and check.
        ///     4. Delete the messages using the message IDs to clean the feed.
        ///     5. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example
        ///     time limit)
        ///     6. Fetch the response from the AR and check.
        /// </summary>
        private static void ActionsForRecipient()
        {
            var queryMessageHeadersService =
                new QueryMessageHeadersService(new HttpMessagingService(HttpClientForRecipient));
            var queryMessageHeadersParameters = new QueryMessagesParameters
            {
                OnboardResponse = Recipient,
                Senders         = new List <string> {
                    Sender.SensorAlternateId
                }
            };

            queryMessageHeadersService.Send(queryMessageHeadersParameters);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            var fetchMessageService = new FetchMessageService(HttpClientForRecipient);
            var fetch = fetchMessageService.Fetch(Recipient);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedHeaderList,
                         decodedMessage.ResponseEnvelope.Type);

            var feedMessageHeaderQuery =
                queryMessageHeadersService.Decode(decodedMessage.ResponsePayloadWrapper.Details);

            Assert.True(feedMessageHeaderQuery.QueryMetrics.TotalMessagesInQuery > 0,
                        "There has to be at least one message in the query.");

            var messageIds =
                (from feed in feedMessageHeaderQuery.Feed from feedHeader in feed.Headers select feedHeader.MessageId)
                .ToList();

            var feedDeleteService =
                new FeedDeleteService(new HttpMessagingService(HttpClientForRecipient));
            var feedDeleteParameters = new FeedDeleteParameters
            {
                OnboardResponse = Recipient,
                MessageIds      = messageIds
            };

            feedDeleteService.Send(feedDeleteParameters);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            fetch = fetchMessageService.Fetch(Recipient);
            Assert.Single(fetch);

            decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);
            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     The actions for the recipient are the following:
        ///     1. Query the message headers.
        ///     2. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example
        ///     time limit)
        ///     3. Fetch the response from the AR and check.
        ///     4. Query the message with that message ID and check the results.
        ///     5. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example
        ///     time limit)
        ///     6. Fetch the response from the AR and check.
        ///     7. Write the message content to the output folder.
        ///     8. Confirm the message using the message ID to clean the feed.
        ///     9. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example
        ///     time limit)
        ///     10. Fetch the response from the AR and check.
        /// </summary>
        private static void ActionsForRecipient()
        {
            var queryMessageHeadersService =
                new QueryMessageHeadersService(new HttpMessagingService(HttpClientForRecipient));
            var queryMessageHeadersParameters = new QueryMessagesParameters
            {
                OnboardResponse = Recipient,
                Senders         = new List <string> {
                    Sender.SensorAlternateId
                }
            };

            queryMessageHeadersService.Send(queryMessageHeadersParameters);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            var fetchMessageService = new FetchMessageService(HttpClientForRecipient);
            var fetch = fetchMessageService.Fetch(Recipient);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedHeaderList,
                         decodedMessage.ResponseEnvelope.Type);

            var feedMessageHeaderQuery =
                queryMessageHeadersService.Decode(decodedMessage.ResponsePayloadWrapper.Details);

            Assert.True(feedMessageHeaderQuery.QueryMetrics.TotalMessagesInQuery > 0,
                        "There has to be at least one message in the query.");

            var messageId = feedMessageHeaderQuery.Feed[0].Headers[0].MessageId;

            var queryMessagesService =
                new QueryMessagesService(new HttpMessagingService(HttpClientForRecipient));
            var queryMessagesParameters = new QueryMessagesParameters
            {
                OnboardResponse = Recipient,
                MessageIds      = new List <string> {
                    messageId
                }
            };

            queryMessagesService.Send(queryMessagesParameters);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            fetch = fetchMessageService.Fetch(Recipient);
            Assert.Single(fetch);

            decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);
            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedMessage,
                         decodedMessage.ResponseEnvelope.Type);

            var feedMessage = queryMessagesService.Decode(decodedMessage.ResponsePayloadWrapper.Details);

            Assert.Equal(1, feedMessage.QueryMetrics.TotalMessagesInQuery);

            var fileName = FilePrefix + feedMessage.Messages[0].Header.MessageId + ".png";
            var image    = Encode.FromMessageContent(feedMessage.Messages[0].Content);

            File.WriteAllBytes(fileName, image);

            var feedConfirmService =
                new FeedConfirmService(new HttpMessagingService(HttpClientForRecipient));
            var feedConfirmParameters = new FeedConfirmParameters
            {
                OnboardResponse = Recipient,
                MessageIds      = new List <string> {
                    messageId
                }
            };

            feedConfirmService.Send(feedConfirmParameters);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            fetch = fetchMessageService.Fetch(Recipient);
            Assert.Single(fetch);

            decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);
            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);

            var messages = DecodeMessageService.Decode(decodedMessage.ResponsePayloadWrapper.Details);

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000206", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "Feed message confirmation confirmed.",
                messages.Messages_[0].Message_);
        }