public async Task AsyncSerializeToValidXml()
            {
                // Arrange
                var deliverMessage = new DeliverMessage();

                // Act
                string actualXml = await AS4XmlSerializer.ToStringAsync(deliverMessage);

                // Assert
                Assert.NotEmpty(actualXml);
            }
        public async Task DeserializedPModeWithDefaultValuesContainsDefaultValues()
        {
            var sendingPMode = new SendingProcessingMode();

            var serialized = await AS4XmlSerializer.ToStringAsync(sendingPMode);

            var deserialized = await AS4XmlSerializer.FromStringAsync <SendingProcessingMode>(serialized);

            Assert.Equal(sendingPMode.Security.Encryption.Algorithm, deserialized.Security.Encryption.Algorithm);
            Assert.Equal(sendingPMode.Security.Encryption.AlgorithmKeySize, deserialized.Security.Encryption.AlgorithmKeySize);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the sending.
        /// </summary>
        /// <param name="basePmode">The base pmode.</param>
        /// <returns></returns>
        public async Task CreateSending(SendingBasePmode basePmode)
        {
            string fileName  = FilterOutInvalidFileNameChars(basePmode.Name);
            string pmodeFile = Path.Combine(_settings.Value.SendingPmodeFolder, fileName + ".xml");

            if (File.Exists(pmodeFile))
            {
                pmodeFile = Path.Combine(_settings.Value.SendingPmodeFolder, fileName + "-" + Guid.NewGuid() + ".xml");
            }

            string pmodeString = await AS4XmlSerializer.ToStringAsync(basePmode.Pmode);

            File.WriteAllText(pmodeFile, pmodeString);
        }
Ejemplo n.º 4
0
            public async Task ThenBuildOutMessageSucceedsWithAS4Message()
            {
                // Arrange
                AS4Message as4Message = CreateAS4MessageWithUserMessage(Guid.NewGuid().ToString());

                // Act
                OutMessage outMessage = BuildForPrimaryMessageUnit(as4Message);

                // Assert
                Assert.NotNull(outMessage);
                Assert.Equal(as4Message.ContentType, outMessage.ContentType);
                Assert.Equal(MessageType.UserMessage, outMessage.EbmsMessageType);
                Assert.Equal(await AS4XmlSerializer.ToStringAsync(ExpectedPMode()), outMessage.PMode);
            }
            public async Task ThenBuildInMessageSucceedsWithAS4MessageAndMessageUnit()
            {
                // Arrange
                AS4Message as4Message = AS4Message.Empty;
                Receipt    receipt    = CreateReceiptMessageUnit();

                // Act
                InMessage inMessage =
                    InMessageBuilder.ForSignalMessage(receipt, as4Message, MessageExchangePattern.Push)
                    .WithPMode(new SendingProcessingMode())
                    .BuildAsToBeProcessed();

                // Assert
                Assert.NotNull(inMessage);
                Assert.Equal(as4Message.ContentType, inMessage.ContentType);
                Assert.Equal(await AS4XmlSerializer.ToStringAsync(new SendingProcessingMode()), inMessage.PMode);
                Assert.Equal(MessageType.Receipt, inMessage.EbmsMessageType);
            }
Ejemplo n.º 6
0
        protected virtual async Task <NotifyMessageEnvelope> CreateNotifyMessageEnvelopeAsync(
            AS4Message as4Message,
            string receivedEntityMessageId,
            Type receivedEntityType)
        {
            SignalMessage tobeNotifiedSignal =
                as4Message.SignalMessages.FirstOrDefault(s => s.MessageId == receivedEntityMessageId);

            NotifyMessage notifyMessage =
                AS4MessageToNotifyMessageMapper.Convert(
                    tobeNotifiedSignal,
                    receivedEntityType,
                    as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message));

            var serialized = await AS4XmlSerializer.ToStringAsync(notifyMessage).ConfigureAwait(false);

            return(new NotifyMessageEnvelope(
                       notifyMessage.MessageInfo,
                       notifyMessage.StatusInfo.Status,
                       System.Text.Encoding.UTF8.GetBytes(serialized),
                       "application/xml",
                       receivedEntityType));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Set the PMode that is used to process the message.
        /// </summary>
        /// <param name="pmode"></param>
        public async Task SetPModeInformationAsync(IPMode pmode)
        {
            if (pmode != null)
            {
                PModeId = pmode.Id;

                // The Xml Serializer is not able to serialize an interface, therefore
                // the argument must first be cast to a correct implementation.

                if (pmode is SendingProcessingMode sp)
                {
                    PMode = await AS4XmlSerializer.ToStringAsync(sp);
                }
                else if (pmode is ReceivingProcessingMode rp)
                {
                    PMode = await AS4XmlSerializer.ToStringAsync(rp);
                }
                else
                {
                    throw new NotImplementedException("Unable to serialize the the specified IPMode");
                }
            }
        }