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 void When_Both_Conditions_Match_Alarm_Should_Be_Fired() { var result = new PriceMeScrapperResults { Price = 500, Title = "gopro" }; var alert = new PriceOfProductBelowAlertConfiguration("GoPro", 500); Assert.True(alert.Fired(result)); }
public void When_Title_Dont_Matches_But_Price_Is_Above_Condition_Alarm_Should_Be_False() { var result = new PriceMeScrapperResults { Price = 510, Title = "gepro" }; var alert = new PriceOfProductBelowAlertConfiguration("GoPro", 500); Assert.False(alert.Fired(result)); }