Exemple #1
0
        public void CookieDictionaryToHeaderNull()
        {
            // null cookie dictionary
            var expectedCookieHeader = "";

            CollectionAssert.AreEqual(expectedCookieHeader, CookieUtil.CookieDictionaryToHeader(null));
        }
Exemple #2
0
        public void Matrix_Add_SquareMatrix()
        {
            var array = new[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
            };
            var arrayExpected = new[, ] {
                { 2, 4, 6 }, { 8, 10, 12 }, { 14, 16, 18 }
            };
            Matrix <int> lhs      = new SquareMatrix <int>(array);
            var          result   = lhs.Add(lhs);
            Matrix <int> expected = new SquareMatrix <int>(arrayExpected);

            CollectionAssert.AreEqual(expected, result);

            array = new[, ] {
                { 1, 0, 0 }, { 0, 5, 0 }, { 0, 0, 9 }
            };
            arrayExpected = new[, ] {
                { 2, 0, 0 }, { 0, 10, 0 }, { 0, 0, 18 }
            };
            lhs = new SquareMatrix <int>(array);
            Matrix <int> rhs = new DiagonaleMatrix <int>(array);

            result   = lhs.Add(rhs);
            expected = new SquareMatrix <int>(arrayExpected);
            CollectionAssert.AreEqual(expected, result);

            rhs    = new SymmetricMatrix <int>(array);
            result = lhs.Add(rhs);
            CollectionAssert.AreEqual(expected, result);
        }
Exemple #3
0
        public void GetNounDeclensionName_KidsClubSelect_Success()
        {
            var obj     = RulesPrivate.InvokeStatic(GetNounDeclensionName, "клуб");
            var listObj = (List <string>)obj;
            var result  = listObj.Select(word => $"{word} для детей").ToList();
            var kids    = listObj.Select(word => $"{word} для ребёнка").ToList();

            result.AddRange(kids);
            result.AddRange(kids.Select(word =>
                                        word.Replace('ё', 'е'))); // include typos

            var expected = new List <string>
            {
                "клуб для детей", "клуба для детей", "клубу для детей", "клубом для детей", "клубе для детей",
                "клубы для детей", "клубов для детей", "клубам для детей", "клубами для детей", "клубах для детей",
                "клуб для ребёнка", "клуба для ребёнка", "клубу для ребёнка", "клубом для ребёнка", "клубе для ребёнка",
                "клубы для ребёнка", "клубов для ребёнка", "клубам для ребёнка", "клубами для ребёнка",
                "клубах для ребёнка",
                "клуб для ребенка", "клуба для ребенка", "клубу для ребенка", "клубом для ребенка", "клубе для ребенка",
                "клубы для ребенка", "клубов для ребенка", "клубам для ребенка", "клубами для ребенка",
                "клубах для ребенка"
            };

            CollectionAssert.AreEquivalent(expected, result);
        }
Exemple #4
0
        public void Filter_String_Predicate()
        {
            string[] str      = { "numbers", "predicate", "numbs", "corn" };
            string[] expected = { "numbers", "numbs" };

            CollectionAssert.AreEqual(str.Filter(x => x.Contains("num")), expected);
        }
Exemple #5
0
        public void ParentsUntil_Sequence()
        {
            var res = Dom[".badge2"].ParentsUntil("[id]");

            // will stop at the first element with an ID, only the immediate parent has no id
            CollectionAssert.AreEqual(expected.Slice(0, 1), res);
        }
Exemple #6
0
        public void CookieHeaderToDictionaryNull()
        {
            // null cookie header
            var expectedCookieDictionary = new Dictionary <string, string>();

            CollectionAssert.AreEqual(expectedCookieDictionary, CookieUtil.CookieHeaderToDictionary(null));
        }
