示例#1
0
        /// <inheritdoc />
        protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            Component component = attributeBag.GetAdapter<Component>();
            if (component == null)
                throw new WatiNException("This constraint class can only be used to compare against a component");

            return comparer.Compare(component);
		}
        /// <inheritdoc />
        public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            Element element = attributeBag.GetAdapter<Element>();
            if (element == null)
                throw new WatiNException("This constraint class can only be used to compare against an element");

            return comparer.Compare(element);
		}
        public void AttributeOperatorNotOverload()
        {
            // Given
            var mockAttributeBag = new Mock<IAttributeBag>().Object;
            ConstraintContext context = new ConstraintContext();

            // WHEN
            var attributenot = !Find.Any;

            // THEN
            Assert.IsInstanceOfType(typeof (NotConstraint), attributenot, "Expected NotAttributeConstraint instance");
            Assert.IsFalse(attributenot.Matches(mockAttributeBag, context));
        }
        public IE FindIEPartiallyInitialized(Constraint findBy)
        {
            var allBrowsers = new ShellWindows2();

            var context = new ConstraintContext();
            foreach (IWebBrowser2 browser in allBrowsers)
            {
                var ie = CreateBrowserInstance(new IEBrowser(browser));
                if (ie.Matches(findBy, context))
                    return ie;
            }

            return null;
        }
        public void NotTest()
        {
            // Given
            var mockAttributeBag = new Mock<IAttributeBag>().Object;
            ConstraintContext context = new ConstraintContext();

            var notConstraint = new NotConstraint(Find.None);

            // WHEN
            var result = notConstraint.Matches(mockAttributeBag, context);

            // THEN
            Assert.That(result, Is.True);
        }
        /// <inheritdoc />
        protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            var element = attributeBag.GetAdapter<Element>();
            if (element == null)
                throw new WatiNException("This constraint class can only be used to compare against an element");

            var cache = (LabelCache)context.GetData(this);
            if (cache == null)
            {
                cache = new LabelCache(labelText);
                context.SetData(this, cache);
            }

            return cache.IsMatch(element);
        }
        /// <summary>
        /// Returns true if the constraint matches an object described by an attribute bag.
        /// </summary>
        /// <param name="attributeBag">The attribute bag</param>
        /// <param name="context">The constraint matching context</param>
        /// <returns>True if the constraint matches</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="attributeBag"/> or <paramref name="context"/> is null</exception>
        public bool Matches(IAttributeBag attributeBag, ConstraintContext context)
        {
            if (attributeBag == null)
                throw new ArgumentNullException("attributeBag");
            if (context == null)
                throw new ArgumentNullException("context");

            try
            {
                EnterMatch();
                return MatchesImpl(attributeBag, context);
            }
            finally
            {
                ExitMatch();
            }
        }
示例#8
0
        /// <inheritdoc />
        protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            var element = attributeBag.GetAdapter <Element>();

            if (element == null)
            {
                throw new WatiNException("This constraint class can only be used to compare against an element");
            }

            var cache = (LabelCache)context.GetData(this);

            if (cache == null)
            {
                cache = new LabelCache(labelText);
                context.SetData(this, cache);
            }

            return(cache.IsMatch(element));
        }
示例#9
0
        /// <summary>
        /// Returns true if the constraint matches an object described by an attribute bag.
        /// </summary>
        /// <param name="attributeBag">The attribute bag</param>
        /// <param name="context">The constraint matching context</param>
        /// <returns>True if the constraint matches</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="attributeBag"/> or <paramref name="context"/> is null</exception>
        public bool Matches(IAttributeBag attributeBag, ConstraintContext context)
        {
            if (attributeBag == null)
            {
                throw new ArgumentNullException("attributeBag");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            try
            {
                EnterMatch();
                return(MatchesImpl(attributeBag, context));
            }
            finally
            {
                ExitMatch();
            }
        }
        /// <inheritdoc />
        public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            var typeToConvertTo = typeof(T);

            if (typeToConvertTo.IsSubclassOf(typeof(Control)))
            {
                if (attributeBag.GetType().IsSubclassOf(typeof(Element)))
                {
                    T control = Control.CreateControl(typeToConvertTo, (Element)attributeBag) as T;
                    return(predicate(control));
                }
            }
            else
            {
                T value = attributeBag.GetAdapter <T>();
                if (value == null)
                {
                    throw new WatiNException(string.Format("The PredicateConstraint class can only be used to compare against values adaptable to {0}.", typeToConvertTo));
                }

                return(predicate(value));
            }
            return(false);
        }
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     var attributeValue = attributeBag.GetAttributeValue(attributeName);
     return comparer.Compare(attributeValue);
 }
        public void Occurence2()
        {
            Constraint findBy = new IndexConstraint(2);

            var mockAttributeBag = new MockAttributeBag("name", "Z");

            ConstraintContext context = new ConstraintContext();
            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
            Assert.IsTrue(findBy.Matches(mockAttributeBag, context));
            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
        }
