public void OrFirstTrue()
 {
     var findBy = Find.ByName("X").Or(Find.ByName("Y"));
     var mockAttributeBag = new MockAttributeBag("name", "X");
     var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());
     Assert.IsTrue(compare);
 }
Пример #2
0
        public void FindByTextOnTextShouldIgnoreSpacesBeforeOrAfterText()
        {
            const string innertext = "innertext";

            var value            = Find.ByText("textvalue");
            var mockAttributeBag = new MockAttributeBag(innertext, "textvalue");
            var context          = new ConstraintContext();

            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Exact match expected");

            mockAttributeBag = new MockAttributeBag(innertext, " textvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "1 Space before should match");

            mockAttributeBag = new MockAttributeBag(innertext, "  textvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "2 Spaces before should match");

            mockAttributeBag = new MockAttributeBag(innertext, "textvalue ");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "1 Spaces after should match");

            mockAttributeBag = new MockAttributeBag(innertext, "textvalue  ");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "2 Spaces after should match");

            mockAttributeBag = new MockAttributeBag(innertext, " textvalue ");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "1 Space before and 1 after should match");

            mockAttributeBag = new MockAttributeBag(innertext, "a textvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.False, "should only match with only spaces before searched text");

            mockAttributeBag = new MockAttributeBag(innertext, "textvalue z");
            Assert.That(value.Matches(mockAttributeBag, context), Is.False, "should only match with only spaces after searched text");

            mockAttributeBag = new MockAttributeBag(innertext, "a textvalue z");
            Assert.That(value.Matches(mockAttributeBag, context), Is.False, "should not match");
        }
Пример #3
0
        public void Find_bytext_on_innertext_should_ignore_spaces_before_or_after_text_to_match_with()
        {
            const string innertext = "innertext";

            var value            = Find.ByText("textvalue");
            var mockAttributeBag = new MockAttributeBag(innertext, "textvalue");
            var context          = new ConstraintContext();

            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Exact match expected");

            mockAttributeBag = new MockAttributeBag(innertext, " textvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "1 Space before should match");

            mockAttributeBag = new MockAttributeBag(innertext, "  textvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "2 Spaces before should match");

            mockAttributeBag = new MockAttributeBag(innertext, "textvalue ");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "1 Spaces after should match");

            mockAttributeBag = new MockAttributeBag(innertext, "textvalue  ");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "2 Spaces after should match");

            mockAttributeBag = new MockAttributeBag(innertext, " textvalue ");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "1 Space before and 1 after should match");

            mockAttributeBag = new MockAttributeBag(innertext, "a textvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.False, "should only match with only spaces before searched text");

            mockAttributeBag = new MockAttributeBag(innertext, "textvalue z");
            Assert.That(value.Matches(mockAttributeBag, context), Is.False, "should only match with only spaces after searched text");

            mockAttributeBag = new MockAttributeBag(innertext, "a textvalue z");
            Assert.That(value.Matches(mockAttributeBag, context), Is.False, "should not match");
        }
