public async Task Fails_To_Store_SignalMessage_When_ReplyPattern_Response_For_Pulled_UserMessage()
        {
            // Arrange
            string userMessageId = $"user-{Guid.NewGuid()}";

            GetDataStoreContext.InsertInMessage(
                new InMessage(userMessageId)
            {
                MEP = MessageExchangePattern.Pull
            });

            var receipt = new Receipt($"receipt-{Guid.NewGuid()}", userMessageId);
            var context = new MessagingContext(
                AS4Message.Create(receipt),
                MessagingContextMode.Receive)
            {
                SendingPMode = new SendingProcessingMode {
                    Id = "shortcut-send-pmode-retrieval"
                },
                ReceivingPMode = new ReceivingProcessingMode
                {
                    ReplyHandling = { ReplyPattern = ReplyPattern.Response }
                }
            };

            // Act / Assert
            await Assert.ThrowsAsync <InvalidOperationException>(
                () => ExerciseStoreSignalMessageAsync(context));
        }
 private void InsertRefInMessage(string refToEbmsMessageId)
 {
     GetDataStoreContext.InsertInMessage(new InMessage(Guid.NewGuid().ToString())
     {
         EbmsRefToMessageId = refToEbmsMessageId
     });
 }
Esempio n. 3
0
        public async Task SignalMessage_Gets_Saved_As_Duplicate_When_InMessage_Exists_With_Same_EbmsRefToMessageId()
        {
            // Arrange
            string ebmsMessageId      = $"receipt-{Guid.NewGuid()}";
            string ebmsRefToMessageId = $"user-{Guid.NewGuid()}";

            GetDataStoreContext.InsertInMessage(
                new InMessage(ebmsMessageId)
            {
                EbmsRefToMessageId = ebmsRefToMessageId
            });

            var receipt = new Receipt(ebmsMessageId, ebmsRefToMessageId);
            var context = new MessagingContext(
                AS4Message.Create(receipt),
                new ReceivedMessage(Stream.Null),
                MessagingContextMode.Receive);

            // Act
            await Step.ExecuteAsync(context);

            // Assert
            InMessage actual = GetDataStoreContext.GetInMessage(
                m => m.EbmsMessageId == ebmsMessageId &&
                m.EbmsRefToMessageId == ebmsRefToMessageId &&
                m.IsDuplicate);

            Assert.True(actual != null, "Saved Receipt should be marked as duplicate");
        }
Esempio n. 4
0
        private async Task TestExecutionException(
            Operation expected,
            MessagingContext context,
            Func <IAgentExceptionHandler, Func <Exception, MessagingContext, Task <MessagingContext> > > getExercise)
        {
            // Arrange
            var inMessage = new InMessage(ebmsMessageId: _expectedId);

            inMessage.SetStatus(InStatus.Received);

            GetDataStoreContext.InsertInMessage(inMessage);

            IAgentExceptionHandler sut = CreateInboundExceptionHandler();
            var exercise = getExercise(sut);

            // Act
            await exercise(new Exception(), context);

            // Assert
            GetDataStoreContext.AssertInMessage(_expectedId, m => Assert.Equal(InStatus.Exception, m.Status.ToEnum <InStatus>()));
            GetDataStoreContext.AssertInException(
                _expectedId,
                ex =>
            {
                Assert.Equal(expected, ex.Operation);
                Assert.Null(ex.MessageLocation);
            });
        }
