예제 #1
0
파일: Program.cs 프로젝트: wayneqs/claims
        private static void Main(string[] args)
        {
            string path;
            while ((path = CaptureFeedPath(args)) == null)
            {
            }

            const char delimiter = ',';

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var parser = new DelimiterSeparatedFieldParser(delimiter);

            TriangleDimensions largestTriangle;
            using( var inputFileReader = new StreamReader(path) )
            {
                var collector = new ErrorCollector();

                WriteProgress("Processing file (this may take some time)...");

                var columnReader = new ColumnReader(inputFileReader, parser);
                var dimensionReader = new Reader<TriangleFeedYearExtract>(columnReader, collector);
                var largestTriangleCalculator = new LargestTriangleCalculator(dimensionReader.Read);
                largestTriangle = largestTriangleCalculator.Calculate();
                ReportAndQuitIfErrors(collector, path, "triangle_dimension_calculation_errors.txt");
            }

            using( var inputFileReader = new StreamReader(path) )
            {
                var collector = new ErrorCollector();

                using( var outputFileWriter = new StreamWriter(BuildPathFromInputPath(path, "output.csv")) )
                {
                    var columnReader = new ColumnReader(inputFileReader, parser);
                    var paymentRecordReader = new Reader<TriangleFeedFullDataExtract>(columnReader, collector);
                    var triangleBuilder = new TriangleBuilder(paymentRecordReader, collector);
                    Func<ClaimTriangle, string[]> triangleConverter = triangle => triangle.Accumulate().Flatten(largestTriangle);
                    var header = string.Format("{0}, {1}", largestTriangle.OriginYear, largestTriangle.DevelopmentYears);
                    var writer = new ColumnWriter<ClaimTriangle>(triangleBuilder.BuildNext, triangleConverter, header, outputFileWriter, delimiter);
                    writer.Write();
                }

                ReportAndQuitIfErrors(collector, path, "payment_record_errors.txt");
            }

            stopwatch.Stop();

            WriteProgress("Processing took: {0}", stopwatch.Elapsed);
            System.Console.WriteLine("Press any key to quit...");
            System.Console.ReadKey();
        }
                public void ItShouldDumpIntoLastFieldWhenQuoteIsInTheMiddleOfTheLine()
                {
                    var expectedValues = new[] { "hello-world", "123\",14" };

                    var parser = new DelimiterSeparatedFieldParser(',');

                    var actualValues = parser.Parse("hello-world,123\",14");

                    for (int i = 0; i < expectedValues.Length; i++)
                    {
                        Assert.Equal(expectedValues[i], actualValues[i]);
                    }
                }
            public void ItShouldParse()
            {
                var expectedValues = new[] {"hello, world", "Garr", "345","123"};

                var parser = new DelimiterSeparatedFieldParser(',');

                var actualValues = parser.Parse("\"hello, world\",\"Garr\",345,123");

                for (int i = 0; i < expectedValues.Length; i++)
                {
                    Assert.Equal(expectedValues[i], actualValues[i]);
                }
            }
                public void ItShouldDumpIntoOneFieldWhenQuoteIsTheBeginningOfTheLine()
                {
                    var expectedValues = new[] { "hello, world,123" };

                    var parser = new DelimiterSeparatedFieldParser(',');

                    var actualValues = parser.Parse("\"hello, world,123");

                    for (int i = 0; i < expectedValues.Length; i++)
                    {
                        Assert.Equal(expectedValues[i], actualValues[i]);
                    }
                }
 public void ItShouldParseWhiteSpace()
 {
     var parser = new DelimiterSeparatedFieldParser(',');
     Assert.Empty(parser.Parse("    \t     "));
 }
 public void ItShouldParseNull()
 {
     var parser = new DelimiterSeparatedFieldParser(',');
     Assert.Empty(parser.Parse(null));
 }
            public void ItShouldCleanEmptySpace()
            {
                var expectedValues = new[] { "hello-world", "Garr" };

                var parser = new DelimiterSeparatedFieldParser(',');

                var actualValues = parser.Parse("       hello-world     ,       Garr       ");

                for (int i = 0; i < expectedValues.Length; i++)
                {
                    Assert.Equal(expectedValues[i], actualValues[i]);
                }
            }