Beispiel #1
0
        public void TryGetElementByID_Returns_Strongly_Typed_Elements_When_Found()
        {
            var primitive = new Primitive();

            var collection = new ImmlElement();
            collection.Add(primitive);

            Primitive outPrimitive = null;
            var found = collection.TryGetElementByID<Primitive>(primitive.ID, out outPrimitive);

            Assert.True(found);
            Assert.Equal(primitive, outPrimitive);
        }
Beispiel #2
0
        public void TryGetElementByID_Returns_An_ImmlElement_When_Found()
        {
            var primitive = new Primitive();

            var collection = new ImmlElement();
            collection.Add(primitive);

            ImmlElement outElement = null;
            var found = collection.TryGetElementByID(primitive.ID, out outElement);

            Assert.True(found);
            Assert.Equal(primitive, outElement);
        }
Beispiel #3
0
        public void TryGetElementByID_Returns_False_When_An_Element_With_The_Specified_ID_Is_Not_Found()
        {
            var name = "PrimitiveElement";

            var primitive = new Primitive();
            primitive.Name = name;

            var collection = new ImmlElement();
            collection.Add(primitive);

            ImmlElement outElement = null;
            var found = collection.TryGetElementByID(-1, out outElement);

            Assert.False(found);
            Assert.Null(outElement);
        }
Beispiel #4
0
        public void Nested_Elements_In_A_Deep_Hierarchy_Can_Be_Found_Via_A_Query_To_The_Parent_Collection_Using_TryGetElementByID()
        {
            var nestDepth = 10;
            var parentName = "parent";
            var childName = "child";

            var parent = new ImmlElement { Name = parentName };
            var addTo = parent;
            var validIds = new List<int>();

            //nest elements 'nestDepth' deep
            for (int i = 0; i < nestDepth; i++)
            {
                //dynamically nest children inside the previously created element
                var toAdd = new ImmlElement { Name = childName + i };
                addTo.Add(toAdd);
                validIds.Add(toAdd.ID);

                //switch the parent to be the just added element
                addTo = toAdd;
            }

            //at this point, the parent should have inherited all of the child names
            foreach (var id in validIds)
            {
                ImmlElement outElement = null;
                Assert.True(parent.TryGetElementByID(id, out outElement));
            }
        }