Esempio n. 5
0
        public Property Updates_Bundled_MessageUnits_For_Forwarding()
        {
            return(Prop.ForAll(
                       CreateUserReceiptArb(),
                       messageUnits =>
            {
                // Before
                Assert.All(
                    messageUnits,
                    u => GetDataStoreContext.InsertInMessage(new InMessage(u.MessageId)));

                // Arrange
                AS4Message received = AS4Message.Create(messageUnits);

                // Act
                ExerciseUpdateReceivedMessage(
                    received,
                    CreateNotifyAllSendingPMode(),
                    CreateForwardingReceivingPMode())
                .GetAwaiter()
                .GetResult();

                // Assert
                IEnumerable <InMessage> updates =
                    GetDataStoreContext.GetInMessages(
                        m => received.MessageIds.Contains(m.EbmsMessageId));

                Assert.All(updates, u => Assert.True(u.Intermediary));

                InMessage primaryUpdate = updates.First(u => u.EbmsMessageId == received.GetPrimaryMessageId());
                Assert.Equal(Operation.ToBeForwarded, primaryUpdate.Operation);
            }));
        }
Esempio n. 6
0
        public async Task ThenExecuteStepWithReceivingPModeAsync()
        {
            // Arrange
            var entity = new InMessage($"error-{Guid.NewGuid()}");

            entity.InitializeIdFromDatabase(1);

            var fixture = new MessagingContext(
                EmptyNotifyMessageEnvelope(Status.Error),
                new ReceivedEntityMessage(entity))
            {
                SendingPMode = new SendingProcessingMode
                {
                    ErrorHandling = { NotifyMethod = new LocationMethod("not-empty-location") }
                }
            };

            GetDataStoreContext.InsertInMessage(new InMessage($"entity-{Guid.NewGuid()}"));

            var   spySender = new SpySender();
            IStep sut       = CreateSendNotifyStepWithSender(spySender);

            // Act
            await sut.ExecuteAsync(fixture);

            // Assert
            Assert.True(spySender.IsNotified);
        }
            private void InsertInMessage(string messageId, Action <InMessage> arrangeMessage)
            {
                var message = new InMessage(ebmsMessageId: messageId);

                arrangeMessage(message);

                GetDataStoreContext.InsertInMessage(message);
            }
Esempio n. 8
0
        public void Set_Retry_Info_When_ReceivingPMode_Is_Configured_For_Retry(
            bool enabled,
            PositiveInt count,
            TimeSpan interval)
        {
            // Arrange
            ClearInExceptions();
            IAgentExceptionHandler sut = CreateInboundExceptionHandler();
            var pmode = new ReceivingProcessingMode();

            pmode.ExceptionHandling.Reliability =
                new RetryReliability
            {
                IsEnabled     = enabled,
                RetryCount    = count.Get,
                RetryInterval = interval.ToString("G")
            };

            var entity = new InMessage($"entity-{Guid.NewGuid()}");

            GetDataStoreContext.InsertInMessage(entity);

            // Act
            sut.HandleExecutionException(
                new Exception(),
                new MessagingContext(
                    new ReceivedEntityMessage(entity),
                    MessagingContextMode.Deliver)
            {
                ReceivingPMode = pmode
            })
            .GetAwaiter()
            .GetResult();

            // Assert
            GetDataStoreContext.AssertInException(ex =>
            {
                Assert.Null(ex.MessageLocation);
                GetDataStoreContext.AssertRetryRelatedInException(
                    ex.Id,
                    rr =>
                {
                    Assert.True(
                        enabled == (0 == rr?.CurrentRetryCount),
                        "CurrentRetryCount != 0 when RetryReliability is enabled");
                    Assert.True(
                        enabled == (count.Get == rr?.MaxRetryCount),
                        enabled
                                ? $"Max retry count failed on enabled: {count.Get} != {rr?.MaxRetryCount}"
                                : $"Max retry count should be 0 on disabled but is {rr?.MaxRetryCount}");
                    Assert.True(
                        enabled == (interval == rr?.RetryInterval),
                        enabled
                                ? $"Retry interval failed on enabled: {interval:G} != {rr?.RetryInterval}"
                                : $"Retry interval should be 0:00:00 on disabled but is {rr?.RetryInterval}");
                });
            });
        }
        public void Stores_Retry_Information_For_ToBePiggyBacked_SignalMessages(bool isEnabled, int maxRetryCount, TimeSpan retryInterval)
        {
            // Arrange
            string userMessageId = $"user-{Guid.NewGuid()}";

            GetDataStoreContext.InsertInMessage(
                new InMessage(userMessageId)
            {
                MEP = MessageExchangePattern.Pull
            });

            var receipt = new Receipt($"receipt-{Guid.NewGuid()}", userMessageId);
            var context = new MessagingContext(
                AS4Message.Create(receipt),
                MessagingContextMode.Receive)
            {
                SendingPMode = new SendingProcessingMode {
                    Id = "shortcut-send-pmode-retrieval"
                },
                ReceivingPMode = new ReceivingProcessingMode
                {
                    ReplyHandling =
                    {
                        ReplyPattern         = ReplyPattern.PiggyBack,
                        PiggyBackReliability = new AS4.Model.PMode.RetryReliability
                        {
                            IsEnabled     = isEnabled,
                            RetryCount    = maxRetryCount,
                            RetryInterval = retryInterval.ToString()
                        }
                    }
                }
            };

            // Act
            ExerciseStoreSignalMessageAsync(context)
            .GetAwaiter()
            .GetResult();

            // Assert
            GetDataStoreContext.AssertOutMessage(
                receipt.MessageId,
                m => GetDataStoreContext.AssertRetryRelatedOutMessage(
                    m.Id,
                    r =>
            {
                Assert.True(
                    isEnabled == (0 == r?.CurrentRetryCount),
                    $"Enabling PiggyBack Reliability should result in 0 = {r?.CurrentRetryCount}");
                Assert.True(
                    isEnabled == (maxRetryCount == r?.MaxRetryCount),
                    $"Enabling PiggyBack Reliability should result in {maxRetryCount} = {r?.MaxRetryCount}");
                Assert.True(
                    isEnabled == (retryInterval == r?.RetryInterval),
                    $"Enabling PiggyBack Reliability should result in {retryInterval} = {r?.RetryInterval}");
            }));
        }
