Exemple #1
0
        static async Task Main(string[] args)
        {
            CommandsInterpreter interpreter = new CommandsInterpreter();
            Commands            commands    = interpreter.ParseCommand(args);

            if (!commands.Address.IsAbsoluteUri)
            {
                Console.WriteLine("The uri format is not correct. Must be of form http(s)://www.domain.com");
                Console.WriteLine("Nothing was Done!");
                return;
            }

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IPersistenceService, PersistenceService>()
                                  .AddSingleton(commands)
                                  .AddSingleton <ICrawlerService, CrawlerService>()
                                  .BuildServiceProvider();

            ICrawlerService crawlerService = serviceProvider.GetService <ICrawlerService>();

            Console.WriteLine($"Downloading from {commands.Address.Host}...");

            await crawlerService.GetUrlContents(commands.Address);

            Console.WriteLine("Done!");
            Console.ReadLine();
        }
        public void CommandsInterpreter_ParseCommand_ParseAllCommands_Test()
        {
            //Arrange
            CommandsInterpreter interpreter      = new CommandsInterpreter();
            Commands            expectedCommands = _commands;
            string stringCommand = "--allowExternal --address:http://www.eloquentix.com/ --destination:C:\\Users\\dan.diaconu\\source\\repos\\WebCrawler\\WebCrawlerTests\\bin\\Debug --depth:2";

            string[] actualCommand = stringCommand.Split(' ');

            //Act
            Commands result = interpreter.ParseCommand(actualCommand);

            //Assert
            Assert.AreEqual(expectedCommands.AllowExternal, result.AllowExternal);
            Assert.AreEqual(expectedCommands.Destination, result.Destination);
            Assert.AreEqual(expectedCommands.Address, result.Address);
            Assert.AreEqual(expectedCommands.Depth, result.Depth);
        }