private static Messaging CreateMessagingHeader(AS4Message message)
        {
            object ToGeneralMessageUnit(MessageUnit u)
            {
                switch (u)
                {
                case UserMessage um: return(UserMessageMap.Convert(um));

                case Receipt r: return(ReceiptMap.Convert(r));

                case Error e: return(ErrorMap.Convert(e));

                case PullRequest pr: return(PullRequestMap.Convert(pr));

                default:
                    throw new NotSupportedException(
                              $"AS4Message contains unkown MessageUnit of type: {u.GetType()}");
                }
            }

            var messagingHeader = new Messaging
            {
                SecurityId   = message.SigningId.HeaderSecurityId,
                MessageUnits = message.MessageUnits.Select(ToGeneralMessageUnit).ToArray()
            };

            if (message.IsMultiHopMessage)
            {
                messagingHeader.role                     = Constants.Namespaces.EbmsNextMsh;
                messagingHeader.mustUnderstand1          = true;
                messagingHeader.mustUnderstand1Specified = true;
            }

            return(messagingHeader);
        }
        public Property Mapping_Receipt_Back_And_Forth_Stays_The_Same(Receipt receipt)
        {
            // Act
            var result = ReceiptMap.Convert(ReceiptMap.Convert(receipt), receipt.MultiHopRouting);

            // Assert
            return(receipt.MessageId.Equals(result.MessageId).Label("equal message id")
                   .And(receipt.RefToMessageId.Equals(result.RefToMessageId).Label("equal ref to message id"))
                   .And(receipt.NonRepudiationInformation.Equals(result.NonRepudiationInformation).Label("equal non repudiation"))
                   .And(receipt.MultiHopRouting.Equals(result.MultiHopRouting)).Label("equal routing usermessage"));
        }
        private static SignalMessage ConvertSignalMessageFromXml(Xml.SignalMessage signalMessage, Maybe <RoutingInputUserMessage> routing)
        {
            if (signalMessage.Error != null)
            {
                return(ErrorMap.Convert(signalMessage, routing));
            }

            if (signalMessage.PullRequest != null)
            {
                return(PullRequestMap.Convert(signalMessage));
            }

            if (signalMessage.Receipt != null)
            {
                return(ReceiptMap.Convert(signalMessage, routing));
            }

            throw new NotSupportedException("Unable to map Xml.SignalMessage to SignalMessage");
        }