Esempio n. 10
0
        private InMessage InsertInMessage(string id)
        {
            var inMsg = new InMessage(id);

            inMsg.SetStatus(InStatus.Received);
            inMsg.Operation = Operation.Delivering;

            return(GetDataStoreContext.InsertInMessage(inMsg));
        }
Esempio n. 11
0
 private void InsertUserMessage(UserMessage user)
 {
     GetDataStoreContext.InsertInMessage(
         new InMessage(user.MessageId)
     {
         Mpc             = user.Mpc,
         EbmsMessageType = MessageType.UserMessage,
         ContentType     = Constants.ContentTypes.Soap
     });
 }
Esempio n. 12
0
        public Property Updates_Bundled_MessageUnits_For_Delivery()
        {
            return(Prop.ForAll(
                       CreateUserReceiptArb(),
                       messageUnits =>
            {
                // Before
                Assert.All(
                    messageUnits,
                    u => GetDataStoreContext.InsertInMessage(
                        new InMessage(u.MessageId)
                {
                    EbmsMessageType = u is UserMessage
                                    ? MessageType.UserMessage
                                    : MessageType.Receipt
                }));

                // Arrange
                var sut = new UpdateReceivedAS4MessageBodyStep(
                    StubConfig.Default,
                    GetDataStoreContext,
                    _messageBodyStore);

                var ctx = new MessagingContext(
                    AS4Message.Create(messageUnits),
                    MessagingContextMode.Receive)
                {
                    SendingPMode = CreateNotifyAllSendingPMode(),
                    ReceivingPMode = CreateDeliveryReceivingPMode()
                };

                // Act
                sut.ExecuteAsync(ctx)
                .GetAwaiter()
                .GetResult();

                // Assert
                Operation UpdatedOperationOf(MessageType t)
                => t == MessageType.UserMessage
                            ? Operation.ToBeDelivered
                            : Operation.ToBeNotified;

                IEnumerable <InMessage> updates =
                    GetDataStoreContext.GetInMessages(
                        m => ctx.AS4Message.MessageIds.Contains(m.EbmsMessageId));

                Assert.All(
                    updates,
                    u => Assert.Equal(UpdatedOperationOf(u.EbmsMessageType), u.Operation));
            }));
        }
        public async Task Stores_SignalMessage_With_Expected_Operation_According_To_MEP_And_ReplyPattern(
            MessageExchangePattern mep,
            ReplyPattern reply,
            Operation op)
        {
            // Arrange
            string userMessageId = $"user-{Guid.NewGuid()}";

            GetDataStoreContext.InsertInMessage(
                new InMessage(userMessageId)
            {
                MEP = mep
            });

            var receipt = new Receipt($"receipt-{Guid.NewGuid()}", userMessageId);
            var context = new MessagingContext(
                AS4Message.Create(receipt),
                MessagingContextMode.Receive)
            {
                SendingPMode = new SendingProcessingMode {
                    Id = "shortcut-send-pmode-retrieval"
                },
                ReceivingPMode = new ReceivingProcessingMode
                {
                    ReplyHandling = { ReplyPattern = reply }
                }
            };

            // Act
            await ExerciseStoreSignalMessageAsync(context);

            // Assert
            GetDataStoreContext.AssertOutMessage(
                receipt.MessageId,
                m =>
            {
                Assert.NotNull(m);
                Assert.Equal(op, m.Operation);
            });
        }
        public async Task ThenExecuteMethodSucceedsWithValidUserMessageAsync()
        {
            // Arrange
            string id = Guid.NewGuid().ToString();

            GetDataStoreContext.InsertInMessage(
                CreateInMessage(id, InStatus.Received, Operation.ToBeDelivered));

            DeliverMessageEnvelope envelope = AnonymousDeliverEnvelope(id);
            IStep sut = CreateSendDeliverStepWithSender(new SpySender());

            // Act
            await sut.ExecuteAsync(new MessagingContext(envelope) { ReceivingPMode = CreateDefaultReceivingPMode() });

            // Assert
            GetDataStoreContext.AssertInMessage(id, inmessage =>
            {
                Assert.NotNull(inmessage);
                Assert.Equal(InStatus.Delivered, inmessage.Status.ToEnum <InStatus>());
                Assert.Equal(Operation.Delivered, inmessage.Operation);
            });
        }
        public async Task Reset_InMessage_Operation_ToBeDelivered_When_CurrentRetry_LessThen_MaxRetry(DeliverRetry input)
        {
            // Arrange
            string id = Guid.NewGuid().ToString();

            InMessage im = CreateInMessage(id, InStatus.Received, Operation.Delivering);

            GetDataStoreContext.InsertInMessage(im);

            var r = RetryReliability.CreateForInMessage(
                refToInMessageId: im.Id,
                maxRetryCount: input.MaxRetryCount,
                retryInterval: default(TimeSpan),
                type: RetryType.Notification);

            r.CurrentRetryCount = input.CurrentRetryCount;
            GetDataStoreContext.InsertRetryReliability(r);

            DeliverMessageEnvelope envelope = AnonymousDeliverEnvelope(id);

            var stub = new Mock <IDeliverSender>();

            stub.Setup(s => s.SendAsync(envelope))
            .ReturnsAsync(input.SendResult);

            IStep sut = CreateSendDeliverStepWithSender(stub.Object);

            // Act
            await sut.ExecuteAsync(new MessagingContext(envelope) { ReceivingPMode = CreateDefaultReceivingPMode() });

            // Assert
            GetDataStoreContext.AssertInMessage(id, inMessage =>
            {
                Assert.NotNull(inMessage);
                Assert.Equal(input.ExpectedStatus, inMessage.Status.ToEnum <InStatus>());
                Assert.Equal(input.ExpectedOperation, inMessage.Operation);
            });
        }
Esempio n. 16
0
 private void InsertDuplicateUserMessage(MessageUnit userMessage)
 {
     GetDataStoreContext.InsertInMessage(new InMessage(ebmsMessageId: userMessage.MessageId));
 }