示例#1
0
        public void TestGetElementWhenElementGetFails()
        {
            IPropertyData resultPropertyData;

            var page = new Mock <IPage>(MockBehavior.Strict);

            page.Setup(p => p.TryGetElement("MyElement", out resultPropertyData)).Returns(false);
            page.Setup(p => p.GetPropertyNames(It.IsAny <Func <IPropertyData, bool> >())).Returns(new[] { "MyProperty" });
            page.SetupGet(p => p.PageType).Returns(typeof(ElementLocatorFixture));

            var locatorAction = new Mock <ILocatorAction>(MockBehavior.Strict);

            locatorAction.Setup(p => p.OnLocate("MyElement"));
            locatorAction.Setup(p => p.OnLocateComplete("MyElement", null));

            var locator = new ElementLocator(page.Object, new[] { locatorAction.Object });

            try
            {
                locator.GetElement("MyElement");
            }
            catch (ElementExecuteException)
            {
                page.VerifyAll();
                locatorAction.VerifyAll();
                throw;
            }
        }
示例#2
0
        public void TestGetElementWhenElementGetIsSuccessful()
        {
            var resultPropertyData = new Mock <IPropertyData>().Object;

            var page = new Mock <IPage>(MockBehavior.Strict);

            page.Setup(p => p.TryGetElement("MyElement", out resultPropertyData)).Returns(true);

            var locatorAction = new Mock <ILocatorAction>(MockBehavior.Strict);

            locatorAction.Setup(p => p.OnLocate("MyElement"));
            locatorAction.Setup(p => p.OnLocateComplete("MyElement", resultPropertyData));

            var locator = new ElementLocator(page.Object, new[] { locatorAction.Object });

            var propertyData = locator.GetElement("MyElement");

            Assert.IsNotNull(propertyData);
            Assert.AreSame(resultPropertyData, propertyData);

            page.VerifyAll();
            locatorAction.VerifyAll();
        }