Esempio n. 1
0
 public ScraperService(
     IHackerNewsScraper hackerNewsScraper,
     IOptions <ScraperOptions> scraperOptions)
 {
     _scraperOptions    = scraperOptions?.Value ?? throw new ArgumentNullException(nameof(scraperOptions));
     _hackerNewsScraper = hackerNewsScraper;
 }
Esempio n. 2
0
        static int Main(string[] args)
        {
            // Initialize our hackernews scraper with our IHttp implementation
            scraper = new HackerNewsScraper(new Http());

            // Set up our CLI commands
            var rootCommand = new RootCommand
            {
                // Create option for -p|--posts
                new Option(new[] { "-p", "--posts" }, "How many posts to print. A positive integer <= 100.")
                {
                    Argument = new Argument <int>()
                }
            };

            rootCommand.Description = "Hacker News Scraper Test";

            // Create the handler that will parse the CLI args and call our scraper
            rootCommand.Handler = CommandHandler.Create <int>(async(posts) =>
            {
                if (posts <= 0 || posts > 100)
                {
                    Console.WriteLine("Number of posts should be a positive integer <= 100");
                    return;
                }
                var result = await scraper.GetPostsJson(posts);

                Console.WriteLine(result);
            });

            // Invoke the CLI handler with the args passed in to Main
            return(rootCommand.InvokeAsync(args).Result);
        }
Esempio n. 3
0
        public void Setup()
        {
            _settings  = new HackerNewsSettings();
            _validator = new HackerNewsStoryItemValidator();
            _provider  = new MockHackerNewsDataProvider();
            _parser    = new HackerNewsDataParser(_settings);

            _scraper = new HackerNewsScraper(_settings, _validator, _provider, _parser);
        }
        public void SetUp()
        {
            _fakeHackerNewsServer.ResetMappings();

            _fixture.Register <IHackerNewsHtmlParser>(_fixture.Create <HackerNewsHtmlParser>);
            _fixture.Register <IHackerNewsPostValidator>(_fixture.Create <HackerNewsPostValidator>);

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri($"http://localhost:{_fakeHackerNewsServer.Ports.First()}")
            };

            _fixture.Inject <IHttpClientService>(new HttpClientService(httpClient, null));

            _hackerNewsScraper = _fixture.Create <HackerNewsScraper>();
        }