public Property Redeserialize_Result_In_Same_MessageUnits_Order(
            NonEmptyArray <MessageUnit> messageUnits)
        {
            // Arrange
            AS4Message start = AS4Message.Create(messageUnits.Get);

            string ToName(MessageUnit u)
            {
                return(u is SignalMessage
                    ? "SignalMessage"
                    : u is UserMessage
                        ? "UserMessage"
                        : "Unknown");
            }

            IEnumerable <string> expected = messageUnits.Get.Select(ToName);

            // Act
            AS4Message end =
                AS4MessageUtils.SerializeDeserializeAsync(start)
                .GetAwaiter()
                .GetResult();

            // Assert
            IEnumerable <string> actual = end.MessageUnits.Select(ToName);

            return(expected
                   .SequenceEqual(actual)
                   .Label($"{String.Join(", ", expected)} != {String.Join(", ", actual)}"));
        }
        public async Task ReserializedMessageHasUntouchedSoapEnvelope()
        {
            AS4Message deserializedAS4Message = await DeserializeToAS4Message(
                rssbus_message,
                @"multipart/related;boundary=""NSMIMEBoundary__e5cfd617-6cec-4276-b190-23f0b25d9d4d"";type=""application/soap+xml"";start=""<_7a711d7c-4d1c-4ce7-ab38-794a01b445e1>""");

            AS4Message reserializedAS4Message = await AS4MessageUtils.SerializeDeserializeAsync(deserializedAS4Message);

            Assert.Equal(
                deserializedAS4Message.EnvelopeDocument.OuterXml,
                reserializedAS4Message.EnvelopeDocument.OuterXml);
        }
            private static async Task <AS4Message> CreateEncryptedAS4Message()
            {
                AS4Message message = AS4Message.Create(new UserMessage("somemessage"));

                message.AddAttachment(
                    new Attachment(
                        "some-attachment",
                        Stream.Null,
                        "text/plain"));

                AS4Message encryptedMessage =
                    AS4MessageUtils.EncryptWithCertificate(
                        message, new StubCertificateRepository().GetStubCertificate());

                return(await AS4MessageUtils.SerializeDeserializeAsync(encryptedMessage));
            }
        public async Task CanDeserializeEncryptAndSerializeSignedMessageWithUntouchedMessagingHeader()
        {
            // Arrange: retrieve an existing signed AS4 Message and encrypt it.
            //          Serialize it again to inspect the Soap envelope of the modified message.
            AS4Message deserializedAS4Message =
                await DeserializeToAS4Message(
                    signed_holodeck_message,
                    @"multipart/related;boundary=""MIMEBoundary_bcb27a6f984295aa9962b01ef2fb3e8d982de76d061ab23f""");

            XmlNode originalSecurityHeader = deserializedAS4Message.SecurityHeader.GetXml().CloneNode(deep: true);

            var encryptionCertificate = new X509Certificate2(certificate_as4, certificate_password);

            // Act: Encrypt the message
            deserializedAS4Message.Encrypt(
                new KeyEncryptionConfiguration(encryptionCertificate),
                DataEncryptionConfiguration.Default);

            // Assert: the soap envelope of the encrypted message should not be equal to the
            //         envelope of the original message since there should be modifications in
            //         the security header.
            Assert.NotEqual(
                originalSecurityHeader.OuterXml,
                deserializedAS4Message.EnvelopeDocument.OuterXml);

            // Serialize it again; the Soap envelope should remain intact, besides
            // some changes that have been made to the security header.
            AS4Message reserializedAS4Message = await AS4MessageUtils.SerializeDeserializeAsync(deserializedAS4Message);

            // Assert: The soap envelopes of both messages should be equal if the
            //         SecurityHeader is not taken into consideration.

            RemoveSecurityHeaderFromMessageEnvelope(reserializedAS4Message);
            RemoveSecurityHeaderFromMessageEnvelope(deserializedAS4Message);

            Assert.Equal(
                reserializedAS4Message.EnvelopeDocument.OuterXml,
                deserializedAS4Message.EnvelopeDocument.OuterXml);
        }