Ejemplo n.º 1
0
        public async Task ReturnsErrorMessageWhenDecryptionCertificateCannotBeFound()
        {
            var userMessage = new UserMessage(
                Guid.NewGuid().ToString(),
                new CollaborationInfo(
                    agreement: new AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: "receiveagent-non_existing_decrypt_cert-pmode"),
                    service: new Service(
                        value: "errorhandling",
                        type: "as4.net:receive_agent:componenttest"),
                    action: "as4.net:receive_agent:decryption_failed",
                    conversationId: "as4.net:receive_agent:conversation"));

            var as4Message = CreateAS4MessageWithAttachment(userMessage);

            var encryptedMessage = AS4MessageUtils.EncryptWithCertificate(as4Message, new StubCertificateRepository().GetStubCertificate());

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, encryptedMessage);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var contentType = response.Content.Headers.ContentType.MediaType;
            var result      = await SerializerProvider.Default.Get(contentType)
                              .DeserializeAsync(await response.Content.ReadAsStreamAsync(), contentType);

            Assert.True(result.IsSignalMessage);

            var errorMessage = result.FirstSignalMessage as Error;

            Assert.NotNull(errorMessage);
            Assert.Equal(ErrorCode.Ebms0102, errorMessage.ErrorLines.First().ErrorCode);
        }
            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));
            }