public void ValueFollowsInheritedAttribute()
        {
            //bool propertyChanged = false;

            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test");
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            //childAttribute.PropertyChanged += (o, e) => propertyChanged = (e.PropertyName == "Value");

            parentAttribute.Value = new Value("value");

            //Assert.IsTrue(propertyChanged);
            Assert.AreEqual("value", childAttribute.Value.Initializer);
        }
        public void GiveInheritedAttributeLocalValue()
        {
            bool propertyChanged = false;

            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test");
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Assert.AreEqual(1, child.Attributes.Count(x => x.IsInherited && !x.HasOwnValue));

            Attribute childAttribute = child.GetAttribute("test");
            childAttribute.PropertyChanged += (o, e) => propertyChanged |= (e.PropertyName == "HasOwnValue");

            childAttribute.Value = new Value("value");

            Assert.IsTrue(propertyChanged);
            Assert.AreEqual(1, child.Attributes.Count(x => x.HasOwnValue));
        }
        public void KeyFollowsInheritedAttribute()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test");
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");

            parentAttribute.Name = "test2";

            Assert.IsFalse(childAttribute.HasOwnValue);
            Assert.AreEqual(0, child.Attributes.Count(x => x.Name == "test"));
            Assert.AreEqual(1, child.Attributes.Count(x => x.Name == "test2"));
        }
        public void ClearAttributeValue()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test") { Value = new Value("originalValue") };
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");

            childAttribute.Value = new Value("value");

            Assert.AreEqual(childAttribute.Value.Initializer, "value");
            Assert.AreEqual(1, child.Attributes.Count(x => x.HasOwnValue));

            childAttribute.Value = null;

            Assert.AreEqual(childAttribute.Value.Initializer, "originalValue");
            Assert.AreEqual(0, child.Attributes.Count(x => x.HasOwnValue));
        }
Example #5
0
        public void CannotRemoveInheritedAttribute()
        {
            Entity parent = new Entity() { Name = "parent" };
            parent.AddAttribute(new Attribute("test"));

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            child.RemoveAttribute(childAttribute);

            Assert.AreEqual(1, child.Attributes.Where(x => x.Name == "test").Count());
        }
Example #6
0
        public void CannotChangeKeyForInheritedAttribute()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            parent.AddAttribute(attribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            childAttribute.Value = new Value("new value");

            Assert.IsTrue(childAttribute.IsInherited);
            Assert.IsTrue(childAttribute.Name == "test");

            childAttribute.Name = "test2";

            Assert.IsTrue(childAttribute.IsInherited);
            Assert.IsTrue(childAttribute.Name == "test");
            Assert.AreEqual(1, parent.Attributes.Count);
            Assert.AreEqual(1, child.Attributes.Count);
        }
Example #7
0
        public void AttributesBecomesNonInheritableAfterParentKeyChange()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            parent.AddAttribute(attribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            //childAttribute.IsInherited = false;
            childAttribute.Value = new Value("new value");

            attribute.Name = "test2";

            Assert.AreEqual(childAttribute.Name, "test");
            //Assert.IsFalse(childAttribute.CanInherit);
            Assert.AreEqual(1, parent.Attributes.Count);
            Assert.AreEqual(2, child.Attributes.Count);
        }
Example #8
0
        public void AttributeBecomesNonInheritableAfterRemoveFromParent()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            parent.AddAttribute(attribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            //childAttribute.IsInherited = false;
            childAttribute.Value = new Value("new value");

            //Assert.IsTrue(childAttribute.CanInherit);

            parent.RemoveAttribute(attribute);

            //Assert.IsFalse(childAttribute.CanInherit);
            Assert.AreEqual(0, parent.Attributes.Count);
            Assert.AreEqual(1, child.Attributes.Count);
        }