Esempio n. 1
0
        private async Task CheckSurveyNews(SurveyNewsFeed feed, SurveyNewsPolicy policy,
                                           DateTime lastChecked, bool forceCheck, string expectedNavigatedUrl, DateTime?expectedLastChecked)
        {
            string navigatedUrl = null;

            // Create the test objects
            var browser = Substitute.For <IWebBrowserServices>();

            browser.When(x => x.OpenBrowser(Arg.Any <WebBrowserRole>(), Arg.Any <string>(), Arg.Any <bool>())).Do(x => {
                ((WebBrowserRole)x.Args()[0]).Should().Be(WebBrowserRole.News);
                navigatedUrl = (string)x.Args()[1];
            });

            var options    = new MockSurveyNewsOptions(policy, lastChecked);
            var feedClient = new MockSurveyNewsFeedClient(feed);

            // Invoke the real survey/news service
            var service = new SurveyNewsService(feedClient, options, browser, Substitute.For <ICoreShell>());
            await service.CheckSurveyNewsAsync(forceCheck);

            // Check that we navigated to the right url (or didn't navigate at all)
            navigatedUrl.Should().Be(expectedNavigatedUrl);

            // Check that the last checked date has been updated (or not updated at all)
            if (expectedLastChecked.HasValue)
            {
                var delta = options.SurveyNewsLastCheck - expectedLastChecked.Value;
                delta.Duration().Should().BeLessOrEqualTo(TimeSpan.FromSeconds(5));
            }
            else
            {
                options.SurveyNewsLastCheck.Should().Be(lastChecked);
            }
        }
Esempio n. 2
0
        private async Task CheckSurveyNews(SurveyNewsFeed feed, SurveyNewsPolicy policy,
                                           DateTime lastChecked, bool forceCheck, string expectedNavigatedUrl, DateTime?expectedLastChecked)
        {
            // Create the test objects
            MockSurveyNewsBrowserLauncher browser = new MockSurveyNewsBrowserLauncher();
            var options    = new MockSurveyNewsOptions(policy, lastChecked);
            var feedClient = new MockSurveyNewsFeedClient(feed);

            // Invoke the real survey/news service
            var service = new SurveyNewsService(feedClient, options, browser);
            await service.CheckSurveyNewsAsync(forceCheck);

            // Check that we navigated to the right url (or didn't navigate at all)
            browser.NavigatedUrl.Should().Be(expectedNavigatedUrl);

            // Check that the last checked date has been updated (or not updated at all)
            if (expectedLastChecked.HasValue)
            {
                var delta = options.SurveyNewsLastCheck - expectedLastChecked.Value;
                delta.Duration().Should().BeLessOrEqualTo(TimeSpan.FromSeconds(5));
            }
            else
            {
                options.SurveyNewsLastCheck.Should().Be(lastChecked);
            }
        }