Exemple #7
0
        public void Class()
        {
            t("Class Selector", ".blog", Arrays.String("mark", "simon"));
            t("Class Selector", ".GROUPS", Arrays.String("groups"));
            t("Class Selector", ".blog.link", Arrays.String("simon"));
            t("Class Selector w/ Element", "a.blog", Arrays.String("mark", "simon"));
            t("Parent Class Selector", "p .blog", Arrays.String("mark", "simon"));

            t("Class selector using UTF8", ".台北Táiběi", Arrays.String("utf8class1"));
            t("Class selector using UTF8", ".台北", Arrays.String("utf8class1", "utf8class2"));
            t("Class selector using UTF8", ".台北Táiběi.台北", Arrays.String("utf8class1"));
            t("Class selector using UTF8", ".台北Táiběi, .台北", Arrays.String("utf8class1", "utf8class2"));
            t("Descendant class selector using UTF8", "div .台北Táiběi", Arrays.String("utf8class1"));
            t("Child class selector using UTF8", "form > .台北Táiběi", Arrays.String("utf8class1"));

            t("Escaped Class", ".foo\\:bar", Arrays.String("foo:bar"));
            t("Escaped Class", ".test\\.foo\\[5\\]bar", Arrays.String("test.foo[5]bar"));
            t("Descendant scaped Class", "div .foo\\:bar", Arrays.String("foo:bar"));
            t("Descendant scaped Class", "div .test\\.foo\\[5\\]bar", Arrays.String("test.foo[5]bar"));
            t("Child escaped Class", "form > .foo\\:bar", Arrays.String("foo:bar"));
            t("Child escaped Class", "form > .test\\.foo\\[5\\]bar", Arrays.String("test.foo[5]bar"));

            var div = document.CreateElement("div");

            div.InnerHTML = "<div class='test e'></div><div class='test'></div>";
            CollectionAssert.AreEqual(Dom[".e", div], Arrays.Create(div.FirstChild), "Finding a second class.");

            div.LastChild.ClassName = "e";

            CollectionAssert.AreEqual(Dom[".e", div], Arrays.Create(div.FirstChild, div.LastChild), "Finding a modified class.");
        }
Exemple #8
0
        public void Filter_String_Interface()
        {
            string[] str      = { "numbers", "predicate", "numbs", "corns" };
            string[] expected = { "numbs", "corns" };

            CollectionAssert.AreEqual(str.Filter(new StringPredicate()), expected);
        }
Exemple #9
0
        public void JaggedArrayExtencion_SortByInterface_IncreasingSum()
        {
            int[][] sourceInts =
            {
                new[] {  6,  2,  3, 6, 7, 15 },
                new[] {  1,  2,  3,4 },
                new[] { 33, 18, 44,15 },
                new[] { 15, 23, 61 }
            };

            int[][] execute =
            {
                new[] {  1,  2,  3,  4 },
                new[] {  6,  2,  3,6, 7, 15 },
                new[] { 15, 23,61 },
                new[] { 33, 18, 44, 15 }
            };

            sourceInts.SortByInterface(new IncreasingCondition());

            for (int i = 0; i < sourceInts.Length; i++)
            {
                CollectionAssert.AreEqual(sourceInts[i], execute[i]);
            }
        }
        public void ChildFromContext()
        {
            var siblingFirst = document.GetElementById("siblingfirst");


            CollectionAssert.AreEqual(Sizzle["~ em", siblingFirst], q("siblingnext", "siblingthird"), "Element Preceded By with a context.");
            CollectionAssert.AreEqual(Sizzle["+ em", siblingFirst], q("siblingnext"), "Element Directly Preceded By with a context.");
            CollectionAssert.AreEqual(Sizzle["~ em:first", siblingFirst], q("siblingnext"), "Element Preceded By positional with a context.");

            var en = document.GetElementById("en");

            CollectionAssert.AreEqual(Sizzle["+ p, a", en], q("yahoo", "sap"), "Compound selector with context, beginning with sibling test.");
            CollectionAssert.AreEqual(Sizzle["a, + p", en], q("yahoo", "sap"), "Compound selector with context, containing sibling test.");

            t("Multiple combinators selects all levels", "#siblingTest em *", Arrays.String("siblingchild", "siblinggrandchild", "siblinggreatgrandchild"));
            t("Multiple combinators selects all levels", "#siblingTest > em *", Arrays.String("siblingchild", "siblinggrandchild", "siblinggreatgrandchild"));
            t("Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", Arrays.String("siblingspan"));
            t("Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", Arrays.String());


            Assert.AreEqual(Sizzle["#listWithTabIndex"].Length, 1, "Parent div for next test is found via ID (#8310)");
            Assert.AreEqual(Sizzle["#listWithTabIndex li:eq(2) ~ li"].Length, 1, "Find by general sibling combinator (#8310)");
            Assert.AreEqual(Sizzle["#__sizzle__"].Length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)");
            Assert.AreEqual(Sizzle["#listWithTabIndex"].Length, 1, "Parent div for previous test is still found via ID (#8310)");

            t("Verify deep class selector", "div.blah > p > a");

            t("No element deep selector", "div.foo > span > a");
        }
