public void TestExecuteWhenPageIsFoundAndUrlMatchesReturnsSuccess() { var page = new Mock <IPage>(MockBehavior.Strict); var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage)); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object); browser.Setup(b => b.EnsureOnPage(page.Object)); var logger = new Mock <ILogger>(); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1)); var result = action.Execute(context); Assert.AreEqual(true, result.Success); Assert.AreSame(page.Object, result.Result); pageMapper.VerifyAll(); browser.VerifyAll(); page.VerifyAll(); }
public void TestExecuteWhenPageIsFoundAndUrlMatchesReturnsSuccess() { var page = new Mock<IPage>(MockBehavior.Strict); var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage)); var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object); browser.Setup(b => b.EnsureOnPage(page.Object)); var logger = new Mock<ILogger>(); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1)); var result = action.Execute(context); Assert.AreEqual(true, result.Success); Assert.AreSame(page.Object, result.Result); pageMapper.VerifyAll(); browser.VerifyAll(); page.VerifyAll(); }
public void TestExecuteWhenPageIsFoundAndUrlDoesntMatchAfterTimeoutReturnsFailure() { var page = new Mock <IPage>(MockBehavior.Strict); var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage)); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object); browser.Setup(b => b.EnsureOnPage(page.Object)).Throws(new PageNavigationException("Cannot find URL")); var logger = new Mock <ILogger>(); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1)); var result = action.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); Assert.AreEqual("Browser did not resolve to the 'SamplePage' page in 00:00:01", result.Exception.Message); pageMapper.VerifyAll(); browser.VerifyAll(); page.VerifyAll(); }
public void TestExecuteWhenPageIsFoundAndUrlMatchesAfterInitialFailureReturnsSuccess() { var page = new Mock <IPage>(MockBehavior.Strict); var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage)); var count = 0; var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object); browser.Setup(b => b.EnsureOnPage(page.Object)) .Callback(() => { count++; if (count == 1) { throw new PageNavigationException("Cannot find URL"); } }); var logger = new Mock <ILogger>(MockBehavior.Strict); logger.Setup(l => l.Debug("Browser is not on page. Details: {0}", "Cannot find URL")); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1)); var result = action.Execute(context); Assert.AreEqual(true, result.Success); Assert.AreSame(page.Object, result.Result); pageMapper.VerifyAll(); browser.Verify(b => b.EnsureOnPage(page.Object), Times.Exactly(2)); browser.Verify(b => b.Page(typeof(SamplePage)), Times.Exactly(2)); browser.Verify(b => b.IsCreated, Times.Never()); browser.VerifyAll(); page.VerifyAll(); logger.VerifyAll(); }
public void TestExecuteWhenPageDoesNotExistReturnsAFailure() { var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns((Type)null); var browser = new Mock<IBrowser>(MockBehavior.Strict); var logger = new Mock<ILogger>(); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("MyPage", null); var result = action.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); Assert.AreEqual("Cannot locate a page for name: MyPage. Check page aliases in the test assembly.", result.Exception.Message); pageMapper.VerifyAll(); browser.VerifyAll(); }
public void TestExecuteWhenPageDoesNotExistReturnsAFailure() { var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns((Type)null); var browser = new Mock <IBrowser>(MockBehavior.Strict); var logger = new Mock <ILogger>(); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("MyPage", null); var result = action.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); Assert.AreEqual("Cannot locate a page for name: MyPage. Check page aliases in the test assembly.", result.Exception.Message); pageMapper.VerifyAll(); browser.VerifyAll(); }
public void TestExecuteWhenPageIsFoundAndUrlMatchesAfterInitialFailureReturnsSuccess() { var page = new Mock<IPage>(MockBehavior.Strict); var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage)); var count = 0; var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object); browser.Setup(b => b.EnsureOnPage(page.Object)) .Callback(() => { count++; if (count == 1) { throw new PageNavigationException("Cannot find URL"); } }); var logger = new Mock<ILogger>(MockBehavior.Strict); logger.Setup(l => l.Debug("Browser is not on page. Details: {0}", "Cannot find URL")); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1)); var result = action.Execute(context); Assert.AreEqual(true, result.Success); Assert.AreSame(page.Object, result.Result); pageMapper.VerifyAll(); browser.Verify(b => b.EnsureOnPage(page.Object), Times.Exactly(2)); browser.Verify(b => b.Page(typeof(SamplePage)), Times.Once()); browser.VerifyAll(); page.VerifyAll(); logger.VerifyAll(); }
public void TestExecuteWhenPageIsFoundAndUrlDoesntMatchAfterTimeoutReturnsFailure() { var page = new Mock<IPage>(MockBehavior.Strict); var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage)); var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object); browser.Setup(b => b.EnsureOnPage(page.Object)).Throws(new PageNavigationException("Cannot find URL")); var logger = new Mock<ILogger>(); var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object); var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1)); var result = action.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); Assert.AreEqual("Browser did not resolve to the 'SamplePage' page in 00:00:01", result.Exception.Message); pageMapper.VerifyAll(); browser.VerifyAll(); page.VerifyAll(); }