Exemple #1
0
        public void TryGetElementByName_Returns_Strongly_Typed_Elements_When_Found()
        {
            var name = "PrimitiveElement";

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

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

            Primitive outPrimitive = null;
            var found = collection.TryGetElementByName<Primitive>(name, out outPrimitive);

            Assert.True(found);
            Assert.Equal(primitive, outPrimitive);
        }
Exemple #2
0
        public void TryGetElementByName_Returns_An_ImmlElement_When_Found()
        {
            var name = "PrimitiveElement";

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

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

            ImmlElement outElement = null;
            var found = collection.TryGetElementByName(name, out outElement);

            Assert.True(found);
            Assert.Equal(primitive, outElement);
        }
Exemple #3
0
        public void TryGetElementByName_Returns_False_When_An_Element_With_The_Specified_Name_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.TryGetElementByName(Guid.NewGuid().ToString(), out outElement);

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

            var parent = new ImmlElement { Name = parentName };
            var addTo = parent;

            //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);

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

            //at this point, the parent should have inherited all of the child names
            for (int i = 0; i < nestDepth; i++)
            {
                ImmlElement outElement = null;
                Assert.True(parent.TryGetElementByName(childName + i, out outElement));
            }
        }