Exemplo n.º 1
0
        public void Use_Submit_MessageProperties_When_SendingPMode_MessageProperties_Are_Empty()
        {
            // Arrange
            var submit = new SubmitMessage
            {
                MessageProperties = new[]
                {
                    new AS4.Model.Common.MessageProperty {
                        Name = "originalSender", Type = "Important", Value = "Holodeck"
                    },
                    new AS4.Model.Common.MessageProperty {
                        Name = "finalRecipient", Value = "AS4.NET"
                    },
                }
            };
            var sendingPMode = new SendingProcessingMode
            {
                MessagePackaging =
                {
                    MessageProperties = null
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Assert.Collection(
                result.MessageProperties,
                p => Assert.Equal(("originalSender", "Important", "Holodeck"), (p.Name, p.Type, p.Value)),
                p => Assert.Equal(("finalRecipient", "AS4.NET"), (p.Name, p.Value)));
        }
Exemplo n.º 2
0
        public void Use_SendingPMode_MessageProperties_When_Submit_MessageProperties_Are_Empty()
        {
            // Arrange
            var submit = new SubmitMessage
            {
                MessageProperties = null
            };
            var sendingPMode = new SendingProcessingMode
            {
                MessagePackaging =
                {
                    MessageProperties = new List <MessageProperty>
                    {
                        new MessageProperty {
                            Name      = "capability",Type  = "info", Value = "receiving"
                        },
                        new MessageProperty {
                            Name      = "endpoint", Value = "international"
                        },
                    }
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Assert.Collection(
                result.MessageProperties,
                p => Assert.Equal(("capability", "info", "receiving"), (p.Name, p.Type, p.Value)),
                p => Assert.Equal(("endpoint", "international"), (p.Name, p.Value)));
        }
Exemplo n.º 3
0
        public void Resolves_Mpc_From_Either_Submit_Or_SendingPMode(
            bool allowOverride,
            string submitMpc,
            string pmodeMpc,
            Mapped expected)
        {
            // Arrange
            var submit = new SubmitMessage {
                MessageInfo = { Mpc = submitMpc }
            };
            var sendingPMode = new SendingProcessingMode
            {
                AllowOverride    = allowOverride,
                MessagePackaging = { Mpc = pmodeMpc }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Mapped actual =
                result.Mpc == pmodeMpc
                    ? Mapped.PMode
                    : result.Mpc == submitMpc
                        ? Mapped.Submit
                        : Mapped.Default;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void Fails_When_Submit_Tries_To_Override_ToParty()
        {
            // Arrange
            var submit = new SubmitMessage
            {
                PartyInfo =
                {
                    ToParty                       = new AS4.Model.Common.Party
                    {
                        Role     = Guid.NewGuid().ToString(),
                        PartyIds = new[] { new AS4.Model.Common.PartyId {
                                               Id = Guid.NewGuid().ToString()
                                           } }
                    }
                }
            };
            var sendingPMode = new SendingProcessingMode
            {
                AllowOverride    = false,
                MessagePackaging =
                {
                    PartyInfo   = new PartyInfo
                    {
                        ToParty = new Party(Guid.NewGuid().ToString(), new PartyId(Guid.NewGuid().ToString()))
                    }
                }
            };

            // Act / Assert
            Assert.Throws <NotSupportedException>(
                () => SubmitMessageMap.CreateUserMessage(submit, sendingPMode));
        }
Exemplo n.º 5
0
        public void Create_UserMessage_From_SubmitMessage()
        {
            // Arrange
            const string submitXml =
                @"<?xml version=""1.0""?>
                <SubmitMessage xmlns=""urn:cef:edelivery:eu:as4:messages"">
                  <MessageInfo>
                    <MessageId>F4840B69-8057-40C9-8530-EC91F946C3BF</MessageId>
                  </MessageInfo>
                  <Collaboration>
                    <AgreementRef>
                      <Value>eu.europe.agreements</Value>
                      <PModeId>sample-pmode</PModeId>
                    </AgreementRef>
                  </Collaboration>
                  <MessageProperties>
                    <MessageProperty>
                      <Name>Payloads</Name>
                      <Type>Metadata</Type>
                      <Value>2</Value>
                    </MessageProperty>
                  </MessageProperties>
                  <Payloads>
                    <Payload>
                      <Id>earth</Id>
                      <MimeType>image/jpeg</MimeType>
                      <Location>file:///messages\attachments\earth.jpg</Location>
                      <PayloadProperties/>
                    </Payload>
                    <Payload>
                      <Id>xml-sample</Id>
                      <MimeType>application/xml</MimeType>
                      <Location>file:///messages\attachments\sample.xml</Location>
                      <PayloadProperties>
                        <PayloadProperty>
                          <Name>Important</Name>
                          <Value>Yes</Value>
                        </PayloadProperty>
                      </PayloadProperties>
                    </Payload>
                  </Payloads>
                </SubmitMessage>";

            var submit       = AS4XmlSerializer.FromString <SubmitMessage>(submitXml);
            var sendingPMode = new SendingProcessingMode();

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Assert.NotNull(result);
            Assert.NotEqual(Maybe.Nothing <AgreementReference>(), result.CollaborationInfo.AgreementReference);
            Assert.Single(result.MessageProperties);
            Assert.True(result.PayloadInfo.Count() == 2, "expected 2 part infos");
        }
Exemplo n.º 6
0
        public void Creates_ToParty_From_Either_Submit_Or_SendingPMode(
            bool allowOverride,
            string submitToParty,
            string pmodeToParty,
            Mapped expected)
        {
            // Arrange
            var submit = new SubmitMessage
            {
                PartyInfo =
                {
                    ToParty                       = submitToParty != null
                        ? new AS4.Model.Common.Party
                    {
                        Role     = Guid.NewGuid().ToString(),
                        PartyIds = new[] { new AS4.Model.Common.PartyId {
                                               Id = submitToParty
                                           } }
                    }
                        : null
                }
            };
            var sendingPMode = new SendingProcessingMode
            {
                AllowOverride    = allowOverride,
                MessagePackaging =
                {
                    PartyInfo   = new PartyInfo
                    {
                        ToParty = pmodeToParty != null
                            ? new Party(Guid.NewGuid().ToString(), new PartyId(pmodeToParty))
                            : null
                    }
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Mapped actual =
                result.Receiver.PartyIds.First().Id == pmodeToParty
                    ? Mapped.PMode
                    : result.Receiver.PartyIds.First().Id == submitToParty
                        ? Mapped.Submit
                        : Mapped.Default;

            Assert.Equal(expected, actual);
            Assert.True(
                (actual == Mapped.Default) == (result.Receiver.Equals(AS4.Model.Core.Party.DefaultTo)),
                "fallback on default ToParty when none in Submit and SendingPMode is defined");
        }
Exemplo n.º 7
0
        public void Fails_When_Submit_Tries_To_Override_Mpc()
        {
            // Arrange
            var submit = new SubmitMessage {
                MessageInfo = { Mpc = Guid.NewGuid().ToString() }
            };
            var sendingPMode = new SendingProcessingMode
            {
                AllowOverride    = false,
                MessagePackaging = { Mpc = Guid.NewGuid().ToString() }
            };

            // Act / Assert
            Assert.Throws <NotSupportedException>(
                () => SubmitMessageMap.CreateUserMessage(submit, sendingPMode));
        }
Exemplo n.º 8
0
        public Property Creates_CollaborationInfo_From_Submit_Collaboration(
            NonEmptyString action,
            string pmodeId,
            NonEmptyString agreementValue,
            string agreementType,
            NonEmptyString serviceValue,
            string serviceType,
            NonEmptyString conversationId)
        {
            // Arrange
            var submit = new SubmitMessage
            {
                Collaboration =
                {
                    Action       = action.Get,
                    AgreementRef =
                    {
                        Value   = agreementValue.Get,
                        RefType = agreementType,
                        PModeId = pmodeId
                    },
                    Service        =
                    {
                        Value = serviceValue.Get,
                        Type  = serviceType
                    },
                    ConversationId = conversationId.Get
                }
            };
            var sendingPMode = new SendingProcessingMode();

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            var actual = result.CollaborationInfo;

            return(actual.Action.Equals(action.Get).Label("equal action")
                   .And(actual.Service.Value.Equals(serviceValue.Get).Label("equal service value"))
                   .And(actual.AgreementReference.UnsafeGet.Value.Equals(agreementValue.Get).Label("equal agreement value"))
                   .And(actual.ConversationId.Equals(conversationId.Get).Label("equal conversation id")));
        }
Exemplo n.º 9
0
        public void Combine_Submit_And_SendingPMode_MessageProperties()
        {
            // Arrange
            var submit = new SubmitMessage
            {
                MessageProperties = new []
                {
                    new AS4.Model.Common.MessageProperty {
                        Name = "originalSender", Type = "Important", Value = "Holodeck"
                    },
                    new AS4.Model.Common.MessageProperty {
                        Name = "finalRecipient", Value = "AS4.NET"
                    },
                }
            };
            var sendingPMode = new SendingProcessingMode
            {
                MessagePackaging =
                {
                    MessageProperties = new List <MessageProperty>
                    {
                        new MessageProperty {
                            Name      = "capability",Type  = "info", Value = "receiving"
                        },
                        new MessageProperty {
                            Name      = "endpoint", Value = "international"
                        },
                    }
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Assert.Collection(
                result.MessageProperties,
                p => Assert.Equal(("originalSender", "Important", "Holodeck"), (p.Name, p.Type, p.Value)),
                p => Assert.Equal(("finalRecipient", "AS4.NET"), (p.Name, p.Value)),
                p => Assert.Equal(("capability", "info", "receiving"), (p.Name, p.Type, p.Value)),
                p => Assert.Equal(("endpoint", "international"), (p.Name, p.Value)));
        }
Exemplo n.º 10
0
        public void Creates_Service_From_Either_Submit_Or_SendingPMode(
            bool allowOverride,
            string submitService,
            string pmodeService,
            Mapped expected)
        {
            // Arrange
            var submit = new SubmitMessage
            {
                Collaboration = { Service = { Value = submitService } }
            };
            var sendingPMode = new SendingProcessingMode
            {
                AllowOverride    = allowOverride,
                MessagePackaging =
                {
                    CollaborationInfo = new CollaborationInfo
                    {
                        Service       ={ Value = pmodeService }
                    }
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            string userService = result.CollaborationInfo.Service.Value;
            Mapped actual      =
                userService == pmodeService
                    ? Mapped.PMode
                    : userService == submitService
                        ? Mapped.Submit
                        : Mapped.Default;

            Assert.Equal(expected, actual);
            Assert.True(
                (actual == Mapped.Default) == (result.CollaborationInfo.Service.Equals(Service.TestService)),
                "fallback on test Service when none in Submit and SendingPMode is defined");
        }
Exemplo n.º 11
0
        public void Assign_Compression_Properties_To_Payloads_When_UseCompression_In_SendingPMode_Is_On(
            bool useCompression)
        {
            // Arrange
            var submit = new SubmitMessage
            {
                Payloads = new[]
                {
                    new Payload("xml-payload")
                    {
                        PayloadProperties = new []
                        {
                            new PayloadProperty("DocumentType", "Business Document")
                        }
                    },
                    new Payload("image-payload")
                }
            };
            var sendingPMode = new SendingProcessingMode
            {
                MessagePackaging =
                {
                    UseAS4Compression = useCompression
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Assert.True(2 == result.PayloadInfo.Count(), "expect 2 part infos");
            Assert.All(result.PayloadInfo, p => Assert.StartsWith("cid:", p.Href));
            Assert.True(
                result.PayloadInfo.First().Properties.Count >= 1,
                "original payload property is present");
            Assert.True(
                useCompression == result.PayloadInfo.All(p => p.Properties.ContainsKey("CompressionType")),
                "expect all part infos to have a 'CompressionType' property");
        }
Exemplo n.º 12
0
        public void Fails_When_Submit_Tries_To_Override_Service()
        {
            // Arrange
            var submit = new SubmitMessage
            {
                Collaboration = { Service = { Value = Guid.NewGuid().ToString() } }
            };
            var sendingPMode = new SendingProcessingMode
            {
                MessagePackaging =
                {
                    CollaborationInfo = new CollaborationInfo
                    {
                        Service       ={ Value = Guid.NewGuid().ToString() }
                    }
                }
            };

            // Act / Assert
            Assert.Throws <NotSupportedException>(
                () => SubmitMessageMap.CreateUserMessage(submit, sendingPMode));
        }
Exemplo n.º 13
0
        public void Creates_AgreementReference_From_Either_Submit_Or_SendingPMode(
            bool allowOverride,
            string submitAgreement,
            string pmodeAgreement,
            Mapped expected)
        {
            // Arrange
            var submit = new SubmitMessage
            {
                Collaboration = { AgreementRef = { Value = submitAgreement } }
            };
            var sendingPMode = new SendingProcessingMode
            {
                AllowOverride    = allowOverride,
                MessagePackaging =
                {
                    CollaborationInfo      = new CollaborationInfo
                    {
                        AgreementReference = { Value = pmodeAgreement }
                    }
                }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Mapped actual =
                result.CollaborationInfo
                .AgreementReference
                .Select(a => a.Value == pmodeAgreement
                        ? Mapped.PMode :
                        a.Value == submitAgreement
                            ? Mapped.Submit
                            : Mapped.Default)
                .GetOrElse(Mapped.Default);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Start Mapping from a <see cref="SubmitMessage"/>
        /// to an <see cref="AS4Message"/>
        /// </summary>
        /// <param name="messagingContext"></param>
        /// <returns></returns>
        public async Task <StepResult> ExecuteAsync(MessagingContext messagingContext)
        {
            if (messagingContext == null)
            {
                throw new ArgumentNullException(nameof(messagingContext));
            }

            SubmitMessage submitMessage = messagingContext.SubmitMessage;

            if (submitMessage == null)
            {
                throw new InvalidOperationException(
                          $"{nameof(CreateAS4MessageStep)} requires a SubmitMessage to create an AS4Message from but no AS4Message is present in the MessagingContext");
            }

            if (messagingContext.SendingPMode == null)
            {
                Logger.Debug("No SendingPMode was found, only use information from SubmitMessage to create AS4 UserMessage");
            }

            ValidateSubmitMessage(submitMessage);

            Logger.Trace("Create UserMessage for SubmitMessage");
            UserMessage userMessage = SubmitMessageMap.CreateUserMessage(submitMessage, submitMessage.PMode);

            Logger.Info($"{messagingContext.LogTag} UserMessage with Id \"{userMessage.MessageId}\" created from SubmitMessage");
            AS4Message as4Message = AS4Message.Create(userMessage, messagingContext.SendingPMode);

            IEnumerable <Attachment> attachments =
                await RetrieveAttachmentsForAS4MessageAsync(submitMessage.Payloads)
                .ConfigureAwait(false);

            as4Message.AddAttachments(attachments);

            messagingContext.ModifyContext(as4Message);
            return(StepResult.Success(messagingContext));
        }
Exemplo n.º 15
0
        public void Use_Test_Defaults_When_Submit_Collaboration_Is_Incomplete(string serviceType)
        {
            // Arrange
            var submit = new SubmitMessage
            {
                Collaboration =
                {
                    Action       = null,
                    AgreementRef = null,
                    Service      = { Value = null, Type = serviceType }
                }
            };
            var sendingPMode = new SendingProcessingMode
            {
                MessagePackaging = { CollaborationInfo = null }
            };

            // Act
            UserMessage result = SubmitMessageMap.CreateUserMessage(submit, sendingPMode);

            // Assert
            Assert.True(result.IsTest);
            Assert.Equal(AS4.Model.Core.CollaborationInfo.DefaultTest, result.CollaborationInfo);
        }