コード例 #1
0
        public async Task Uses_custom_xml_field_names_when_supplied()
        {
            var xmlOptions = new XmlConversionOptions
            {
                RootNodeName = "clients",
                RowNodeName  = "client"
            };

            var options = new StructuredDataConversionOptions
            {
                InputData = new StructuredData
                {
                    Format   = StructuredDataFormat.Csv,
                    Contents = await File.ReadAllTextAsync("./multi-row.csv")
                },
                TargetFormat = StructuredDataFormat.Xml,
                XmlOptions   = xmlOptions
            };

            var converter = new StructuredDataConverter(
                new StructuredDataInterpreterFactory(),
                new StructuredDataWriterFactory());

            var result = converter.Convert(options);

            Assert.Equal(StructuredDataFormat.Xml, result.Format);
            Assert.Equal(await File.ReadAllTextAsync("./expected-custom-fields.xml"), result.Contents);
        }
コード例 #2
0
        public void RunConversion(Options commandLineOptions)
        {
            var validationResult = _optionsValidator.Validate(commandLineOptions);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            var fileContents = File.ReadAllText(commandLineOptions.CsvInputFileName);

            var conversionOptions = _conversionOptionsBuilder
                                    .WithInputFormat(StructuredDataFormat.Csv)
                                    .WithInputContents(fileContents)
                                    .WithTargetFormat((StructuredDataFormat)Enum.Parse(typeof(StructuredDataFormat), commandLineOptions.TargetFormat, true))
                                    .WithXmlRootName(commandLineOptions.XmlRootName)
                                    .WithXmlRowName(commandLineOptions.XmlRowName)
                                    .Build();

            var converter = new StructuredDataConverter(
                new StructuredDataInterpreterFactory(),
                new StructuredDataWriterFactory());

            var result = converter.Convert(conversionOptions);

            File.WriteAllText(commandLineOptions.OutputFile, result.Contents);
        }
コード例 #3
0
        public async Task Converts_CSV_to_expected_xml(string inputFilePath, string expectedFilePath)
        {
            var options = new StructuredDataConversionOptions
            {
                InputData = new StructuredData
                {
                    Format   = StructuredDataFormat.Csv,
                    Contents = await File.ReadAllTextAsync(inputFilePath)
                },
                TargetFormat = StructuredDataFormat.Xml
            };

            var converter = new StructuredDataConverter(
                new StructuredDataInterpreterFactory(),
                new StructuredDataWriterFactory());

            var result = converter.Convert(options);

            Assert.Equal(StructuredDataFormat.Xml, result.Format);
            Assert.Equal(await File.ReadAllTextAsync(expectedFilePath), result.Contents);
        }