public void TestExecuteWithNavigateAndCorrectParametersAndArgumentsReturnsSuccessful()
        {
            var testPage   = new Mock <IPage>();
            var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict);

            pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns(typeof(TestBase));

            var logger = new Mock <ILogger>();

            var arguments = new Dictionary <string, string> {
                { "MyKey", "value1" }
            };

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

            browser.Setup(b => b.GoToPage(typeof(TestBase), arguments)).Returns(testPage.Object);


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

            var context = new PageNavigationAction.PageNavigationActionContext("MyPage", PageNavigationAction.PageAction.NavigateToPage, arguments);

            var result = navigationAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(testPage.Object, result.Result);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWithEnsureOnPageAndCorrectParametersReturnsSuccessful()
        {
            var testPage   = new Mock <IPage>();
            var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict);

            pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns(typeof(TestBase));

            var logger = new Mock <ILogger>();

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

            browser.Setup(b => b.Page(typeof(TestBase))).Returns(testPage.Object);
            browser.Setup(b => b.EnsureOnPage(testPage.Object));

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

            var context = new PageNavigationAction.PageNavigationActionContext("MyPage", PageNavigationAction.PageAction.EnsureOnPage);

            var result = navigationAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(testPage.Object, result.Result);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWhenFieldDoesNotExistThrowsAnException()
        {
            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 context = new PageNavigationAction.PageNavigationActionContext("doesnotexist", PageNavigationAction.PageAction.EnsureOnPage);

            var result = navigationAction.Execute(context);
            
            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Cannot locate a page for name: doesnotexist. Check page aliases in the test assembly.", result.Exception.Message);
            
            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWhenFieldDoesNotExistThrowsAnException()
        {
            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 context = new PageNavigationAction.PageNavigationActionContext("doesnotexist", PageNavigationAction.PageAction.EnsureOnPage);

            var result = navigationAction.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Cannot locate a page for name: doesnotexist. Check page aliases in the test assembly.", result.Exception.Message);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
        public void TestExecuteWithNavigateAndCorrectParametersReturnsSuccessful()
        {
            var testPage = new Mock<IPage>();
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns(typeof(TestBase));

            var logger = new Mock<ILogger>();

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.GoToPage(typeof(TestBase), null)).Returns(testPage.Object);


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

            var context = new PageNavigationAction.PageNavigationActionContext("MyPage", PageNavigationAction.PageAction.NavigateToPage);

            var result = navigationAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(testPage.Object, result.Result);

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