public void TestGivenNavigateToPageStepWithArguments()
        {
            var testPage = new Mock<IPage>();

            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);
            pipelineService.Setup(p => p.PerformAction<PageNavigationAction>(
                null,
                It.Is<PageNavigationAction.PageNavigationActionContext>(c => c.PropertyName == "mypage" && 
                    c.PageAction == PageNavigationAction.PageAction.NavigateToPage && 
                    c.PageArguments != null && c.PageArguments.Count == 2)))
                .Returns(ActionResult.Successful(testPage.Object));

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.SetValue(It.IsAny<IPage>(), PageStepBase.CurrentPageKey));

            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            tokenManager.Setup(t => t.GetToken(It.IsAny<string>())).Returns<string>(s => s);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            var table = new Table("Id", "Part");
            table.AddRow("1", "A");

            steps.GivenNavigateToPageWithArgumentsStep("mypage", table);

            scenarioContext.VerifyAll();
            pipelineService.VerifyAll();
        }
        public void TestGivenNavigateToPageStepWithArguments()
        {
            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);

            var testPage = new Mock<IPage>();
            

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.GoToPage(typeof(TestBase), It.Is<IDictionary<string, string>>(d => d.Count == 2))).Returns(testPage.Object);


            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("mypage")).Returns(typeof(TestBase));

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.SetValue(It.IsAny<IPage>(), PageStepBase.CurrentPageKey));

            var steps = new PageNavigationSteps(browser.Object, pageMapper.Object, scenarioContext.Object, pipelineService.Object);

            var table = new Table("Id", "Part");
            table.AddRow("1", "A");

            steps.GivenNavigateToPageWithArgumentsStep("mypage", table);

            browser.VerifyAll();
            pageMapper.VerifyAll();
            scenarioContext.VerifyAll();
            
        }
        public void TestGivenEnsureOnPageStep()
        {
            var testPage = new Mock <IPage>();

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);

            pipelineService.Setup(p => p.PerformAction <PageNavigationAction>(
                                      null,
                                      It.Is <PageNavigationAction.PageNavigationActionContext>(c => c.PropertyName == "mypage" && c.PageAction == PageNavigationAction.PageAction.EnsureOnPage && c.PageArguments == null)))
            .Returns(ActionResult.Successful(testPage.Object));

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.SetValue(testPage.Object, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            steps.GivenEnsureOnPageStep("mypage");

            pipelineService.VerifyAll();
            scenarioContext.VerifyAll();
            testPage.VerifyAll();
        }
        public void TestGivenNavigateToPageStep()
        {
            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);

            var testPage = new Mock<IPage>();
            

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


            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("mypage")).Returns(typeof(TestBase));

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.SetValue(It.IsAny<IPage>(), PageStepBase.CurrentPageKey));

            var steps = new PageNavigationSteps(browser.Object, pageMapper.Object, scenarioContext.Object, pipelineService.Object);

            steps.GivenNavigateToPageStep("mypage");

            browser.VerifyAll();
            pageMapper.VerifyAll();
            scenarioContext.VerifyAll();
            
            pipelineService.VerifyAll();
        }
        public void TestGivenNavigateToPageStepWithArguments()
        {
            var testPage = new Mock <IPage>();

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);

            pipelineService.Setup(p => p.PerformAction <PageNavigationAction>(
                                      null,
                                      It.Is <PageNavigationAction.PageNavigationActionContext>(c => c.PropertyName == "mypage" &&
                                                                                               c.PageAction == PageNavigationAction.PageAction.NavigateToPage &&
                                                                                               c.PageArguments != null && c.PageArguments.Count == 2)))
            .Returns(ActionResult.Successful(testPage.Object));

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.SetValue(It.IsAny <IPage>(), PageStepBase.CurrentPageKey));

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            tokenManager.Setup(t => t.GetToken(It.IsAny <string>())).Returns <string>(s => s);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            var table = new Table("Id", "Part");

            table.AddRow("1", "A");

            steps.GivenNavigateToPageWithArgumentsStep("mypage", table);

            scenarioContext.VerifyAll();
            pipelineService.VerifyAll();
        }
        public void TestWaitForPageStepWithTimeoutWhenTimeoutIsZeroSetsTimeoutToNull()
        {
            var testPage = new Mock <IPage>();

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);

            pipelineService.Setup(p => p.PerformAction <WaitForPageAction>(
                                      null,
                                      It.Is <WaitForPageAction.WaitForPageActionContext>(c => c.PropertyName == "mypage" && c.Timeout == null)))
            .Returns(ActionResult.Successful(testPage.Object));

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

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.SetValue(testPage.Object, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            steps.WaitForPageStepWithTimeout(0, "mypage");

            browser.VerifyAll();
            pageMapper.VerifyAll();
            scenarioContext.VerifyAll();
            testPage.VerifyAll();
        }
        public void TestWaitForPageStepWhenFailsClearsPageContext()
        {
            var testPage = new Mock <IPage>();

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);

            pipelineService.Setup(p => p.PerformAction <WaitForPageAction>(
                                      null,
                                      It.Is <WaitForPageAction.WaitForPageActionContext>(c => c.PropertyName == "mypage" && c.Timeout == null)))
            .Returns(ActionResult.Failure(new PageNavigationException("Navigation Failed")));

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

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.SetValue <IPage>(null, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            ExceptionHelper.SetupForException <PageNavigationException>(() => steps.WaitForPageStep("mypage"),
                                                                        e =>
            {
                browser.VerifyAll();
                pageMapper.VerifyAll();
                scenarioContext.VerifyAll();
                testPage.VerifyAll();
            });
        }
        public void TestGivenEnsureOnDialogStep()
        {
            var page     = new Mock <IPage>();
            var listItem = new Mock <IPage>();

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);

            pipelineService.Setup(p => p.PerformAction <GetElementAsPageAction>(
                                      page.Object, It.Is <ActionContext>(a => a.PropertyName == "myproperty")))
            .Returns(ActionResult.Successful(listItem.Object));


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


            var pageMapper      = new Mock <IPageMapper>(MockBehavior.Strict);
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetValue <IPage>(PageStepBase.CurrentPageKey)).Returns(page.Object);
            scenarioContext.Setup(s => s.SetValue(listItem.Object, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            steps.GivenEnsureOnDialogStep("my property");

            browser.VerifyAll();
            pageMapper.VerifyAll();
            scenarioContext.VerifyAll();
        }
        public void TestGivenNavigateToPageStep()
        {
            var testPage = new Mock<IPage>();

            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);
            pipelineService.Setup(p => p.PerformAction<PageNavigationAction>(
                null,
                It.Is<PageNavigationAction.PageNavigationActionContext>(c => c.PropertyName == "mypage" && c.PageAction == PageNavigationAction.PageAction.NavigateToPage && c.PageArguments == null)))
                .Returns(ActionResult.Successful(testPage.Object));

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.SetValue(testPage.Object, PageStepBase.CurrentPageKey));
            
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            steps.GivenNavigateToPageStep("mypage");

            pipelineService.VerifyAll();
            scenarioContext.VerifyAll();
            testPage.VerifyAll();
        }
        public void TestWaitForPageStepWithTimeoutWhenTimeoutIsZeroSetsTimeoutToNull()
        {
            var testPage = new Mock<IPage>();

            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);
            pipelineService.Setup(p => p.PerformAction<WaitForPageAction>(
                null,
                It.Is<WaitForPageAction.WaitForPageActionContext>(c => c.PropertyName == "mypage" && c.Timeout == null)))
                .Returns(ActionResult.Successful(testPage.Object));

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

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.SetValue(testPage.Object, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            steps.WaitForPageStepWithTimeout(0, "mypage");

            browser.VerifyAll();
            pageMapper.VerifyAll();
            scenarioContext.VerifyAll();
            testPage.VerifyAll();
        }
        public void TestWaitForPageStepWhenFailsClearsPageContext()
        {
            var testPage = new Mock<IPage>();

            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);
            pipelineService.Setup(p => p.PerformAction<WaitForPageAction>(
                null,
                It.Is<WaitForPageAction.WaitForPageActionContext>(c => c.PropertyName == "mypage" && c.Timeout == null)))
                .Returns(ActionResult.Failure(new PageNavigationException("Navigation Failed")));

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

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.SetValue<IPage>(null, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            ExceptionHelper.SetupForException<PageNavigationException>(() => steps.WaitForPageStep("mypage"),
                e =>
                    {
                        browser.VerifyAll();
                        pageMapper.VerifyAll();
                        scenarioContext.VerifyAll();
                        testPage.VerifyAll();
                    });
        }
        public void TestGivenEnsureOnDialogStep()
        {
            var page = new Mock<IPage>();
            var listItem = new Mock<IPage>();

            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);
            pipelineService.Setup(p => p.PerformAction<GetElementAsPageAction>(
                page.Object, It.Is<ActionContext>(a => a.PropertyName == "myproperty")))
                           .Returns(ActionResult.Successful(listItem.Object));

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


            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);
            scenarioContext.Setup(s => s.GetValue<IPage>(PageStepBase.CurrentPageKey)).Returns(page.Object);
            scenarioContext.Setup(s => s.SetValue(listItem.Object, PageStepBase.CurrentPageKey));

            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(scenarioContext.Object, pipelineService.Object, tokenManager.Object);

            steps.GivenEnsureOnDialogStep("my property");

            browser.VerifyAll();
            pageMapper.VerifyAll();
            scenarioContext.VerifyAll();
            
        }
        public void TestGivenNavigateToPageStepTypeNotFound()
        {
            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);

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

            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("mypage")).Returns((Type)null);

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(browser.Object, pageMapper.Object, scenarioContext.Object, pipelineService.Object);

            try
            {
                steps.GivenNavigateToPageStep("mypage");
            }
            catch (PageNavigationException ex)
            {
                StringAssert.Contains(ex.Message, "mypage");

                browser.VerifyAll();
                pageMapper.VerifyAll();
                scenarioContext.VerifyAll();
                

                throw;
            }
        }
        public void TestGivenEnsureOnPageStepPageNotFound()
        {
            var pipelineService = new Mock<IActionPipelineService>(MockBehavior.Strict);

            
            var testPage = new Mock<IPage>();

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.Page(typeof(TestBase))).Returns(testPage.Object);
            browser.Setup(b => b.EnsureOnPage(testPage.Object)).Throws(new PageNavigationException("Page Not found"));


            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("mypage")).Returns(typeof(TestBase));

            var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict);

            var steps = new PageNavigationSteps(browser.Object, pageMapper.Object, scenarioContext.Object, pipelineService.Object);

            try
            {
                steps.GivenEnsureOnPageStep("mypage");
            }
            catch (PageNavigationException)
            {
                browser.VerifyAll();
                pageMapper.VerifyAll();
                scenarioContext.VerifyAll();
                

                throw;
            }
        }