public void Get_Stream_When_Is_Right_And_Produce_Response()
        {
            //arrange
            var stream = $"{InputHelpers.Inputs[0]}{Environment.NewLine}{Environment.NewLine}{InputHelpers.Inputs[1]}".GenerateStreamFromString();
            var output = new List <string> {
                InputHelpers.Outputs[0], InputHelpers.Outputs[1]
            };

            //act
            var result = _service.Transform <Position, List <string> >(stream).Result;

            //assert
            Assert.That(result, Is.EquivalentTo(output));
        }
Пример #2
0
        public async Task <IHttpActionResult> Post([FromBody] SourceExample source, CancellationToken cancellationToken = default)
        {
            // 4.7.2 Web API does not automatically reject an invalid request.
            // This must be handled manually in 4.7.2.
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // transform the data
            var dest = TransformationService.Transform(source);

            // derive the data
            dest = await DerivationService.Derive(source, dest, cancellationToken);

            // hack put in place for testing post transform validation errors.
            if (dest.TestDeriveStringToBool == bool.FalseString)
            {
                dest.TestDeriveStringToBool = null;
            }

            // validate the object after transformation.
            Validate(dest);

            // handle post transformation validation errors.
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // return the object post transformation & validation
            return(Ok(dest));
        }
        public virtual string Transform(string x12)
        {
            string xml = _preProcessor.Transform(x12);

            XslCompiledTransform transform = GetTransform();

            var writer = new StringWriter();

            transform.Transform(XmlReader.Create(new StringReader(xml)), GetArguments(), writer);
            return(writer.GetStringBuilder().ToString());
        }
        public async Task <IActionResult> Import([FromForm] IFormFile file, TypeOfResult type = TypeOfResult.Object)
        {
            if (file == null)
            {
                _logger.Log(LogLevel.Information, "empty file");
                return(new ContentResult()
                {
                    Content = "empty file", StatusCode = 422
                });
            }

            try
            {
                var transform = await(_transformationService.Transform <Position, List <string> >(file.OpenReadStream()))
                                .ConfigureAwait(false);

                switch (type)
                {
                case TypeOfResult.File:
                    var result = _exportService.Export(transform);
                    return(File(Encoding.UTF8.GetBytes(result), "text/plain", $"output_{DateTime.Now}.txt"));

                case TypeOfResult.Object:
                default:
                    return(Ok(JsonConvert.SerializeObject(transform)));
                }
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, e, "can't import'");

                return(new ContentResult()
                {
                    Content = "Something going wrong", StatusCode = 500
                });
            }
        }