public async Task Null_file_does_not_cause_error()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, null);

            var people = await jsonTreeWriter.ReadAllAsync();

            Assert.Empty(people);
        }
        public async Task Error_is_indicated_when_people_are_not_found()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, $@"Data\\Empty.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.True(treeStatistics.PeopleNotFound);
        }
        public async Task Error_is_indicated_when_file_is_empty()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, $@"Data\\Empty.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.True(treeStatistics.TreesAreEmpty);
        }
        public async Task Error_is_indicated_when_file_does_not_exist()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, $@"Data\\{System.Guid.NewGuid()}.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.True(treeStatistics.TreesAreEmpty);
        }
        public async Task Empty_tree_results_in_non_null_stats()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, string.Empty);
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.NotNull(treeStatistics);
        }
        public async Task Count_of_people_within_file_is_correct()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, @"Data\\Processed tree.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.Equal(282, treeStatistics.NumberOfPeople);
        }
        public async Task Statistics_can_be_generated_for_valid_file()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, @"Data\\Processed tree.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.NotNull(treeStatistics);
        }
Exemplo n.º 8
0
        public async Task Invalid_locations_raise_flag()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, @"Data\\Processed tree.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.True(treeStatistics.LocationIssuesExist);
        }
Exemplo n.º 9
0
        public static async Task Main(string[] args)
        {
            var configuration = ConfigureSettings.Build(args);

            serviceProvider = ConfigureDi.BuildDi(configuration);
            logger          = serviceProvider.GetService <ILogger <Program> >();

            try
            {
                logger.LogInformation("Starting");

                var configurationChecker = serviceProvider.GetRequiredService <ConfigurationChecker>();
                var configurationCheck   = configurationChecker.ConfigurationIsValid();
                if (configurationCheck.Errors.Any())
                {
                    logger.LogError("Configuration is invalid, stopping.");
                    return;
                }

                var argumentParser = serviceProvider.GetRequiredService <ArgumentParser>();
                var dataFiles      = argumentParser.ParseArgs(args);

                if (dataFiles.UnableToParseArguments)
                {
                    logger.LogError("Unable to parse command line, details follow.");
                    foreach (var message in dataFiles.Errors)
                    {
                        logger.LogCritical(message);
                    }
                }
                else
                {
                    var sawyerFactory = serviceProvider.GetRequiredService <SawyerFactory>();
                    var sawmill       = sawyerFactory.CreateCsvReaderWriter(dataFiles.Source.FullName, dataFiles.Destination.FullName);
                    await sawmill.ProcessTreeDataAsync();

                    // Output a bunch of stats on the tree we just processed.
                    var treeAnalyser   = serviceProvider.GetRequiredService <TreeAnalyser>();
                    var jsonTreeWriter = new JsonTreeWriter(null, dataFiles.Destination.FullName);
                    var trees          = await jsonTreeWriter.ReadAllAsync();

                    var treeStatistics      = treeAnalyser.GenerateStatistics(trees);
                    var consoleTreeReporter = serviceProvider.GetRequiredService <ConsoleTreeReporter>();

                    consoleTreeReporter.OutputToConsole(treeStatistics);
                }
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex, "Unable to start application.");
                Console.WriteLine("Unable to start application.");
            }

            logger.LogInformation("Complete");
            Console.WriteLine("Press a key to exit.");
            Console.ReadKey();
        }
Exemplo n.º 10
0
        public async Task Date_breakdown_is_correct()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, @"Data\\Processed tree.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.Equal(193, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.Empty).Count);
            Assert.Equal(115, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.MonthIsAmbiguous).Count);
            Assert.Equal(0, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.NotSet).Count);
            Assert.Equal(0, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.NotValid).Count);
            Assert.Equal(256, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.OK).Count);
            Assert.Equal(0, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.OnlyMonthIsPresent).Count);
            Assert.Equal(0, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.ThreePartsWithoutYear).Count);
            Assert.Equal(0, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.TooManyDateParts).Count);
            Assert.Equal(0, treeStatistics.DateCountsByStatus.Single(d => d.Status == DateQualityStatus.YearInMiddle).Count);
        }
Exemplo n.º 11
0
        public async Task Location_breakdown_is_correct()
        {
            var jsonTreeWriter = new JsonTreeWriter(null, @"Data\\Processed tree.json");
            var trees          = await jsonTreeWriter.ReadAllAsync();

            var treeStatistics = treeAnalyser.GenerateStatistics(trees);

            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.AllNumeric).Count);
            Assert.Equal(330, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.Geocoded).Count);
            Assert.Equal(134, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.KnownErroneous).Count);
            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.RequiresGeocoding).Count);
            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.RequiresLookup).Count);
            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.RequiresUserIntervention).Count);
            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.SeemsToBeADate).Count);
            Assert.Equal(100, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.SkippedAsEmpty).Count);
            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.TemporaryGeocodeError).Count);
            Assert.Equal(0, treeStatistics.LocationCountsByStatus.Single(d => d.Status == Models.SawmillStatus.ZeroResults).Count);
        }