public void TestExecuteWhenActionIsNotNavigationDoesNothing()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            var logger = new Mock<ILogger>();
            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            var action = new Mock<IAction>();

            var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object);
            var context = new ActionContext("doesnotexist");

            cookiePreAction.PerformPreAction(action.Object, context);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWhenFieldDoesNotExistDoesNothing()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("doesnotexist")).Returns((Type)null);

            var logger = new Mock<ILogger>();
            var browser = new Mock<IBrowser>(MockBehavior.Strict);

            var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object);

            var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object);
            var context = new ActionContext("doesnotexist");

            cookiePreAction.PerformPreAction(navigationAction, context);
           
            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWithPageThatDoesNotContainAnAttributeDoesNothing()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("NoAttributePage")).Returns(typeof(NoAttributePage));

            var logger = new Mock<ILogger>();

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            
            var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object);

            var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object);
            var context = new ActionContext("NoAttributePage");

            cookiePreAction.PerformPreAction(navigationAction, context);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWithNavigateAndCorrectParametersAndArgumentsReturnsSuccessful()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("AttributePage")).Returns(typeof(AttributePage));

            var logger = new Mock<ILogger>();

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.AddCookie("TestCookie", "TestValue", "/mydomain", null, "www.mydomain.com", true));

            var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object);

            var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object);
            var context = new ActionContext("AttributePage");

            cookiePreAction.PerformPreAction(navigationAction, context);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWithInvalidDateTimeLogsInfoAndContinues()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("InvalidDateAttributePage")).Returns(typeof(InvalidDateAttributePage));

            var logger = new Mock<ILogger>();
            logger.Setup(l => l.Info("Cannot parse cookie date: {0}", new object[] { "foo" })).Verifiable();

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.AddCookie("TestCookie", "TestValue", "/", null, null, false));

            var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object);

            var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object);
            var context = new ActionContext("InvalidDateAttributePage");

            cookiePreAction.PerformPreAction(navigationAction, context);

            pageMapper.VerifyAll();
            browser.VerifyAll();
            logger.VerifyAll();
        }
        public void TestExecuteWithNumericSlidingDateTimePassesToBrowser()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("SlidingDateAttributePage")).Returns(typeof(SlidingDateAttributePage));

            var logger = new Mock<ILogger>();

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.AddCookie("TestCookie", "TestValue", "/", It.Is<DateTime?>(d => d.Value > DateTime.Now), null, false));

            var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object);

            var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object);
            var context = new ActionContext("SlidingDateAttributePage");

            cookiePreAction.PerformPreAction(navigationAction, context);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }