Beispiel #1
0
        public async Task Expected_number_of_rows_can_be_found_after_parsing_csv()
        {
            var csvTreeReader = new CsvTreeReader(RyansTreeCsv, null);

            var people = await csvTreeReader.ReadAllAsync();

            Assert.Equal(282, people.Count);
        }
Beispiel #2
0
        public async Task Csv_can_be_read_and_rows_parsed()
        {
            var csvTreeReader = new CsvTreeReader(RyansTreeCsv, null);

            var people = await csvTreeReader.ReadAllAsync();

            Assert.NotEmpty(people);
        }
Beispiel #3
0
        public async Task Corrupt_file_contents_do_not_cause_error()
        {
            var csvTreeReader = new CsvTreeReader(CorruptTreeCsv, null);

            var people = await csvTreeReader.ReadAllAsync();

            Assert.Empty(people);
        }
Beispiel #4
0
        public async Task Missing_file_does_not_cause_error()
        {
            var csvTreeReader = new CsvTreeReader("abcd", null);

            var people = await csvTreeReader.ReadAllAsync();

            Assert.Empty(people);
        }
        public static async Task <List <WhoWhatWhereWhen> > ParseTreesFromFilePathAsync(string filePath)
        {
            var csvLoader = new CsvTreeReader(filePath, null);
            var imported  = await csvLoader.ReadAllAsync();

            var treeParser = ConfigureDi.Services.GetRequiredService <TreeParser>();

            return(treeParser.ParseListIntoTrees(imported));
        }
        public async Task Trees_can_be_written()
        {
            var csvTreeReader = new CsvTreeReader(RyansTreeCsv, null);
            var people        = await csvTreeReader.ReadAllAsync();

            var treeParser     = serviceProvider.GetRequiredService <TreeParser>();
            var trees          = treeParser.ParseListIntoTrees(people);
            var file           = new System.IO.FileInfo(Guid.NewGuid().ToString() + ".json");
            var jsonTreeWriter = new JsonTreeWriter(null, file.FullName);

            await jsonTreeWriter.WriteAllAsync(trees);

            Assert.True(file.Exists);
        }
        public Sawyer CreateCsvReaderWriter(string source, string destination)
        {
            var addressQualityChecker = serviceProvider.GetRequiredService <AddressQualityChecker>();
            var readerLogger          = serviceProvider.GetRequiredService <ILogger <CsvTreeReader> >();
            var reader       = new CsvTreeReader(source, readerLogger);
            var writerLogger = serviceProvider.GetRequiredService <ILogger <JsonTreeWriter> >();
            var writer       = new JsonTreeWriter(writerLogger, destination);

            var geocodeManager       = serviceProvider.GetRequiredService <IGeocodeManager>();
            var locationCacheFactory = serviceProvider.GetRequiredService <ILocationCacheFactory>();
            var logger     = serviceProvider.GetRequiredService <ILogger <Sawyer> >();
            var treeParser = serviceProvider.GetRequiredService <TreeParser>();

            return(new Sawyer(addressQualityChecker, geocodeManager, locationCacheFactory, logger, treeParser, reader, writer));
        }
        /// <summary>
        /// Creates an instance of <see cref="Sawyer"/> that is wired up to real I/O but the cache and geocoders are all fake I/O classes for unit testing.
        /// </summary>
        /// <returns></returns>
        public Sawyer CreateWithLocalIO(string source, string destination)
        {
            var addressQualityChecker = serviceProvider.GetRequiredService <AddressQualityChecker>();

            ReaderLogger = serviceProvider.GetRequiredService <FakeLogger <CsvTreeReader> >();
            var reader = new CsvTreeReader(source, ReaderLogger);

            WriterLogger = serviceProvider.GetRequiredService <FakeLogger <JsonTreeWriter> >();
            var writer = new JsonTreeWriter(WriterLogger, destination);

            GeocodeManager       = new FakeGeocodeManager();
            LocationCacheFactory = serviceProvider.GetRequiredService <FakeLocationCacheFactory>();
            TreeParser           = serviceProvider.GetRequiredService <TreeParser>();

            return(new Sawyer(addressQualityChecker, GeocodeManager, LocationCacheFactory, null, TreeParser, reader, writer));
        }