Beispiel #1
0
        /// <summary>
        /// Finds the parent container for the given element. Returns null if no parent is specified.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static IImmlContext FindParentContainer(ImmlElement element)
        {
            if (element.Parent == null && element is IImmlContext)
                return element as IImmlContext;
            else if (element.Parent == null)
                return null;

            return _FindParent(element);
        }
Beispiel #2
0
        public override void Add(ImmlElement element)
        {
            base.Add(element);

            if (element is IVisibleElement)
            {
                _VisibleElements.Add(element);
            }
        }
Beispiel #3
0
        public void Changing_An_Elements_Name_That_Exists_In_An_ImmlElement_Frees_Up_That_Name_To_Be_Reused()
        {
            var name = "name1";
            var altName = "altName";

            var element1 = new ImmlElement { Name = name };
            var element2 = new ImmlElement { Name = name };

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

            Assert.Equal(name, element1.Name);
            element1.Name = altName;
            Assert.Equal(altName, element1.Name);

            collection.Add(element2);
            Assert.Equal(name, element2.Name);
        }
Beispiel #4
0
        public void Adding_One_Collection_As_The_Child_Of_Another_Guarantees_Names_Are_Unique()
        {
            var childName = "child1";
            var childCollectionName = "childCollection";

            var parentCollection = new ImmlElement();

            var childCollection = new ImmlElement { Name = childCollectionName };
            childCollection.Add(new ImmlElement { Name = childName });

            var childCollection2 = new ImmlElement();
            var childOfChildCollection2 = new ImmlElement { Name = childName };
            childCollection2.Add(childOfChildCollection2);

            parentCollection.Add(childCollection);
            parentCollection.Add(childCollection2);

            Assert.NotEqual(childName, childOfChildCollection2.Name);
        }
Beispiel #5
0
        public void Changing_An_Elements_Name_That_Exists_In_An_ImmlElement_Means_The_Element_Is_Able_To_Be_Found_With_That_New_Name()
        {
            var name = "name1";
            var altName = "altName";

            var element = new ImmlElement { Name = name };

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

            collection.Add(element);

            Assert.Equal(name, element.Name);

            //switch out the name
            element.Name = altName;

            Assert.Equal(altName, element.Name);
            Assert.False(parentCollection.ContainsName(name));
            Assert.True(parentCollection.ContainsName(altName));
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void HasChildren_Is_True_When_One_Child_Has_Been_Added()
        {
            var element = new ImmlElement();

            element.Add(new ImmlElement());

            Assert.Equal(true, element.HasChildren);
        }
Beispiel #8
0
        public override void Remove(ImmlElement element)
        {
            base.Remove(element);

            if (element is IVisibleElement)
            {
                _VisibleElements.Remove(element);
            }
        }
Beispiel #9
0
        public override void Add(ImmlElement element)
        {
            base.Add(element);

            if (element is IPositionalElement)
            {
                _PositionalElements.Add(element as IPositionalElement);
            }
        }
Beispiel #10
0
        public void Elements_Must_Have_Globally_Unique_Names()
        {
            var name = "name1";

            var element1 = new ImmlElement { Name = name };
            var element2 = new ImmlElement { Name = name };

            var collection = new ImmlElement();
            collection.Add(element1);
            collection.Add(element2);

            Assert.NotEqual(name, element2.Name);
        }
Beispiel #11
0
        /// <summary>
        /// Returns true if the specified element is nested within a dock
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static bool IsDocked(ImmlElement element)
        {
            if (element is Video || element is Web)
                return (element.Parent != null && element.Parent.Parent != null && element.Parent.Parent.Parent != null && (element.Parent.Parent.Parent is Dock));

            return element.Parent is Dock;
        }
Beispiel #12
0
        public void ContainsName_Returns_False_When_A_Child_Element_With_That_Name_Does_Not_Exist()
        {
            var name = "name1";
            var collection = new ImmlElement();

            Assert.False(collection.ContainsName(name));
        }
Beispiel #13
0
        public void Nested_Elements_In_A_Deep_Hierarchy_Then_Added_To_A_Collection_Can_Be_Found_Via_A_Query_To_The_Collection()
        {
            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++)
            {
                var toAdd = new ImmlElement { Name = childName + i };
                addTo.Add(toAdd);

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

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

            //at this point, collection should inherit the names of the parent collection

            for (int i = 0; i < nestDepth; i++)
            {
                Assert.True(collection.ContainsName(childName + i));
            }
        }
Beispiel #14
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));
            }
        }
Beispiel #15
0
 public void ImmlElement_Has_No_Triggers_By_Default()
 {
     var element = new ImmlElement();
     Assert.Empty(element.GetTriggers());
 }
Beispiel #16
0
 public void ImmlElement_Has_No_Defines_By_Default()
 {
     var element = new ImmlElement();
     Assert.Empty(element.GetDefines());
 }
Beispiel #17
0
        public void HasChildren_Should_Be_False_When_One_Child_Is_Added_Then_Removed()
        {
            var parent = new ImmlElement();
            var child = new ImmlElement();

            parent.Add(child);
            parent.Remove(child);

            Assert.Equal(false, parent.HasChildren);
        }
