Ejemplo n.º 1
0
        public void UnicleNameTest()
        {
            var t = new NamedList <NamedElement>();

            var el = new NamedElement();

            el.Rename("dsa");

            var el2 = new NamedElement();

            el2.Rename("dsa");

            t.Add(el);

            try
            {
                t.Add(el);
            }
            catch (InvalidOperationException)
            {
                try
                {
                    t[0] = el2;
                }
                catch (InvalidOperationException)
                {
                    return;
                }
            }

            throw new Exception("Exception has not throwed by NamedList");
        }
Ejemplo n.º 2
0
        public void BasicTest()
        {
            var list = new NamedList <NamedElement>();

            var el = new NamedElement();

            list.Add(el);

            var el2 = new NamedElement();

            el2.Rename("asd");
            list.Add(el2);

            //Test

            //Get by indexer
            Assert.AreEqual(el, list[null], $"el:{el}, list[null]:{list[null]}");
            Assert.AreEqual(el2, list["asd"], $"el2:{el2}, list[\"asd\"]:{list["asd"]}");

            //Get by method
            Assert.AreEqual(el, list.GetElementByName(null), $"el:{el}, " +
                            $"list.GetElementByName(null){list.GetElementByName(null)}");

            Assert.AreEqual(el2, list.GetElementByName("asd"), $"el2:{el2}, " +
                            $"list.GetElementByName(\"asd\"){list.GetElementByName("asd")}");

            //Set
            var el3 = new NamedElement();

            el3.Rename("qwe");
            list[null] = el3;

            Assert.IsTrue(!list.Contains(el));
            Assert.AreEqual(el3, list["qwe"], $"el3:{el3}, list[\"qwe\"]:{list["qwe"]}");
            Assert.AreEqual(el2, list["asd"], $"el2:{el2}, list[\"asd\"]:{list["asd"]}");
        }