protected static Element ResolveQuery(StubElementFinder finder)
        {
            var strategy = new FinderOptionsDisambiguationStrategy();
            var results  = strategy.ResolveQuery(finder);

            return(results);
        }
        public void When_there_is_more_than_one_substring_match_it_throws_ambiguous_execption()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);
            var exactResults = new List<ElementFound> {new StubElement(), new StubElement()};

            StubSubstringResults(finder, finderOptions, exactResults);

            Assert.Throws<AmbiguousException>(() => ResolveQuery(finder));
        }
        public void When_there_are_multiple_exact_matches_it_checks_only_exact_and_returns_the_first_exact_one()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);
            var exactResults = new List<Element> { new StubElement(), new StubElement() };

            StubExactResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.First())); 
        }
        public void When_there_is_more_than_one_match_it_picks_the_first_one()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);
            var exactResults = new List<Element> { new StubElement(), new StubElement() };

            StubExactResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.First()));
        }
Exemple #5
0
        public void When_there_is_more_than_one_exact_match_it_throws_ambiguous_execption()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions);
            var exactResults  = new List <Element> {
                new StubElement(), new StubElement()
            };

            StubExactResults(finder, finderOptions, exactResults);

            Assert.Throws <AmbiguousException>(() => ResolveQuery(finder));
        }
        public void When_there_is_only_one_exact_match_it_only_looks_for_exact_and_finds_it()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);

            var exactResults = new List<ElementFound> { new StubElement() };
            StubExactResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.Single()));
        }
        public void When_there_is_only_one_substring_match_it_finds_it_with_exact_false()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);
            var exactResults = new List<ElementFound> { new StubElement() };

            StubSubstringResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.First()));
        }
Exemple #8
0
        public void When_there_are_multiple_exact_matches_it_checks_only_exact_and_returns_the_first_exact_one()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions);
            var exactResults  = new List <Element> {
                new StubElement(), new StubElement()
            };

            StubExactResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.First()));
        }
        public void When_there_is_more_than_one_match_it_picks_the_first_one()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions);
            var exactResults  = new List <Element> {
                new StubElement(), new StubElement()
            };

            StubExactResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.First()));
        }
Exemple #10
0
        public void When_there_is_only_one_exact_match_it_finds_it_and_only_looks_for_exact()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions);
            var exactResults  = new List <Element> {
                new StubElement()
            };

            StubExactResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.Single()));
        }
        public void When_there_is_only_one_substring_match_it_finds_it_with_exact_false()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions);
            var exactResults  = new List <ElementFound> {
                new StubElement()
            };

            StubSubstringResults(finder, finderOptions, exactResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(exactResults.First()));
        }
        public void When_there_are_no_exact_but_multiple_substring_matches_it_returns_the_first_substring_match()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);
            var exactResults = new List<Element> ();
            var substringResults = new List<Element> { new StubElement(), new StubElement() };

            StubExactResults(finder, finderOptions, exactResults);
            StubSubstringResults(finder, finderOptions, substringResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(substringResults.First())); 
        }
        public void When_there_is_no_exact_match_but_multiple_substring_matches_it_throws_ambiguous_exception()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions);

            var exactResults     = new List <ElementFound> ();
            var substringResults = new List <ElementFound> {
                new StubElement(), new StubElement()
            };

            StubExactResults(finder, finderOptions, exactResults);
            StubSubstringResults(finder, finderOptions, substringResults);

            Assert.Throws <AmbiguousException>(() => ResolveQuery(finder));
        }