示例#13
0
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return ! inner.Matches(attributeBag, context);
 }
 /// <summary>
 /// Returns true if the constraint matches an object described by an attribute bag.
 /// </summary>
 /// <param name="attributeBag">The attribute bag, not null</param>
 /// <param name="context">The constraint matching context, not null</param>
 /// <returns>True if the constraint matches</returns>
 protected abstract bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context);
        public void TrueAndOccurence()
        {
            var findBy = Find.ByName("Z").And(new IndexConstraint(1));

            var mockAttributeBag = new MockAttributeBag("name", "Z");

            ConstraintContext context = new ConstraintContext();
            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
            Assert.IsTrue(findBy.Matches(mockAttributeBag, context));
        }
示例#16
0
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return(!inner.Matches(attributeBag, context));
 }
示例#17
0
 /// <summary>
 /// Returns true if the constraint matches an object described by an attribute bag.
 /// </summary>
 /// <param name="attributeBag">The attribute bag, not null</param>
 /// <param name="context">The constraint matching context, not null</param>
 /// <returns>True if the constraint matches</returns>
 protected abstract bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context);
        public void RecusiveCallExceptionExpected()
        {
            var mockAttributeBag = new Mock<IAttributeBag>();

            // Note: Creating a re-entrant constraint is now much more difficult than
            //       before because constraints are immutable.  Even the code findBy |= findBy
            //       will not create a re-entrant constraint, it will just be an Or constraint
            //       with two identical clauses.  Given this change in constraint construction
            //       we should consider removing the re-entrance checks in the future.  -- Jeff.
            Constraint findBy = Find.By("tag", "value");
            findBy |=  new PredicateConstraint<IAttributeBag>(bag => findBy.Matches(bag, new ConstraintContext()));

            ConstraintContext context = new ConstraintContext();
            mockAttributeBag.Expect(bag => bag.GetAttributeValue("tag")).Returns("val");
            mockAttributeBag.Expect(bag => bag.GetAdapter<IAttributeBag>()).Returns(mockAttributeBag.Object);

            findBy.Matches(mockAttributeBag.Object, context);

            mockAttributeBag.VerifyAll();
        }
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return false;
 }
示例#20
0
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return(false);
 }
 private IEnumerable<Element> WrapMatchingElements(IEnumerable<INativeElement> nativeElements)
 {
     var context = new ConstraintContext();
     foreach (var nativeElement in nativeElements)
     {
         var element = WrapElementIfMatch(nativeElement, context);
         if (element == null) continue;
         
         yield return element;
     }
 }
 private bool IsMatchByConstraint(Component element, ConstraintContext context)
 {
     return element.Matches(Constraint, context);
 }
        private Element WrapElementIfMatch(INativeElement nativeElement, ConstraintContext context)
        {
            nativeElement.WaitUntilReady();

            if (IsMatchByTag(nativeElement))
            {
                var element = WrapElement(nativeElement);
                if (element == null) return null;

                if (IsMatchByConstraint(element, context))
                    return element;
            }

            return null;
        }
        public void OccurenceOr()
        {
            var findBy = new IndexConstraint(2).Or(Find.ByName("Z"));
            ConstraintContext context = new ConstraintContext();

            var mockAttributeBag = new MockAttributeBag("name", "Z");
            Assert.IsTrue(findBy.Matches(mockAttributeBag, context));

            mockAttributeBag = new MockAttributeBag("name", "y");

            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
            Assert.IsTrue(findBy.Matches(mockAttributeBag, context));
        }