Пример #4
0
        public void FindByStyle()
        {
            const string attributeName = "background-color";
            var          value         = Find.ByStyle(attributeName, "red");

            Assert.IsInstanceOf(typeof(Constraint), value, "StyleAttributeConstraint class should inherit AttributeConstraint class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            const string fullAttributeName = "style.background-color";

            Assert.AreEqual(fullAttributeName, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'red'"), "Wrong value");

            var regex = new Regex("een$");

            value = Find.ByStyle(attributeName, regex);
            var mockAttributeBag = new MockAttributeBag(fullAttributeName, "green");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex een$ should match");

            value = Find.ByStyle(attributeName, new StringContainsAndCaseInsensitiveComparer("rEe"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.ByStyle(attributeName, text => text == "green");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #5
0
        public void FindByValue()
        {
            const string valueAttrib = "value";

            var value = Find.ByValue("valuevalue");

            Assert.IsInstanceOf(typeof(Constraint), value, "Value class should inherit AttributeConstraint class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            Assert.AreEqual(valueAttrib, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'valuevalue'"), "Wrong value");

            var regex = new Regex("lue$");

            value = Find.ByValue(regex);

            var mockAttributeBag = new MockAttributeBag(valueAttrib, "valuevalue");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex lue$ should match");

            value = Find.ByValue(new StringContainsAndCaseInsensitiveComparer("eVal"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.ByValue(text => text == "valuevalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #6
0
        public void FindByFor()
        {
            const string htmlfor = "htmlFor";

            var value = Find.ByFor("foridvalue");

            Assert.IsInstanceOf(typeof(Constraint), value, "For class should inherit Attribute class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            Assert.That(value.AttributeName, Is.EqualTo(htmlfor), "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'foridvalue'"), "Wrong value");

            var regex = new Regex("^id");

            value = Find.ByFor(regex);
            var mockAttributeBag = new MockAttributeBag(htmlfor, "idvalue");

            var context = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex ^id should match");

            value = Find.ByFor(new StringContainsAndCaseInsensitiveComparer("VAl"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            mockAttributeBag = new MockAttributeBag(htmlfor, "forvalue");

            value = Find.ByFor(text => text == "forvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #7
0
        public void FindBySrc()
        {
            const string src = "src";

            var value = Find.BySrc("image.gif");

            Assert.IsInstanceOf(typeof(Constraint), value, "Src class should inherit AttributeConstraint class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            Assert.AreEqual(src, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'image.gif'"), "Wrong value");

            var mockAttributeBag = new MockAttributeBag(src, "/images/image.gif");
            var context          = new ConstraintContext();

            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Should not match /images/image.gif");

            mockAttributeBag = new MockAttributeBag(src, "image.gif");
            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Should match image.gif");

            var regex = new Regex("image.gif$");

            value            = Find.BySrc(regex);
            mockAttributeBag = new MockAttributeBag(src, "/images/image.gif");

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex image.gif$ should match");

            value = Find.BySrc(new StringContainsAndCaseInsensitiveComparer("es/Im"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.BySrc(text => text == "/images/image.gif");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #8
0
        public void FindByClass()
        {
            var value = Find.ByClass("highlighted");

            Assert.IsInstanceOf(typeof(Constraint), value, "Find.ByClass should return an AttributeConstraint");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            const string classname = "className";

            Assert.AreEqual(classname, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'highlighted'"), "Wrong value");

            var regex = new Regex("ghted$");

            value = Find.ByClass(regex);

            var mockAttributeBag = new MockAttributeBag(classname, "highlighted");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex ghted$ should match");

            value = Find.ByClass(new StringContainsAndCaseInsensitiveComparer("hLIg"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.ByClass(text => text == "highlighted");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #9
0
        public void FindByUrl()
        {
            var url   = WatiNURI.AbsoluteUri;
            var value = Find.ByUrl(url);

            Assert.IsInstanceOfType(typeof(Constraint), value, "Url class should inherit AttributeConstraint class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(UriComparer)), "Unexpected comparer");
            AssertUrlValue(value);

            // make sure overload also works
            value = Find.ByUrl(url, true);

            Assert.IsInstanceOfType(typeof(Constraint), value, "Url class should inherit AttributeConstraint class");
            AssertUrlValue(value);

            var mockAttributeBag = new MockAttributeBag("href", url);
            var context          = new ConstraintContext();

            value = Find.ByUrl(new StringContainsAndCaseInsensitiveComparer("/watin.Sour"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            _expectedPredicateCompareValue = url;
            value = Find.ByUrl(TestPredicateCompareMethod);
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #10
0
        public void FindByAlt()
        {
            var value = Find.ByAlt("alt text");

            Assert.IsInstanceOf(typeof(Constraint), value, "Alt class should inherit Attribute class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            const string name = "alt";

            Assert.AreEqual(name, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'alt text'"), "Wrong value");

            var regex = new Regex("ext$");

            value = Find.ByAlt(regex);
            var mockAttributeBag = new MockAttributeBag(name, "alt text");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex ext$ should match");

            value = Find.ByAlt(new StringContainsAndCaseInsensitiveComparer("ALT TexT"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.ByAlt(text => text == "alt text");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #11
0
        public void FindByText()
        {
            var value = Find.ByText("textvalue");

            Assert.IsInstanceOfType(typeof(Constraint), value, "Text class should inherit Attribute class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(RegexComparer)), "Unexpected comparer");

            const string innertext = "innertext";

            Assert.AreEqual(innertext, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'^ *textvalue *$'"), "Wrong value");

            var regex = new Regex("lue$");

            value = Find.ByText(regex);
            var mockAttributeBag = new MockAttributeBag(innertext, "textvalue");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex lue$ should match");

            value = Find.ByText(new StringContainsAndCaseInsensitiveComparer("tVal"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            _expectedPredicateCompareValue = "textvalue";
            value = Find.ByText(TestPredicateCompareMethod);
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
Пример #12
0
        public void FindByTextHandlesBackslashes()
        {
            var value            = Find.ByText(@"abc\xyz");
            var mockAttributeBag = new MockAttributeBag("innertext", @"abc\xyz");
            var context          = new ConstraintContext();

            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "With backslash should match");
        }
        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));
        }
        public void OrFirstTrue()
        {
            var findBy           = Find.ByName("X").Or(Find.ByName("Y"));
            var mockAttributeBag = new MockAttributeBag("name", "X");
            var compare          = findBy.Matches(mockAttributeBag, new ConstraintContext());

            Assert.IsTrue(compare);
        }
        public void OccurenceAndOrWithOrTrue()
        {
            var findBy = new IndexConstraint(2).And(Find.ByName("Y")).Or(Find.ByName("Z"));

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

            Assert.IsTrue(findBy.Matches(mockAttributeBag, context));
        }
        public void AndOrThroughOperatorOverloads()
        {
            var findBy = Find.ByName("X") & Find.ByValue("Cancel") | (Find.ByName("Z") & Find.ByValue("Cancel"));

            var mockAttributeBag = new MockAttributeBag("name", "Z");
            mockAttributeBag.Add("value", "OK");
            var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());
            Assert.IsFalse(compare);
        }
Пример #17
0
        public void FindByUrlWithRegex()
        {
            var regex            = new Regex("^http://watin");
            var value            = Find.ByUrl(regex);
            var mockAttributeBag = new MockAttributeBag(Href, "http://watin.sourceforge.net");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex ^http://watin should match");
        }
        public void AndFalseSecond()
        {
            var findBy = Find.ByName("X").And(Find.ByValue("Cancel"));

            var mockAttributeBag = new MockAttributeBag("name", "X");
            mockAttributeBag.Add("value", "OK");

            var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());
            Assert.IsFalse(compare);
        }
        public void AndOr()
        {
            var findByNames = Find.ByName("X").Or(Find.ByName("Y"));
            var findBy = Find.ByValue("Cancel").And(findByNames);

            var mockAttributeBag = new MockAttributeBag("name", "X");
            mockAttributeBag.Add("value", "Cancel");
            var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());
            Assert.IsTrue(compare);
        }
Пример #20
0
        public void FindByTitle()
        {
            const string title = "title";

            var value = Find.ByTitle("titlevalue");

            Assert.IsInstanceOfType(typeof(Constraint), value, "Title class should inherit AttributeConstraint class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringContainsAndCaseInsensitiveComparer)), "Unexpected comparer");

            Assert.AreEqual(title, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'titlevalue'"), "Wrong value");


            var mockAttributeBag = new MockAttributeBag(title, String.Empty);
            var context          = new ConstraintContext();

            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Empty should not match");

            mockAttributeBag = new MockAttributeBag(title, null);
            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Null should not match");

            mockAttributeBag = new MockAttributeBag(title, "titlevalue");

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Compare should match");

            value = Find.ByTitle("titl");
            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Compare should partial match titl");

            value = Find.ByTitle("tItL");
            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Compare should partial match tItL");

            value = Find.ByTitle("lev");
            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Compare should partial match lev");

            value = Find.ByTitle("alue");
            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Compare should partial match alue");

            var regex = new Regex("^titl");

            value = Find.ByTitle(regex);
            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex ^titl should match");

            value            = Find.ByTitle("titlevalue");
            mockAttributeBag = new MockAttributeBag(title, "title");

            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Compare should not match title");

            mockAttributeBag = new MockAttributeBag(title, "title");
            value            = Find.ByTitle(new StringContainsAndCaseInsensitiveComparer("iTl"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            _expectedPredicateCompareValue = "title";
            value = Find.ByTitle(TestPredicateCompareMethod);
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
        public void Occurence0()
        {
            Constraint findBy = new IndexConstraint(0);

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

            ConstraintContext context = new ConstraintContext();

            Assert.IsTrue(findBy.Matches(mockAttributeBag, context));
            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
        }
        public void FalseAndOccurence()
        {
            var findBy = Find.ByName("Y").And(new IndexConstraint(1));

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

            ConstraintContext context = new ConstraintContext();

            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
            Assert.IsFalse(findBy.Matches(mockAttributeBag, context));
        }
        public void AndOrThroughOperatorOverloads()
        {
            var findBy = Find.ByName("X") & Find.ByValue("Cancel") | (Find.ByName("Z") & Find.ByValue("Cancel"));

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

            mockAttributeBag.Add("value", "OK");
            var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());

            Assert.IsFalse(compare);
        }
        public void AndFalseSecond()
        {
            var findBy = Find.ByName("X").And(Find.ByValue("Cancel"));

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

            mockAttributeBag.Add("value", "OK");

            var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());

            Assert.IsFalse(compare);
        }
        public void AndOr()
        {
            var findByNames = Find.ByName("X").Or(Find.ByName("Y"));
            var findBy      = Find.ByValue("Cancel").And(findByNames);

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

            mockAttributeBag.Add("value", "Cancel");
            var compare = findBy.Matches(mockAttributeBag, new ConstraintContext());

            Assert.IsTrue(compare);
        }
Пример #26
0
        public void Find_bytext_should_match_given_regex()
        {
            // GIVEN
            var mockAttributeBag = new MockAttributeBag("innertext", "textvalue");
            var context          = new ConstraintContext();

            // WHEN
            var value   = Find.ByText(new Regex("lue$"));
            var matches = value.Matches(mockAttributeBag, context);

            // THEN
            Assert.That(matches, Is.True, "Regex lue$ should match");
        }
Пример #27
0
        public void Find_bytext_should_use_given_predicate()
        {
            // GIVEN
            const string innertext        = "innertext";
            var          mockAttributeBag = new MockAttributeBag(innertext, "textvalue");
            var          context          = new ConstraintContext();

            // WHEN
            var value   = Find.ByText(text => text == "textvalue");
            var matches = value.Matches(mockAttributeBag, context);

            // THEN
            Assert.That(matches, Is.True, "PredicateComparer not used");
        }
Пример #28
0
        public void Find_bytext_should_use_given_comparer()
        {
            // GIVEN
            const string innertext        = "innertext";
            var          mockAttributeBag = new MockAttributeBag(innertext, "textvalue");
            var          context          = new ConstraintContext();

            // WHEN
            var value   = Find.ByText(new StringContainsAndCaseInsensitiveComparer("tVal"));
            var matches = value.Matches(mockAttributeBag, context);

            // THEN
            Assert.That(matches, Is.True, "Comparer not used");
        }
        public void Setup()
        {
            mockAttributeBag = new MockAttributeBag("1", "true");
            mockAttributeBag.Add("2","false");
            mockAttributeBag.Add("4", "true");
            mockAttributeBag.Add("5", "false");

            findBy = null;

            findBy1 = Find.By("1", "true");
            findBy2 = Find.By("2", "true");
            findBy3 = Find.By("3", "true");
            findBy4 = Find.By("4", "true");
            findBy5 = Find.By("5", "true");
        }
Пример #30
0
        public void Find_bytext_should_match_equal_innertext()
        {
            // GIVEN
            const string innerText = "textvalue";

            var mockAttributeBag = new MockAttributeBag("innertext", innerText);
            var context          = new ConstraintContext();

            // WHEN
            var value   = Find.ByText("textvalue");
            var matches = value.Matches(mockAttributeBag, context);

            // THEN
            Assert.That(matches, Is.True, "Should match");
        }
Пример #31
0
        public void Setup()
        {
            mockAttributeBag = new MockAttributeBag("1", "true");
            mockAttributeBag.Add("2", "false");
            mockAttributeBag.Add("4", "true");
            mockAttributeBag.Add("5", "false");

            findBy = null;

            findBy1 = Find.By("1", "true");
            findBy2 = Find.By("2", "true");
            findBy3 = Find.By("3", "true");
            findBy4 = Find.By("4", "true");
            findBy5 = Find.By("5", "true");
        }
Пример #32
0
        public void Find_bytext_should_match_when_text_to_find_contains_regex_char()
        {
            // GIVEN
            const string innerTextWithSpaces = "textvalue?";

            var mockAttributeBag = new MockAttributeBag("innertext", innerTextWithSpaces);
            var context          = new ConstraintContext();

            // WHEN
            var value   = Find.ByText("textvalue?");
            var matches = value.Matches(mockAttributeBag, context);

            // THEN
            Assert.That(matches, Is.True, "Should match");
        }
Пример #33
0
        public void IdWithRegexAndComparer()
        {
            var context          = new ConstraintContext();
            var mockAttributeBag = new MockAttributeBag("id", "idvalue");

            Constraint value = Find.ById(new Regex("lue$"));

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex lue$ should match.");

            // See if mocked comparer is used. VerifyAll will check this
            var comparerMock = new Mock <Comparer <string> >();

            comparerMock.Expect(comparer => comparer.Compare("MyMockComparer")).Returns(true);

            mockAttributeBag = new MockAttributeBag("id", "MyMockComparer");
            Find.ById(comparerMock.Object).Matches(mockAttributeBag, context);

            comparerMock.VerifyAll();
        }
Пример #34
0
        private static void AssertUrlValue(AttributeConstraint value)
        {
            Assert.AreEqual(Href, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'" + WatiNURI.AbsoluteUri + "'"), "Wrong value");

            var mockAttributeBag = new MockAttributeBag(Href, WatiNURI.AbsoluteUri);
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Should match WatiN url");

            mockAttributeBag = new MockAttributeBag(Href, "http://www.microsoft.com");
            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Shouldn't match Microsoft");

            mockAttributeBag = new MockAttributeBag(Href, null);
            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Null should not match");

            mockAttributeBag = new MockAttributeBag(Href, String.Empty);
            Assert.IsFalse(value.Matches(mockAttributeBag, context), "Null should not match");
        }
Пример #35
0
        public void FindByID()
        {
            var value = Find.ById("idvalue");

            Assert.IsInstanceOf(typeof(Constraint), value, "Id class should inherit Attribute class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            const string id = "id";

            Assert.AreEqual(id, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'idvalue'"), "Wrong value");

            var mockAttributeBag = new MockAttributeBag("id", "idvalue");
            var context          = new ConstraintContext();

            value = Find.ById(new StringContainsAndCaseInsensitiveComparer("Val"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.ById(text => text == "idvalue");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
        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));
        }
 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));
 }
        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));
        }
        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));
        }