Exemplo n.º 1
0
        public void TestExecuteWhenContextIsCorrectFillsThePropertyData()
        {
            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            tokenManager.Setup(t => t.SetToken("some data")).Returns("translated data");

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

            propData.Setup(p => p.FillData("translated data"));

            // ReSharper disable once RedundantAssignment
            var property = propData.Object;

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

            locator.Setup(p => p.TryGetElement("myitem", out property)).Returns(true);

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

            var context = new EnterDataAction.EnterDataContext("myitem", "some data");
            var result  = getItemAction.Execute(context);

            Assert.AreEqual(true, result.Success);

            locator.VerifyAll();
            propData.VerifyAll();
            tokenManager.VerifyAll();
        }
Exemplo n.º 2
0
        public void TestExecuteWhenFieldDoesNotExistThenExceptionIsThrown()
        {
            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);
            var locator      = new Mock <IElementLocator>(MockBehavior.Strict);

            // ReSharper disable once RedundantAssignment
            IPropertyData property = null;

            locator.Setup(p => p.TryGetElement("doesnotexist", out property)).Returns(false);
            locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item"));

            var enterDataAction = new EnterDataAction(tokenManager.Object)
            {
                ElementLocator = locator.Object
            };

            var context = new EnterDataAction.EnterDataContext("doesnotexist", "some value");

            ExceptionHelper.SetupForException <ElementExecuteException>(
                () => enterDataAction.Execute(context),
                e =>
            {
                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 enterDataAction = new EnterDataAction(tokenManager.Object)
            {
                                        ElementLocator = locator.Object
                                    };

            var context = new EnterDataAction.EnterDataContext("doesnotexist", "some value");
            ExceptionHelper.SetupForException<ElementExecuteException>(
                () => enterDataAction.Execute(context),
                e =>
                    {
                        locator.VerifyAll();
                        tokenManager.VerifyAll();
                    });
        }
Exemplo n.º 4
0
        public void TestExecuteWhenContextTypeIsInvalidThenAnExceptionIsThrown()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            var locator = new Mock<IElementLocator>(MockBehavior.Strict);

            var enterDataAction = new EnterDataAction(tokenManager.Object)
            {
                                        ElementLocator = locator.Object
                                    };

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

                        locator.VerifyAll();
                        tokenManager.VerifyAll();
                    });
        }
Exemplo n.º 5
0
        public void TestExecuteWhenContextTypeIsInvalidThenAnExceptionIsThrown()
        {
            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);
            var locator      = new Mock <IElementLocator>(MockBehavior.Strict);

            var enterDataAction = new EnterDataAction(tokenManager.Object)
            {
                ElementLocator = locator.Object
            };

            var context = new ActionContext("doesnotexist");

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

                locator.VerifyAll();
                tokenManager.VerifyAll();
            });
        }
Exemplo n.º 6
0
        public void TestExecuteWhenFieldDoesNotExistThenExceptionIsThrown()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            var locator = new Mock<IElementLocator>(MockBehavior.Strict);

            // ReSharper disable once RedundantAssignment
            IPropertyData property = null;
            locator.Setup(p => p.TryGetElement("doesnotexist", out property)).Returns(false);
            locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item"));

            var enterDataAction = new EnterDataAction(tokenManager.Object)
            {
                                        ElementLocator = locator.Object
                                    };

            var context = new EnterDataAction.EnterDataContext("doesnotexist", "some value");
            ExceptionHelper.SetupForException<ElementExecuteException>(
                () => enterDataAction.Execute(context),
                e =>
                    {
                        locator.VerifyAll();
                        tokenManager.VerifyAll();
                    });
        }
Exemplo n.º 7
0
        public void TestExecuteWhenContextIsCorrectFillsThePropertyData()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            tokenManager.Setup(t => t.SetToken("some data")).Returns("translated data");

            var propData = new Mock<IPropertyData>(MockBehavior.Strict);
            propData.Setup(p => p.FillData("translated data"));

            // ReSharper disable once RedundantAssignment
            var property = propData.Object;

            var locator = new Mock<IElementLocator>(MockBehavior.Strict);
            locator.Setup(p => p.TryGetElement("myitem", out property)).Returns(true);

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

            var context = new EnterDataAction.EnterDataContext("myitem", "some data");
            var result = getItemAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            
            locator.VerifyAll();
            propData.VerifyAll();
            tokenManager.VerifyAll();
        }
        public void TestExecuteWhenContextIsCorrectFillsThePropertyData()
        {
            var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict);
            tokenManager.Setup(t => t.SetToken("some data")).Returns("translated data");

            var propData = new Mock<IPropertyData>(MockBehavior.Strict);
            propData.Setup(p => p.FillData("translated data"));

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

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

            var context = new EnterDataAction.EnterDataContext("doesnotexist", "some data");
            var result = getItemAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            
            locator.VerifyAll();
            propData.VerifyAll();
            tokenManager.VerifyAll();
        }