public void TestExecuteFieldDoesNotExist()
        {
            var locator = new Mock<IElementLocator>(MockBehavior.Strict);
            locator.Setup(p => p.GetElement("doesnotexist")).Throws(new ElementExecuteException("Cannot find item"));

            var buttonClickAction = new ValidateElementEnabledAction
                                        {
                                            ElementLocator = locator.Object
                                        };

            var context = new ValidationCheckContext("doesnotexist", true);

            ExceptionHelper.SetupForException<ElementExecuteException>(
                () => buttonClickAction.Execute(context), e => locator.VerifyAll());
        }
        public void TestExecuteWhenElementShouldBeEnabledAndIsReturnsSuccess()
        {
            var propData = new Mock<IPropertyData>(MockBehavior.Strict);
            propData.Setup(p => p.CheckElementEnabled()).Returns(true);

            var locator = new Mock<IElementLocator>(MockBehavior.Strict);
            locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object);

            var buttonClickAction = new ValidateElementEnabledAction
                                        {
                                            ElementLocator = locator.Object
                                        };

            var context = new ValidationCheckContext("myproperty", true);
            var result = buttonClickAction.Execute(context);

            Assert.AreEqual(true, result.Success);

            locator.VerifyAll();
            propData.VerifyAll();
        }
        public void TestExecuteWhenElementShouldBeEnabledAndIsNotEnabledReturnsFailure()
        {
            var propData = new Mock<IPropertyData>(MockBehavior.Strict);
            propData.SetupGet(p => p.Name).Returns("MyProperty");
            propData.Setup(p => p.CheckElementEnabled()).Returns(false);

            var locator = new Mock<IElementLocator>(MockBehavior.Strict);
            locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object);

            var buttonClickAction = new ValidateElementEnabledAction
            {
                ElementLocator = locator.Object
            };

            var context = new ValidationCheckContext("myproperty", true);
            var result = buttonClickAction.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.AreEqual("Element 'MyProperty' is not enabled on the page and should be enabled.", result.Exception.Message);

            locator.VerifyAll();
            propData.VerifyAll();
        }
        public void TestGetActionName()
        {
            var buttonClickAction = new ValidateElementEnabledAction();

            Assert.AreEqual("ValidateElementEnabledAction", buttonClickAction.Name);
        }