Beispiel #18
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);
        }
Beispiel #19
0
        public void Removing_An_Element_From_An_ImmlElement_Frees_Up_That_Name_To_Be_Reused()
        {
            var name = "name1";

            var element1 = new ImmlElement { Name = name };
            var element2 = new ImmlElement { Name = name };

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

            Assert.Equal(name, element1.Name);
            collection.Remove(element1);

            collection.Add(element2);
            Assert.Equal(name, element2.Name);
        }
Beispiel #20
0
        public void Removing_A_Parent_Element_Correctly_Removes_Child_Element_Names_From_The_Used_Names()
        {
            var parentName = "parent";
            var childName = "child";
            var childOfChildName = "childOfChild";

            var parent = new ImmlElement { Name = parentName };
            parent.Add(new ImmlElement { Name = childName });

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

            collection.Remove(parent);
            Assert.Empty(collection.Elements);

            var child = new ImmlElement { Name = childName };
            collection.Add(child);
            Assert.Equal(childName, child.Name);

            var childOfChild = new ImmlElement { Name = childOfChildName };
            child.Add(childOfChild);

            Assert.True(collection.ContainsName(childName));
        }
Beispiel #21
0
        public void ContainsName_Returns_True_When_A_Child_Element_With_That_Name_Exists()
        {
            var name = "name1";

            var element1 = new ImmlElement { Name = name };

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

            Assert.True(collection.ContainsName(name));
        }
Beispiel #22
0
        public void Triggers_Can_Be_Retrieved_When_Present()
        {
            var element = new ImmlElement();
            var trigger = new Trigger();
            trigger.Target = Guid.NewGuid().ToString();
            trigger.Event = EventType.DragDrop;

            element.Add(trigger);

            Assert.Equal(1, element.GetTriggers().Count);
            Assert.Equal(trigger.Target, element.GetTriggers().First().Target);
            Assert.Equal(trigger.Event, element.GetTriggers().First().Event);
        }
Beispiel #23
0
        private static IImmlContext _FindParent(ImmlElement element)
        {
            if (element.Parent == null)
                return null;

            if (element.Parent is IImmlContext)
                return element.Parent as IImmlContext;

            return _FindParent(element.Parent);
        }
Beispiel #24
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 #25
0
        public static ElementType GetType(ImmlElement element)
        {
            if (element is Camera)
                return ElementType.Camera;

            if (element is Dock)
                return ElementType.Dock;

            if (element is Effect)
                return ElementType.Effect;

            if (element is Grid)
                return ElementType.Grid;

            if (element is Light)
                return ElementType.Light;

            if (element is Model)
                return ElementType.Model;

            if (element is Plugin)
                return ElementType.Plugin;

            if (element is Anchor)
                return ElementType.Anchor;

            if (element is Primitive)
                return ElementType.Primitive;

            if (element is Script)
                return ElementType.Script;

            if (element is Shader)
                return ElementType.Shader;

            if (element is Background)
                return ElementType.Background;

            if (element is Sound)
                return ElementType.Sound;

            if (element is Stack)
                return ElementType.Stack;

            if (element is Text)
                return ElementType.Text;

            if (element is Trigger)
                return ElementType.Trigger;

            if (element is Video)
                return ElementType.Video;

            if (element is Web)
                return ElementType.Web;

            if (element is Widget)
                return ElementType.Widget;

            return ElementType.All;
        }
Beispiel #26
0
        public void Dynamically_Adding_An_Element_With_Hierarchy_To_A_Collection_Then_Removing_The_Parent_Of_The_Hierarchy_Frees_The_Child_Names()
        {
            var name = "theName";

            var collection = new ImmlElement();
            collection.Name = "Context";

            var elementWithHierarchy = new ImmlElement();

            var childOfHierarchy = new ImmlElement();
            childOfHierarchy.Name = name;

            elementWithHierarchy.Add(childOfHierarchy);

            collection.Add(elementWithHierarchy);

            Assert.True(collection.ContainsName(name));

            collection.Remove(elementWithHierarchy);

            Assert.False(collection.ContainsName(name));

            collection.Add(new ImmlElement { Name = name });

            Assert.True(collection.ContainsName(name));
        }
Beispiel #27
0
        public override void Remove(ImmlElement element)
        {
            base.Remove(element);

            if (element is IPositionalElement)
            {
                _PositionalElements.Remove(element as IPositionalElement);
            }
        }
Beispiel #28
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);
        }
Beispiel #29
0
        public void Defines_Can_Be_Retrieved_When_Present()
        {
            var element = new ImmlElement();
            var define = new Define();
            define.Key = Guid.NewGuid().ToString();
            define.Value = Guid.NewGuid().ToString();

            element.Add(define);

            Assert.Equal(1, element.GetDefines().Count);
            Assert.Equal(define.Key, element.GetDefines().First().Key);
            Assert.Equal(define.Value, element.GetDefines().First().Value);
        }
Beispiel #30
0
        public void HasChildren_Is_False_When_No_Elements_Have_Been_Added()
        {
            var element = new ImmlElement();

            Assert.Equal(false, element.HasChildren);
        }