public void TestGetElementAsPageWhenPageIsNotAListReturnsAFailure() { var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(false); propData.SetupGet(p => p.Name).Returns("MyProperty"); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new GetListItemByIndexAction { ElementLocator = locator.Object }; var context = new GetListItemByIndexAction.ListItemByIndexContext("myproperty", 1); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); StringAssert.Contains(result.Exception.Message, "MyProperty"); locator.VerifyAll(); propData.VerifyAll(); }
public void TestGetElementAsPageWhenPageIsNullReturnsAFailure() { var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(true); propData.SetupGet(p => p.Name).Returns("MyProperty"); propData.Setup(p => p.GetItemAtIndex(0)).Returns((IPage)null); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new GetListItemByIndexAction { ElementLocator = locator.Object }; var context = new GetListItemByIndexAction.ListItemByIndexContext("myproperty", 1); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); Assert.AreEqual("Could not find item 1 on list 'MyProperty'", result.Exception.Message); locator.VerifyAll(); propData.VerifyAll(); }
public void TestGetElementAsPageSuccess() { var page = new Mock <IPage>(MockBehavior.Strict); var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(true); propData.Setup(p => p.GetItemAtIndex(0)).Returns(page.Object); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new GetListItemByIndexAction { ElementLocator = locator.Object }; var context = new GetListItemByIndexAction.ListItemByIndexContext("myproperty", 1); var result = buttonClickAction.Execute(context); Assert.AreEqual(true, result.Success); Assert.AreSame(page.Object, result.Result); locator.VerifyAll(); propData.VerifyAll(); }
public void TestGetElementAsPageFieldDoesNotExist() { var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var buttonClickAction = new GetListItemByIndexAction { ElementLocator = locator.Object }; var context = new GetListItemByIndexAction.ListItemByIndexContext("doesnotexist", 1); ExceptionHelper.SetupForException<ElementExecuteException>( () => buttonClickAction.Execute(context), e => locator.VerifyAll()); }
public void TestGetElementAsPageFieldDoesNotExist() { var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var buttonClickAction = new GetListItemByIndexAction { ElementLocator = locator.Object }; var context = new GetListItemByIndexAction.ListItemByIndexContext("doesnotexist", 1); ExceptionHelper.SetupForException <ElementExecuteException>( () => buttonClickAction.Execute(context), e => locator.VerifyAll()); }
public void TestGetElementAsPageSuccess() { var page = new Mock<IPage>(MockBehavior.Strict); var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(true); propData.Setup(p => p.GetItemAtIndex(0)).Returns(page.Object); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new GetListItemByIndexAction { ElementLocator = locator.Object }; var context = new GetListItemByIndexAction.ListItemByIndexContext("myproperty", 1); var result = buttonClickAction.Execute(context); Assert.AreEqual(true, result.Success); Assert.AreSame(page.Object, result.Result); locator.VerifyAll(); propData.VerifyAll(); }