Пример #1
0
        [InlineData(3, "bigfile.csv", "step3.txt")] //=>not xml ext to avoid auto formatting
        public void CheckStep(int stepNumber, string inputFileName, string expectedFileName)
        {
            var mapper    = new MapperConfiguration(cfg => _ = MapperHelper.Configure(cfg)).CreateMapper();
            var formatter = ((OutputType)stepNumber).GetFormatter();
            var rows      = formatter.Serialize(
                CsvHelperProxy.ReadRows(Path.Combine("Assets", inputFileName))
                .ToResult(mapper)
                );

            //using (var s = new StreamWriter(File.OpenWrite(@"c:\temp\totototo.xml")))
            //{
            //    foreach (var row in rows)
            //        s.WriteLine(row);
            //}
            var expectedRows = new List <string>();

            using (var stream = new StreamReader(File.OpenRead(Path.Combine("Assets", expectedFileName))))
            {
                while (!stream.EndOfStream)
                {
                    expectedRows.Add(stream.ReadLine());
                }
            }

            var expectedEnumerator = expectedRows.GetEnumerator();

            foreach (var row in rows)
            {
                Assert.True(expectedEnumerator.MoveNext(), $"{stepNumber} : too many rows received !");
                Assert.Equal(expectedEnumerator.Current, row);
            }
            Assert.False(expectedEnumerator.MoveNext(), $"{stepNumber} : not enough rows received !");
        }
Пример #2
0
        public static void Run(ApplicationArguments arg)
        {
            var mapper = new MapperConfiguration(cfg => _ = MapperHelper.Configure(cfg)).CreateMapper();

            var rows = arg.OutputType.GetFormatter().Serialize(CsvHelperProxy
                                                               .ReadRows(arg.File).ToResult(mapper)
                                                               );

            foreach (var row in rows)
            {
                System.Console.WriteLine($"{row}");
            }
            System.Console.WriteLine("Press any key...");
            System.Console.ReadKey();
        }
Пример #3
0
        public void CheckResultsBetweenTwoMethods()
        {
            var filepath = Path.Combine("Assets", "bigfile.csv");

            var mapper = new RowModelMapper();

            var homeMade = CsvHelperProxy
                           .ReadRows(filepath)
                           .Select(mapper.Map)
                           .Skip(1)
                           .Where(m => m != null).ToList();

            var expected = CsvHelperProxy.Read <RowModel, RowModelMap>(filepath).ToList();

            foreach (var r in expected)
            {
                Assert.True(homeMade.Remove(r), r.ToString() + " NotFound");
            }
            Assert.Empty(homeMade);

            homeMade = CsvHelperProxy
                       .ReadRowsLowLevel(filepath)
                       .Select(mapper.Map)
                       .Skip(1)
                       .Where(m => m != null).ToList();
            foreach (var r in expected)
            {
                Assert.True(homeMade.Remove(r), r.ToString() + " NotFound");
            }
            Assert.Empty(homeMade);

            var automapper = new MapperConfiguration(cfg => _ = MapperHelper.Configure(cfg)).CreateMapper();

            homeMade = CsvHelperProxy
                       .ReadRows(filepath)
                       .Select(v => automapper.Map <RowModel>(v))
                       .Skip(1)
                       .Where(m => m != null).ToList();
            foreach (var r in expected)
            {
                Assert.True(homeMade.Remove(r), r.ToString() + " NotFound");
            }
            Assert.Empty(homeMade);
        }