示例#25
0
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return(true);
 }
 public void OrSecondTrue()
 {
     var findBy = Find.ByName("X").Or(Find.ByName("Y"));
     var mockAttributeBag = new MockAttributeBag("name", "Y");
     ConstraintContext context = new ConstraintContext();
     Assert.IsTrue(findBy.Matches(mockAttributeBag, context));
 }
示例#27
0
 /// <summary>
 /// Returns true if the constraint matches an object described by an attribute bag.
 /// </summary>
 /// <param name="attributeBag">The attribute bag, not null</param>
 /// <param name="context">The constraint matching context, not null</param>
 /// <returns>True if the constraint matches</returns>
 public abstract bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context);
        public void TrueAndIndexConstraintAndTrue()
        {
            var mockAttributeBag = new Mock<IAttributeBag>();

            var findBy = Find.ByName("Z").And(new IndexConstraint(1)).And(Find.ByValue("text"));
            ConstraintContext context = new ConstraintContext();

            mockAttributeBag.Expect(bag => bag.GetAttributeValue("name")).Returns("Z");

            Assert.IsFalse(findBy.Matches(mockAttributeBag.Object, context), "False because index will be 0 when evaluated.");

            mockAttributeBag.Expect(bag => bag.GetAttributeValue("name")).Returns("Y");

            Assert.IsFalse(findBy.Matches(mockAttributeBag.Object, context), "False because index will be skipped since first clause fails to match.");

            mockAttributeBag.Expect(bag => bag.GetAttributeValue("name")).Returns("Z");
            mockAttributeBag.Expect(bag => bag.GetAttributeValue("value")).Returns("text");

            Assert.IsTrue(findBy.Matches(mockAttributeBag.Object, context), "True because index will be 1 when evaluated.");

            mockAttributeBag.Expect(bag => bag.GetAttributeValue("name")).Returns("Z");

            Assert.IsFalse(findBy.Matches(mockAttributeBag.Object, context), "False because index will be 2 when evaluated.");

            mockAttributeBag.VerifyAll();
        }
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     int counter = ((int?)context.GetData(this)).GetValueOrDefault();
     context.SetData(this, counter + 1);
     return counter == index;
 }
 /// <summary>
 /// Returns true if the constraint matches an object described by an attribute bag.
 /// </summary>
 /// <param name="attributeBag">The attribute bag, not null</param>
 /// <param name="context">The constraint matching context, not null</param>
 /// <returns>True if the constraint matches</returns>
 public abstract bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context);
示例#31
0
        /// <inheritdoc />
        public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
        {
            var attributeValue = attributeBag.GetAttributeValue(attributeName);

            return(comparer.Compare(attributeValue));
        }
示例#32
0
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return first.Matches(attributeBag, context)
         && second.Matches(attributeBag, context);
 }
示例#33
0
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return(first.Matches(attributeBag, context) &&
            second.Matches(attributeBag, context));
 }
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return true;
 }
        public void TestMatchesImpl()
        {
            Mock<IAttributeBag> attributeBag = new Mock<IAttributeBag>();
            ConstraintContext constraintContext = new ConstraintContext();
            Mock<Constraint> constraint = new Mock<Constraint>();

            constraint.Expect(c => c.MatchesImpl(attributeBag.Object, constraintContext))
                .Verifiable();

            CssSelectorConstraint_allowingMockedInternal sut = new CssSelectorConstraint_allowingMockedInternal();

            sut.SetActualConstraint(constraint.Object);

            sut.MatchesImpl(attributeBag.Object, constraintContext);

            constraint.Verify();
        }
示例#36
0
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return(first.Matches(attributeBag, context) ||
            second.Matches(attributeBag, context));
 }
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     var element = attributeBag.GetAdapter<Element>();
     return element != null && Comparer.Compare(IsVisible(element).ToString());
 }
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return first.Matches(attributeBag, context)
         || second.Matches(attributeBag, context);
 }
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return ActualConstraint.MatchesImpl(attributeBag, context);
 }