Esempio n. 1
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);
            });
        }
            public void ThenInsertInMessageSucceedsAsync(string sharedId)
            {
                // Arrange
                InsertInMessageWithOperation(sharedId);

                // Assert
                GetDataStoreContext.AssertInMessage(sharedId, Assert.NotNull);
            }
Esempio n. 3
0
        public async Task During_Saving_The_Deserialized_AS4Message_Is_Used_Instead_Of_Deserializing_Incoming_Stream()
        {
            // Arrange
            var receipt = new Receipt($"receipt-{Guid.NewGuid()}", $"reftoid-{Guid.NewGuid()}");
            var ctx     = new MessagingContext(
                AS4Message.Create(receipt),
                new ReceivedMessage(Stream.Null, Constants.ContentTypes.Soap),
                MessagingContextMode.Receive);

            // Act
            await Step.ExecuteAsync(ctx);

            // Assert
            GetDataStoreContext.AssertInMessage(receipt.MessageId, Assert.NotNull);
        }
            public async Task ThenUpdateInMessageSucceedsAsync(string sharedId)
            {
                // Arrange
                InsertInMessageWithOperation(sharedId, Operation.ToBeDelivered);

                // Act
                using (DatastoreContext context = GetDataStoreContext())
                {
                    new DatastoreRepository(context).UpdateInMessage(
                        sharedId,
                        m => m.Operation = Operation.Delivered);

                    await context.SaveChangesAsync();
                }

                // Assert
                GetDataStoreContext.AssertInMessage(sharedId, m => Assert.Equal(Operation.Delivered, m.Operation));
            }
Esempio n. 5
0
        public async Task ThenExecuteStepSavesBothUserAndReceiptMessage()
        {
            // Arrange
            UserMessage   um  = CreateUserMessage();
            SignalMessage r   = CreateReceipt();
            var           as4 = AS4Message.Empty;

            as4.AddMessageUnit(um);
            as4.AddMessageUnit(r);

            // Act
            using (MessagingContext ctx =
                       CreateReceivedMessagingContext(as4, new ReceivingProcessingMode()))
            {
                // Act
                await Step.ExecuteAsync(ctx);
            }

            // Assert
            GetDataStoreContext.AssertInMessage(um.MessageId, Assert.NotNull);
            GetDataStoreContext.AssertInMessage(r.MessageId, Assert.NotNull);
        }
        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. 8
0
        public async Task Retries_Uploading_When_Uploader_Returns_RetryableFail_Result(UploadRetry input)
        {
            // Arrange
            string    id = "deliver-" + Guid.NewGuid();
            InMessage im = InsertInMessage(id);

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

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

            var        a           = new FilledAttachment();
            var        userMessage = new FilledUserMessage(id, a.Id);
            AS4Message as4Msg      = AS4Message.Create(userMessage);

            as4Msg.AddAttachment(a);

            MessagingContext fixture = await PrepareAS4MessageForDeliveryAsync(as4Msg, CreateReceivingPModeWithPayloadMethod());

            IAttachmentUploader stub = CreateStubAttachmentUploader(fixture.DeliverMessage.Message.MessageInfo, input.UploadResult);

            // Act
            await CreateUploadStep(stub).ExecuteAsync(fixture);

            // Assert
            GetDataStoreContext.AssertInMessage(id, actual =>
            {
                Assert.NotNull(actual);
                Assert.Equal(input.ExpectedStatus, actual.Status.ToEnum <InStatus>());
                Assert.Equal(input.ExpectedOperation, actual.Operation);
            });
        }
Esempio n. 9
0
        public async Task All_Attachments_Should_Succeed_Or_Fail(UploadRetry input)
        {
            // Arrange
            string    id = "deliver-" + Guid.NewGuid();
            InMessage im = InsertInMessage(id);

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

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


            var a1          = new FilledAttachment("attachment-1");
            var a2          = new FilledAttachment("attachment-2");
            var userMessage = new FilledUserMessage(id, a1.Id, a2.Id);

            var as4Msg = AS4Message.Create(userMessage);

            as4Msg.AddAttachment(a1);
            as4Msg.AddAttachment(a2);

            MessagingContext fixture = await PrepareAS4MessageForDeliveryAsync(as4Msg, CreateReceivingPModeWithPayloadMethod());

            var stub = new Mock <IAttachmentUploader>();

            stub.Setup(s => s.UploadAsync(a1, fixture.DeliverMessage.Message.MessageInfo))
            .ReturnsAsync(input.UploadResult);
            stub.Setup(s => s.UploadAsync(a2, fixture.DeliverMessage.Message.MessageInfo))
            .ReturnsAsync(
                input.UploadResult.Status == SendResult.Success
                        ? UploadResult.FatalFail
                        : UploadResult.RetryableFail);

            // Act
            await CreateUploadStep(stub.Object).ExecuteAsync(fixture);

            // Assert
            GetDataStoreContext.AssertInMessage(id, actual =>
            {
                Assert.NotNull(actual);
                Operation op = actual.Operation;
                Assert.NotEqual(Operation.Delivered, op);
                InStatus st = actual.Status.ToEnum <InStatus>();
                Assert.NotEqual(InStatus.Delivered, st);

                bool operationToBeRetried     = Operation.ToBeRetried == op;
                bool uploadResultCanBeRetried =
                    input.UploadResult.Status == SendResult.RetryableFail &&
                    input.CurrentRetryCount < input.MaxRetryCount;

                Assert.True(
                    operationToBeRetried == uploadResultCanBeRetried,
                    "InMessage should update Operation=ToBeDelivered");

                bool messageSetToException = Operation.DeadLettered == op && InStatus.Exception == st;
                bool exhaustRetries        =
                    input.CurrentRetryCount == input.MaxRetryCount ||
                    input.UploadResult.Status != SendResult.RetryableFail;

                Assert.True(
                    messageSetToException == exhaustRetries,
                    $"{messageSetToException} != {exhaustRetries} InMessage should update Operation=DeadLettered, Status=Exception");
            });
        }