Ejemplo n.º 1
0
        public async Task <Response> HandleSendMessageAsync(Request request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var context = await _validationParser.ParseAsync(request.Content).ConfigureAwait(false);

            try
            {
                if (!Validate(context.RsmDocumentType.IsValid()))
                {
                    // TODO: refactor validation when we agree upon a framework for that.
                    throw new SoapAdapterException(context.MessageReference, "Validation error");
                }

                await using (var streamForIngestion = await ConvertToInternalAsync(request.Content, context, request.CorrelationId).ConfigureAwait(false))
                {
                    var internalResponse = await _client.SendAsync(streamForIngestion, context.RsmDocumentType.Value).ConfigureAwait(false);

                    var response = await ConvertFromInternalAsync(internalResponse, context).ConfigureAwait(false);

                    return(new Response(true, response));
                }
            }
            catch (UnknownConverterException)
            {
                return(await _errorResponseFactory.CreateAsync($"B2B001:{context.MessageReference}").ConfigureAwait(false));
            }
        }
Ejemplo n.º 2
0
        public async Task Parser_should_fill_header()
        {
            await using var fs = File.OpenRead("Assets/Rsm001CPR.xml");

            var     sut    = new RsmValidationParser();
            Context actual = await sut.ParseAsync(fs).ConfigureAwait(false);

            Assert.NotNull(actual);

            var expected = new RsmHeader
            {
                Creation                     = Instant.FromUtc(2020, 02, 20, 10, 56, 46),
                Identification               = "MsgId-0.58755000-1582196206",
                DocumentType                 = "392",
                RecipientIdentification      = "5790001330552",
                SenderIdentification         = "5790002263057",
                EnergyBusinessProcess        = "E03",
                EnergyIndustryClassification = "23",
                EnergyBusinessProcessRole    = "DDQ",
                MessageReference             = null,
            };

            Assert.Equal(expected, actual.RsmHeader);
        }