Example #1
0
        public void DisplaysSpecialMessageIfWebServerHasSomehowGoneBackInTime()
        {
            // Inject a mock IDateProvider, setting the clock back to 1975
            var dateToSimulate = new DateTime(1975, 1, 1);

            Deleporter.Run(() =>
            {
                var mockDateProvider = new Mock <IDateProvider>();
                mockDateProvider.Setup(x => x.CurrentDate).Returns(dateToSimulate);
                NinjectControllerFactoryUtils.TemporarilyReplaceBinding(mockDateProvider.Object);
            });

            // Now see what it displays
            Driver.Navigate().GoToUrl(DeleporterConfiguration.SiteBaseUrl);
            var dateElement   = Driver.FindElement(By.Id("date"));
            var displayedDate = DateTime.Parse(dateElement.Text);

            Assert.AreEqual(1975, displayedDate.Year);

            var extraInfo = Driver.FindElement(By.Id("extraInfo")).Text;

            Assert.IsTrue(extraInfo.Contains("The world wide web hasn't been invented yet"));

            Console.WriteLine(new WebClient().DownloadString(DeleporterConfiguration.SiteBaseUrl));
        }
Example #2
0
        public void DisplaysSpecialMessageIfWebServerHasSomehowGoneBackInTime()
        {
            // Inject a mock IDateProvider, setting the clock back to 1975
            var dateToSimulate = new DateTime(1975, 1, 1);

            Deleporter.Run(() => {
                var mockDateProvider = new Mock <IDateProvider>();
                mockDateProvider.Setup(x => x.CurrentDate).Returns(dateToSimulate);
                NinjectControllerFactoryUtils.TemporarilyReplaceBinding(mockDateProvider.Object);
            });

            // Now see what it displays
            var html = GetPageHtml("/");

            Assert.AreEqual(1975, ParseSimpleDomElement <DateTime>(html, "date").Year);
            StringAssert.Contains("The world wide web hasn't been invented yet", ParseSimpleDomElement <string>(html, "extraInfo"));
        }