예제 #1
0
        public void GetLocationFinder()
        {
            string outputFile = OutputFile();

            ILocationFinder locationFinder = _locationFinderFactory.GetLocationFinder(_inputFile, outputFile, _locationsFile);

            Assert.Equal(locationFinder, _locationFinderFactory.GetLocationFinder(_inputFile, outputFile, _locationsFile));
        }
예제 #2
0
        public void AddFileMapServices()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddFileMapServices();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            string          outputFile = OutputFile();
            ILocationFinder finder1, finder2;

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                ILocationFinderFactory singletonFactory = scope.ServiceProvider.GetRequiredService <ILocationFinderFactory>();
                finder1 = singletonFactory.GetLocationFinder(_inputFile, outputFile, _locationsFile);
            }

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                ILocationFinderFactory singletonFactory = scope.ServiceProvider.GetRequiredService <ILocationFinderFactory>();
                finder2 = singletonFactory.GetLocationFinder(_inputFile, outputFile, _locationsFile);
            }

            Assert.Equal(finder1, finder2);
        }
예제 #3
0
        private static async Task MapLocations(string inputFile, string outputFile, string locationsFile)
        {
            Stopwatch       watch          = Stopwatch.StartNew();
            ILocationFinder locationFinder = _locationFinderFactory.GetLocationFinder(inputFile, outputFile, locationsFile);

            Console.WriteLine($"Mapping from {inputFile} to {outputFile} using {locationsFile}");

            await locationFinder.MapLocations().ContinueWith((task) =>
            {
                watch.Stop();
                ConsoleColor originalColor = Console.ForegroundColor;
                if (task.IsCompletedSuccessfully)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine($"Mapping successfully completed");
                }
                else
                {
                    Console.WriteLine($"Mapping completed with errors:");
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine(task.Exception.Message);
                }
                Console.ForegroundColor = originalColor;
                Console.WriteLine($"{watch.ElapsedMilliseconds}ms elapsed");
            });
        }
예제 #4
0
        public async Task MapLocations()
        {
            string          outputFile = OutputFile();
            ILocationFinder finder     = _locationFinderFactory.GetLocationFinder(_inputFile, outputFile, _locationsFile);

            await finder.MapLocations();

            using (StreamReader expectedFileStreamReader = new StreamReader(_expectedOutputFile))
                using (StreamReader outputFileStreamReader = new StreamReader(outputFile))
                {
                    string expectedLine;
                    while ((expectedLine = expectedFileStreamReader.ReadLine()) != null)
                    {
                        Assert.Equal(expectedLine, outputFileStreamReader.ReadLine());
                    }

                    Assert.Null(outputFileStreamReader.ReadLine());
                }
        }