Exemple #11
0
        public void GetMovementsByDateRange_MustReturns_MovementsInRange()
        {
            Account account = new Account();

            Expense ex1 = new Expense(1, new DateTime(2013, 1, 1));               // skip
            Expense ex2 = new Expense(1, new DateTime(2013, 1, 10));              // keep
            Expense ex3 = new Expense(1, new DateTime(2013, 1, 15));              // keep
            Expense ex4 = new Expense(1, new DateTime(2013, 2, 1));               // keep
            Expense ex5 = new Expense(1, new DateTime(2013, 2, 10));              // keep
            Expense ex6 = new Expense(1, new DateTime(2013, 2, 12));              // skip

            var from = new DateTime(2013, 1, 10);
            var to   = new DateTime(2013, 2, 10);

            account.AddMovements(new List <IMovement>()
            {
                ex1, ex2, ex3, ex4, ex5, ex6
            });

            IEnumerable <IMovement> movements = account.GetMovementsByDateRange(from, to);

            CollectionAssert.Contains(movements, ex2);
            CollectionAssert.Contains(movements, ex3);
            CollectionAssert.Contains(movements, ex4);
            CollectionAssert.Contains(movements, ex5);
            CollectionAssert.DoesNotContain(movements, ex1);
            CollectionAssert.DoesNotContain(movements, ex6);
        }
Exemple #12
0
        private void AssertAllMethodsWereLocated(MethodInfo[] expected, Matcher matcher, params Type[] typesToBuildCompositeTypeFrom)
        {
            IList <MethodInfo> matches = new CompositeType(typesToBuildCompositeTypeFrom)
                                         .GetMatchingMethods(matcher, false);

            CollectionAssert.IsSubsetOf(expected, matches);
        }
Exemple #13
0
        private void AssertMethodWasLocated(MethodInfo expected, Matcher matcher, params Type[] typesToBuildCompositeTypeFrom)
        {
            IList <MethodInfo> matches = new CompositeType(typesToBuildCompositeTypeFrom)
                                         .GetMatchingMethods(matcher, false);

            CollectionAssert.Contains(matches, expected);
        }
Exemple #14
0
        public void PrimaryTypeAndAdditionalInterfaceTypesIdentifiedAndOrderedCorrectlyWhenClassTypeSpecified()
        {
            CompositeType type = new CompositeType(new[] { typeof(IDisposable), typeof(ParentClass), typeof(IEnumerable) });

            Assert.AreEqual(typeof(ParentClass), type.PrimaryType, "Incorrect PrimaryType");
            CollectionAssert.AreEqual(new[] { typeof(IEnumerable), typeof(IDisposable) }, type.AdditionalInterfaceTypes, "Incorrect AdditionalInterfaceTypes");
        }
Exemple #15
0
        public void PrimaryTypeAndAdditionalInterfaceTypesCorrectWhenOnlyOneTypeSpecified()
        {
            CompositeType type = new CompositeType(new[] { typeof(IDisposable) });

            Assert.AreEqual(typeof(IDisposable), type.PrimaryType, "Incorrect PrimaryType");
            CollectionAssert.IsEmpty(type.AdditionalInterfaceTypes, "Incorrect AdditionalInterfaceTypes");
        }
Exemple #16
0
        public void ReturnAListOfTheCellsNeighbours()
        {
            var universe = new Universe();

            var world = universe.CreateEmptyWorld(4, 4);

            var  neighbourFetcher = new NeighbourFetcher();
            Cell cell             = new Cell()
            {
                X = 1,
                Y = 1
            };
            var neighbours = neighbourFetcher.GetAllNeighbours(world, cell);

            var deadCell = new Cell()
            {
                State = false
            };

            var expected = new List <Cell>();

            for (var i = 0; i < 8; i++)
            {
                expected.Add(deadCell);
            }

            CollectionAssert.AreEqual(expected, neighbours);
        }
