public static async Task <ScrapperRunnerResults> RunScrappers(IConfiguration configuration, ILogger logger) { var runner = new ScrapperRunner(logger); var priceMeAlertConfig = new PriceOfProductBelowAlertConfiguration(configuration); var scrapperRunnerConfig = new ScrapperRunnerConfiguration(priceMeAlertConfig, new TwilioSmsAction((result) => TransformPriceMeResultsToSms(result), configuration, logger)); var priceMeScrapper = new PriceMeScrapper(configuration); runner.AddConfigurations(priceMeScrapper, scrapperRunnerConfig); logger.Log("Running scrappers..."); var results = await runner.RunAllConfigurations(); logger.Log("Scrappers ran successfully, showing results..."); foreach (var result in results.GetResults()) { logger.Log($"Match result for Scrapper: {result.Key}:"); foreach (var config in result.Value) { logger.Log($"for the config({config.Key.GetType().Name}): {config.Key.GetAlertDescription()} with value: {config.Value}."); } } return(results); }
public async void True_Result_With_Action_To_Execute_Should_Be_Fired() { var runner = new ScrapperRunner(Mock.Of <ILogger>()); var result = new TestScrapperResults() { Test = true }; var scrapper = new TestScrapper(result); var config = new TestAlertConfig(true); var mockAction = new Mock <IScrapperAction>(); mockAction.Setup(o => o.RunAction(result)).Verifiable(); var runConfig = new ScrapperRunnerConfiguration(config, mockAction.Object); runner.AddConfigurations(scrapper, runConfig); var results = await runner.RunAllConfigurations(); var testScrapperRunResults = results.GetResultsForScrapper <TestScrapper>(); var firstResult = testScrapperRunResults.First(); Assert.Equal(1, testScrapperRunResults.Count()); mockAction.VerifyAll(); Assert.True(firstResult.Value); }