Esempio n. 1
0
        public void TestGetElementAsPageWhenPageIsNullReturnsAFailure()
        {
            var propData = new Mock <IPropertyData>(MockBehavior.Strict);

            propData.SetupGet(p => p.IsList).Returns(false);
            propData.SetupGet(p => p.Name).Returns("MyProperty");
            propData.Setup(p => p.GetItemAsPage()).Returns((IPage)null);

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

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

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

            var context = new ActionContext("myproperty");
            var result  = buttonClickAction.Execute(context);

            Assert.AreEqual(false, result.Success);

            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Could not retrieve a page from property 'MyProperty'", result.Exception.Message);

            locator.VerifyAll();
            propData.VerifyAll();
        }
Esempio n. 2
0
        public void TestGetElementAsPageWhenPageIsAListReturnsAFailure()
        {
            var propData = new Mock <IPropertyData>(MockBehavior.Strict);

            propData.SetupGet(p => p.IsList).Returns(true);
            propData.SetupGet(p => p.Name).Returns("MyProperty");

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

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

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

            var context = new ActionContext("myproperty");
            var result  = buttonClickAction.Execute(context);

            Assert.AreEqual(false, result.Success);

            Assert.IsNotNull(result.Exception);
            StringAssert.Contains(result.Exception.Message, "MyProperty");

            locator.VerifyAll();
            propData.VerifyAll();
        }
Esempio n. 3
0
        public void TestGetElementAsPageSuccess()
        {
            var page = new Mock <IPage>(MockBehavior.Strict);

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

            propData.SetupGet(p => p.IsList).Returns(false);
            propData.Setup(p => p.GetItemAsPage()).Returns(page.Object);

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

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

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

            var context = new ActionContext("myproperty");
            var result  = buttonClickAction.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(page.Object, result.Result);

            locator.VerifyAll();
            propData.VerifyAll();
        }
Esempio n. 4
0
        public void TestGetElementAsPageFieldDoesNotExist()
        {
            var locator = new Mock <IElementLocator>(MockBehavior.Strict);

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

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

            var context = new ActionContext("doesnotexist");

            ExceptionHelper.SetupForException <ElementExecuteException>(
                () => buttonClickAction.Execute(context), e => locator.VerifyAll());
        }
Esempio n. 5
0
        public void TestGetActionName()
        {
            var buttonClickAction = new GetElementAsPageAction();

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