Пример #1
0
        public void TestGetPropertyWhenPropertyGetFails()
        {
            IPropertyData resultPropertyData;

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

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

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

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

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

            try
            {
                locator.GetProperty("MyProperty");
            }
            catch (ElementExecuteException)
            {
                page.VerifyAll();
                locatorAction.VerifyAll();
                throw;
            }
        }
Пример #2
0
        public void TestGetPropertyWhenPropertyGetIsSuccessful()
        {
            var resultPropertyData = new Mock <IPropertyData>().Object;

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

            page.Setup(p => p.TryGetProperty("MyProperty", out resultPropertyData)).Returns(true);

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

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

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

            var propertyData = locator.GetProperty("MyProperty");

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

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