public void TestGetItemAndSetTokenSuccess()
        {
            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            tokenManager.Setup(t => t.SetToken("mytoken", "Hello!"));

            var propData = new Mock <IPropertyData>(MockBehavior.Strict);

            propData.Setup(p => p.GetCurrentValue()).Returns("Hello!");

            var locator = new Mock <IElementLocator>(MockBehavior.Strict);

            locator.Setup(p => p.GetElement("doesnotexist")).Returns(propData.Object);

            var getItemAction = new SetTokenFromValueAction(tokenManager.Object)
            {
                ElementLocator = locator.Object
            };

            var context = new SetTokenFromValueAction.TokenFieldContext("doesnotexist", "mytoken");
            var result  = getItemAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreEqual("Hello!", result.Result);

            locator.VerifyAll();
            propData.VerifyAll();
            tokenManager.VerifyAll();
        }
        public void TestExecuteWhenContextTypeIsInvalidThenAnExceptionIsThrown()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            var locator = new Mock<IElementLocator>(MockBehavior.Strict);
            
            var getItemAction = new SetTokenFromValueAction(tokenManager.Object)
            {
                ElementLocator = locator.Object
            };

            var context = new ActionContext("doesnotexist");
            ExceptionHelper.SetupForException<InvalidOperationException>(
                () => getItemAction.Execute(context),
                e =>
                {
                    StringAssert.Contains(e.Message, "TokenFieldContext");

                    locator.VerifyAll();
                    tokenManager.VerifyAll();
                });
        }
        public void TestExecuteWhenFieldDoesNotExistThenExceptionIsThrown()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);

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

            var getItemAction = new SetTokenFromValueAction(tokenManager.Object)
                                        {
                                            ElementLocator = locator.Object
                                        };

            var context = new SetTokenFromValueAction.TokenFieldContext("doesnotexist", "mytoken");
            ExceptionHelper.SetupForException<ElementExecuteException>(
                () => getItemAction.Execute(context),
                e =>
                    {
                        locator.VerifyAll();
                        tokenManager.VerifyAll();
                    });
        }
        public void TestExecuteWhenContextTypeIsInvalidThenAnExceptionIsThrown()
        {
            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);
            var locator      = new Mock <IElementLocator>(MockBehavior.Strict);

            var getItemAction = new SetTokenFromValueAction(tokenManager.Object)
            {
                ElementLocator = locator.Object
            };

            var context = new ActionContext("doesnotexist");

            ExceptionHelper.SetupForException <InvalidOperationException>(
                () => getItemAction.Execute(context),
                e =>
            {
                StringAssert.Contains(e.Message, "TokenFieldContext");

                locator.VerifyAll();
                tokenManager.VerifyAll();
            });
        }
        public void TestExecuteWhenFieldDoesNotExistThenExceptionIsThrown()
        {
            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            var locator = new Mock <IElementLocator>(MockBehavior.Strict);

            locator.Setup(p => p.GetElement("doesnotexist")).Throws(new ElementExecuteException("Cannot find item"));

            var getItemAction = new SetTokenFromValueAction(tokenManager.Object)
            {
                ElementLocator = locator.Object
            };

            var context = new SetTokenFromValueAction.TokenFieldContext("doesnotexist", "mytoken");

            ExceptionHelper.SetupForException <ElementExecuteException>(
                () => getItemAction.Execute(context),
                e =>
            {
                locator.VerifyAll();
                tokenManager.VerifyAll();
            });
        }
        public void TestGetItemAndSetTokenSuccess()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            tokenManager.Setup(t => t.SetToken("mytoken", "Hello!"));

            var propData = new Mock<IPropertyData>(MockBehavior.Strict);
            propData.Setup(p => p.GetCurrentValue()).Returns("Hello!");

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

            var getItemAction = new SetTokenFromValueAction(tokenManager.Object)
                                        {
                                            ElementLocator = locator.Object
                                        };

            var context = new SetTokenFromValueAction.TokenFieldContext("doesnotexist", "mytoken");
            var result = getItemAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreEqual("Hello!", result.Result);

            locator.VerifyAll();
            propData.VerifyAll();
            tokenManager.VerifyAll();
        }