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_Error_Back_And_Forth_Stays_The_Same(Error error)
        {
            // Act
            var result = ErrorMap.Convert(ErrorMap.Convert(error), error.MultiHopRouting);

            // Assert
            return(error.MessageId.Equals(result.MessageId).Label("equal message id")
                   .And(error.RefToMessageId.Equals(result.RefToMessageId).Label("equal ref to message id"))
                   .And(error.ErrorLines.SequenceEqual(result.ErrorLines).Label("equal error lines"))
                   .And(error.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");
        }