Exemple #17
0
        public void JaggedArrayExtencion_Sort_DecreasingMax()
        {
            int[][] sourceInts =
            {
                new[] {  6,  2,  3, 6, 7, 15 },
                new[] {  1,  2,  3,4 },
                new[] { 33, 18, 44,15 },
                new[] { 15, 23, 61 }
            };

            int[][] execute =
            {
                new[] { 15, 23, 61 },
                new[] { 33, 18,44, 15 },
                new[] {  6,  2,3, 6, 7, 15 },
                new[] {  1,  2,3, 4 }
            };

            sourceInts.Sort(new DecreasingMax());

            for (int i = 0; i < sourceInts.Length; i++)
            {
                CollectionAssert.AreEqual(sourceInts[i], execute[i]);
            }
        }
Exemple #18
0
        public void ParentsUntil_Filtered()
        {
            var res = Dom[".badge2"].ParentsUntil("body", "[id]");

            // will only match the hlinks-user one (nothing else has an ID)
            //
            CollectionAssert.AreEqual(expected.Slice(1, 2), res);
        }
Exemple #19
0
        public void GivenStatementAndWordDictionaryCheckStatementWordSplit(bool removePunctuation, string[] wordDictionary)
        {
            var res = "Hello, I am Slava!".ToWordArray(removePunctuation);

            CollectionAssert.AllItemsAreInstancesOfType(res, typeof(string));
            CollectionAssert.AllItemsAreNotNull(res);
            CollectionAssert.AreEquivalent(res, wordDictionary);
        }
Exemple #20
0
        public void NthChildOfType_Children()
        {
            var res = Dom["body > span > :nth-of-type(1)"];

            CollectionAssert.AreEqual(
                Dom[".profile-triangle, .profile-link, input[name=stuff], #textarea"],
                res);
        }
Exemple #21
0
        public void GetNounDeclension_WordWithoutPluralAndWithDuplicates_Success()
        {
            var obj      = RulesPrivate.InvokeStatic(GetNounDeclensionName, "еда");
            var expected = new List <string> {
                "еда", "еды", "еде", "еду", "едой"
            };

            CollectionAssert.AreEquivalent(expected, (List <string>)obj);
        }
Exemple #22
0
        public void Add_IncomeOnAccount_MustBeAdded()
        {
            Account account = new Account();
            Income  income  = new Income(100, DateTime.Today);

            account.AddIncome(income);

            CollectionAssert.Contains(account.Movements, income);
        }
Exemple #23
0
        public void Add_ExpenseOnAccount_MustBeAdded()
        {
            Account account = new Account();
            Expense ex      = new Expense(5, DateTime.Today);

            account.AddExpense(ex);

            CollectionAssert.Contains(account.Movements, ex);
        }
Exemple #24
0
        public void SiblingsSelf()
        {
            var dom = CQ.Create("<table><tr id=1><tr id=2><tr id=3></table>");

            var res = dom["table tr+tr"];

            Assert.AreEqual(2, res.Length);
            CollectionAssert.AreEqual(Arrays.String("2", "3"), res.Select(item => item.Id).ToList());
        }
Exemple #25
0
        public void CookieHeaderToDictionaryMalformed()
        {
            // malformed cookies
            var cookieHeader             = "__cfduidd6237f041586694295; __cf_;bm TlOng; good_cookie=value";
            var expectedCookieDictionary = new Dictionary <string, string> {
                { "good_cookie", "value" },
            };

            CollectionAssert.AreEqual(expectedCookieDictionary, CookieUtil.CookieHeaderToDictionary(cookieHeader));
        }
Exemple #26
0
        public void DisconnectedBefore()
        {
            string s   = "This is <b> a big</b> text";
            var    dom = CQ.Create(s);
            var    res = dom[dom.Document];
            var    el  = dom.Document.CreateElement("code");

            res = res.Before(el);
            CollectionAssert.AreEqual(Objects.Enumerate(el, dom.Document), res.ToList());
        }