Exemple #14
0
        public void When_there_are_no_exact_but_multiple_substring_matches_it_returns_the_first_substring_match()
        {
            var finderOptions    = FinderOptions();
            var finder           = new StubElementFinder(finderOptions);
            var exactResults     = new List <Element> ();
            var substringResults = new List <Element> {
                new StubElement(), new StubElement()
            };

            StubExactResults(finder, finderOptions, exactResults);
            StubSubstringResults(finder, finderOptions, substringResults);

            var results = ResolveQuery(finder);

            Assert.That(results, Is.SameAs(substringResults.First()));
        }
        public void When_there_are_no_substring_matches_it_throws_missing_exception()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions, queryDescription: "something from StubElementFinder");

            StubSubstringResults(finder, finderOptions, new List<ElementFound>());

            try
            {
                ResolveQuery(finder);
                Assert.Fail("Expected missing html exception");
            }
            catch (MissingHtmlException ex)
            {
                Assert.That(ex.Message, Is.EqualTo("Unable to find something from StubElementFinder"));
            }
        }
        public void When_there_are_no_exact_matches_it_throws_missing_exception_and_only_looks_for_exact()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions, queryDescription: "something from StubElementFinder");

            StubExactResults(finder, finderOptions, new List <Element>());

            try
            {
                ResolveQuery(finder);
                Assert.Fail("Expected missing html exception");
            }
            catch (MissingHtmlException ex)
            {
                Assert.That(ex.Message, Is.EqualTo("Unable to find something from StubElementFinder"));
            }
        }
        public void When_there_are_no_exact_matches_But_the_finder_does_not_support_substring_text_matching_It_doesnt_bother_trying_substrings()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions, queryDescription: "something from StubElementFinder",
                supportsSubstringTextMatching: false);

            StubExactResults(finder, finderOptions, new List<Element>());

            try
            {
                ResolveQuery(finder);
                Assert.Fail("Expected missing html exception");
            }
            catch (MissingHtmlException ex)
            {
                Assert.That(ex.Message, Is.EqualTo("Unable to find something from StubElementFinder"));
            }
        }
Exemple #18
0
        public void When_there_are_no_exact_matches_But_the_finder_does_not_support_substring_text_matching_It_doesnt_bother_trying_substrings()
        {
            var finderOptions = FinderOptions();
            var finder        = new StubElementFinder(finderOptions, queryDescription: "something from StubElementFinder",
                                                      supportsSubstringTextMatching: false);

            StubExactResults(finder, finderOptions, new List <Element>());

            try
            {
                ResolveQuery(finder);
                Assert.Fail("Expected missing html exception");
            }
            catch (MissingHtmlException ex)
            {
                Assert.That(ex.Message, Is.EqualTo("Unable to find something from StubElementFinder"));
            }
        }
        public void When_there_is_no_exact_match_but_multiple_substring_matches_it_throws_ambiguous_exception ()
        {
            var finderOptions = FinderOptions();
            var finder = new StubElementFinder(finderOptions);

            var exactResults = new List<Element> ();
            var substringResults = new List<Element> { new StubElement(), new StubElement() };
            StubExactResults(finder, finderOptions, exactResults);
            StubSubstringResults(finder, finderOptions, substringResults);

            Assert.Throws<AmbiguousException>(() => ResolveQuery(finder));
        }
Exemple #20
0
 protected static void StubExactResults(StubElementFinder finder, Options finderOptions, IEnumerable <ElementFound> exactResults)
 {
     finder.StubbedFindResults[Options.Merge(Options.Exact, finderOptions)] = exactResults;
 }
 protected static void StubSubstringResults(StubElementFinder finder, Options finderOptions, IEnumerable <Element> exactResults)
 {
     finder.StubbedFindResults[Options.Merge(Options.Substring, finderOptions)] = exactResults;
 }
 protected static Element ResolveQuery(StubElementFinder finder)
 {
     var strategy = new FinderOptionsDisambiguationStrategy();
     var results = strategy.ResolveQuery(finder);
     return results;
 }
 protected static void StubSubstringResults(StubElementFinder finder, Options finderOptions, IEnumerable<Element> exactResults)
 {
     finder.StubbedFindResults[Options.Merge(Options.Substring, finderOptions)] = exactResults;
 }
Exemple #24
0
 protected static void StubExactResults(StubElementFinder finder, Options finderOptions, IEnumerable<ElementFound> exactResults)
 {
     finder.StubbedFindResults[Options.Merge(Options.Exact,finderOptions)] = exactResults;
 }