AreEqual() public static method

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order.
public static AreEqual ( IEnumerable expected, IEnumerable actual ) : void
expected IEnumerable The first IEnumerable of objects to be considered
actual IEnumerable The second IEnumerable of objects to be considered
return void
Example #1
0
        public void CookieDictionaryToHeaderNull()
        {
            // null cookie dictionary
            var expectedCookieHeader = "";

            CollectionAssert.AreEqual(expectedCookieHeader, CookieUtil.CookieDictionaryToHeader(null));
        }
Example #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);
        }
Example #3
0
        public void Filter_String_Interface()
        {
            string[] str      = { "numbers", "predicate", "numbs", "corns" };
            string[] expected = { "numbs", "corns" };

            CollectionAssert.AreEqual(str.Filter(new StringPredicate()), expected);
        }
Example #4
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]);
            }
        }
Example #5
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);
        }
Example #6
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]);
            }
        }
Example #7
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);
        }
Example #8
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.");
        }
Example #9
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);
        }
Example #10
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");
        }
        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");
        }
Example #12
0
        public void CookieHeaderToDictionaryNull()
        {
            // null cookie header
            var expectedCookieDictionary = new Dictionary <string, string>();

            CollectionAssert.AreEqual(expectedCookieDictionary, CookieUtil.CookieHeaderToDictionary(null));
        }
Example #13
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);
        }
Example #14
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);
        }
Example #15
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());
        }
Example #16
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());
        }
Example #17
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));
        }
        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");
        }
Example #19
0
        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;
        }
Example #20
0
        public void CookieDictionaryToHeaderGood()
        {
            // valid cookies with non-alpha characters in the value
            var cookieDictionary = new Dictionary <string, string>
            {
                { "__cfduid", "d6237f041586694295" }, { "__cf_bm", "TlOng/xyqckk-TMen38z+0RFYA7YA=" }
            };
            var expectedCookieHeader = "__cfduid=d6237f041586694295; __cf_bm=TlOng/xyqckk-TMen38z+0RFYA7YA=";

            CollectionAssert.AreEqual(expectedCookieHeader, CookieUtil.CookieDictionaryToHeader(cookieDictionary));
        }
Example #21
0
        public void QueryByClass()
        {
            var dom = CreateDom();

            string selector = ".links";

            Assert.AreEqual(2, dom[selector].Length);
            CollectionAssert.AreEqual(
                dom[selector].ToList(),
                ((IDomIndexSimple)dom.Document.DocumentIndex).QueryIndex(GetKey(selector)).ToList()
                );
        }
Example #22
0
        public void AutoCreateHead()
        {
            string test = @"<html>
            <script id=script1 type=""text/javascript"" src=""stuff""></script>
            <div id=div1>This should be in the body.</div>";

            var dom = CQ.CreateDocument(test);

            Assert.AreEqual(dom["#script1"][0], dom["head > :first-child"][0]);
            Assert.AreEqual(dom["#div1"][0], dom["body > :first-child"][0]);
            CollectionAssert.AreEqual(Arrays.String("HEAD", "BODY"), dom["html"].Children().NodeNames());
        }
Example #23
0
        public void QueryByNodeName()
        {
            var dom = CreateDom();

            string selector = "span";

            Assert.AreEqual(3, dom[selector].Length);
            CollectionAssert.AreEqual(
                dom[selector].ToList(),
                ((IDomIndexSimple)dom.Document.DocumentIndex).QueryIndex(GetKey("+" + selector)).ToList()
                );
        }
Example #24
0
        public void GetAllCouponsTest()
        {
            var actualCoupons = feedScraper.GetAll(0, 0); //.ToList()

//            var serialized = JsonConvert.SerializeObject(actualCoupons);
//            File.WriteAllText(CouponFilePath, serialized);

            var           expectedCouponsJson = File.ReadAllText(CouponFilePath, Encoding.UTF8);
            List <Coupon> expectedCoupons     = JsonConvert.DeserializeObject <List <Coupon> >(expectedCouponsJson);

            CollectionAssert.AreEqual(expectedCoupons, actualCoupons);
        }
Example #25
0
        public void Issue61_Closest()
        {
            var html  = "<div id=outer><div id=div1><span></span></div><div id=div2><span></span></div></div>";
            var doc   = CQ.CreateFragment(html);
            var spans = doc["span"];

            Assert.AreEqual(2, spans.Length);

            var closestDivs = spans.Closest("div");

            Assert.AreEqual(2, closestDivs.Length);
            CollectionAssert.AreEqual(Arrays.String("div1", "div2"), closestDivs.Select(item => item.Id));
        }
Example #26
0
        public void QueryByAttribute()
        {
            var    dom      = CreateDom();
            string selector = "[data]";
            string key      = "data";

            Assert.AreEqual(2, dom[selector].Length);

            CollectionAssert.AreEqual(
                dom[selector].ToList(),
                ((IDomIndexSimple)dom.Document.DocumentIndex).QueryIndex(GetKey("!" + key)).ToList()
                );
        }
Example #27
0
        public void EverythingButFistLast()
        {
            var res = Dom["#hlinks-user > :not(:first-child,:last-child)"];
            IEnumerable <IDomElement> res2 = Dom["#hlinks-user"].Children().Not(":first-child,:last-child").Elements;

            CollectionAssert.AreEqual(res, res2);

            var hlinks = Dom["#hlinks-user"][0];
            var lastEl = hlinks.LastElementChild;

            res2 = hlinks.ChildElements.Skip(1).TakeWhile(item => item != lastEl);

            CollectionAssert.AreEqual(res, res2);
        }
Example #28
0
        public void CookieHeaderToDictionaryDuplicateKeys()
        {
            // cookie with duplicate keys and whitespace separator instead of ;
            // this cookie is not valid according to the standard, but it occurs in Jackett because we are concatenating
            // cookies in many parts of the code (and we are not doing it well). this is safe because the whitespace
            // can't be part of the key nor the value.
            var cookieHeader             = "__cfduid=d6237f041586694295; __cf_bm=TlOng/xyqckk-TMen38z+0RFYA7YA= __cf_bm=test";
            var expectedCookieDictionary = new Dictionary <string, string>
            {
                { "__cfduid", "d6237f041586694295" },
                { "__cf_bm", "test" } // we always assume the latest value is the most recent
            };

            CollectionAssert.AreEqual(expectedCookieDictionary, CookieUtil.CookieHeaderToDictionary(cookieHeader));
        }
Example #29
0
        public void ClassNameCase()
        {
            var dom = CQ.CreateFragment("<div class=\"class1 CLASS2 claSS3\" x=\"y\" />");
            var el  = dom.Select("div").FirstElement();

            Assert.AreEqual(3, el.Classes.Count());
            CollectionAssert.AreEqual(Arrays.String("class1", "CLASS2", "claSS3"), el.Classes.ToList());

            Assert.AreEqual(0, dom[".class2"].Length);
            Assert.AreEqual(1, dom[".CLASS2"].Length);

            el = CQ.CreateFragment("<div class=\"class CLASS\" />").Select("div").FirstElement();

            Assert.AreEqual(2, el.Classes.Count());
            CollectionAssert.AreEqual(Arrays.String("class", "CLASS"), el.Classes.ToList());
        }
        public void ChildFromContext()
        {
            var siblingFirst = document.GetElementById("siblingfirst");

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

            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");
        }