Beispiel #1
0
        public void TestConvertShouldReturnCorrectXml()
        {
            //Arrange
            var expectedResult = new XElement("Root",
                                              new XElement("Line1",
                                                           new XElement("name", "Dave"),
                                                           new XElement("address",
                                                                        new XElement("line1", "Street"),
                                                                        new XElement("line2", "Town")
                                                                        )
                                                           )).ToString();

            var testData = new List <string>
            {
                "name,address_line1,address_line2",
                "Dave,Street,Town"
            }.AsQueryable();

            var sut = new CsvToXmlConverter();

            //Act
            var result = sut.Convert(testData).ToString();

            //Assert
            Assert.Equal(expectedResult, result);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var opts   = new Options();
            var result = Parser.Default.ParseArguments(args, opts);

            if (!result)
            {
                Console.WriteLine(HelpText.AutoBuild(opts));
                return;
            }

            var settings = new CsvToXmlSettings()
            {
                RootNodeName  = opts.RootName,
                EntryNodeName = opts.EntryName,
                Header        = opts.HasHeader,
                Separator     = opts.Separator
            };

            if (opts.HeaderToKey != null)
            {
                settings.SetHeaderToKeyMappings(opts.HeaderToKey.ToArray());
            }

            var converter = new CsvToXmlConverter(opts.Input, settings);

            var ret = converter.Convert();

            ret.Save(opts.Output);
        }