コード例 #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);
		}
コード例 #2
0
        /// <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);
		}
コード例 #3
0
        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));
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
        }
コード例 #6
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);
        }
コード例 #7
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();
            }
        }
コード例 #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();
            }
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
 /// <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
ファイル: NotConstraint.cs プロジェクト: pusp/o2platform
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return ! inner.Matches(attributeBag, context);
 }
コード例 #14
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 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
ファイル: Constraint.cs プロジェクト: teknologika/McWatiN
 /// <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();
        }
コード例 #19
0
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return false;
 }
コード例 #20
0
ファイル: NoneConstraint.cs プロジェクト: Nokkes/Powershell
 /// <inheritdoc />
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return(false);
 }
コード例 #21
0
 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;
     }
 }
コード例 #22
0
 private bool IsMatchByConstraint(Component element, ConstraintContext context)
 {
     return element.Matches(Constraint, context);
 }
コード例 #23
0
        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();
        }
コード例 #29
0
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     int counter = ((int?)context.GetData(this)).GetValueOrDefault();
     context.SetData(this, counter + 1);
     return counter == index;
 }
コード例 #30
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);
コード例 #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));
 }
コード例 #34
0
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return true;
 }
コード例 #35
0
        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));
 }
コード例 #37
0
 protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     var element = attributeBag.GetAdapter<Element>();
     return element != null && Comparer.Compare(IsVisible(element).ToString());
 }
コード例 #38
0
 /// <inheritdoc />
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return first.Matches(attributeBag, context)
         || second.Matches(attributeBag, context);
 }
コード例 #39
0
 public override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
 {
     return ActualConstraint.MatchesImpl(attributeBag, context);
 }