Exemple #27
0
        public void GetPhraseDeclensionName_KidsFood_Success()
        {
            var obj      = RulesPrivate.InvokeStatic(GetPhraseDeclensionReducedName, "детская еда");
            var expected = new List <string>
            {
                "детская еда", "детской еды", "детскую еду", "детской едой", "детской еде"
            };

            CollectionAssert.AreEquivalent(expected, (List <string>)obj);
        }
        public void AdjacentFromContext()
        {
            var nothiddendiv = document.GetElementById("nothiddendiv");

            CollectionAssert.AreEqual(Sizzle["> :first", nothiddendiv], q("nothiddendivchild"), "Verify child context positional selctor");
            CollectionAssert.AreEqual(Sizzle["> :eq(0)", nothiddendiv], q("nothiddendivchild"), "Verify child context positional selctor");
            CollectionAssert.AreEqual(Sizzle["> *:first", nothiddendiv], q("nothiddendivchild"), "Verify child context positional selctor");

            t("Non-existant ancestors", ".fototab > .thumbnails > a");
        }
        public void MatchesSizzleSelect()
        {
            var opt = document.GetElementById("option1a");

            opt.SetAttribute("test", "");

            Assert.IsTrue(match(opt, "[id*=option1][type!=checkbox]"), "Attribute Is Not Equal Matches");
            Assert.IsTrue(match(opt, "[id*=option1]"), "Attribute With No Quotes Contains Matches");
            Assert.IsTrue(match(opt, "[test=]"), "Attribute With No Quotes No Content Matches");
            Assert.IsTrue(!match(opt, "[test^='']"), "Attribute with empty string value does not match startsWith selector (^=)");
            Assert.IsTrue(match(opt, "[id=option1a]"), "Attribute With No Quotes Equals Matches");
            Assert.IsTrue(match(document.GetElementById("simon1"), "a[href*=#]"), "Attribute With No Quotes Href Contains Matches");

            t("Empty values", "#select1 option[value='']", Arrays.String("option1a"));
            t("Empty values", "#select1 option[value!='']", Arrays.String("option1b", "option1c", "option1d"));

            t("Select options via :selected", "#select1 option:selected", Arrays.String("option1a"));
            t("Select options via :selected", "#select2 option:selected", Arrays.String("option2d"));
            t("Select options via :selected", "#select3 option:selected", Arrays.String("option3b", "option3c"));

            t("Grouped Form Elements", "input[name='foo[bar]']", Arrays.String("hidden2"));

            //Uncomment if the boolHook is removed
            // [CsQuery] checked should match the selector after checked is set to true

            IDomElement check2 = document.GetElementById("check2");

            check2.Checked = true;
            // the sizzle test said assert.AreNotEqual
            Assert.IsTrue(match(check2, "[checked]"), "Dynamic boolean attributes match when they should with Sizzle.matches (#11115)");

            //Make sure attribute value quoting works correctly. See: #6093

            var attrbad = jQuery("<input type=\"hidden\" value=\"2\" name=\"foo.baz\" id=\"attrbad1\"/><input type=\"hidden\" value=\"2\" name=\"foo[baz]\" id=\"attrbad2\"/>")
                          .AppendTo("body");

            t("Find escaped attribute value", "input[name=foo\\.baz]", Arrays.String("attrbad1"));
            t("Find escaped attribute value", "input[name=foo\\[baz\\]]", Arrays.String("attrbad2"));

            t("input[type=text]", "#form input[type=text]", Arrays.String("text1", "text2", "hidden2", "name"));
            t("input[type=search]", "#form input[type=search]", Arrays.String("search"));

            attrbad.Remove();

            //   #6428
            t("Find escaped attribute value", "#form input[name=foo\\[bar\\]]", Arrays.String("hidden2"));

            //#3279
            var div = document.CreateElement("div");

            div.InnerHTML = "<div id='foo' xml:test='something'></div>";

            CollectionAssert.AreEqual(Sizzle["[xml\\:test]", div], Arrays.Create <IDomObject>(div.FirstChild), "Finding by attribute with escaped characters.");
            div = null;
        }
        public void TestEnabledNodes()
        {
            var shouldBeEnabled    = new ValidEnabledStatePropertyNode();
            var shouldNotBeEnabled = new DisabledStatePropertyNode();

            NodeCollection initializedNodes = Node.InitializedNodes;
            NodeCollection enabledNodes     = this.nodeSupervisor.FilterEnabledNodes(initializedNodes);

            CollectionAssert.Contains(enabledNodes, shouldBeEnabled);
            CollectionAssert.DoesNotContain(enabledNodes, shouldNotBeEnabled);
        }