Example #1
0
        public void AddPrototype()
        {
            Entity entity = new Entity();

            Entity prototype = new Entity() { Name = "prototype" };
            entity.AddPrototype(prototype);

            Assert.AreEqual(1, entity.Prototypes.Where(x => x.Name == "prototype").Count());
        }
Example #2
0
        public void AttributeBecomesInheritableAfterAddToParent()
        {
            Entity parent = new Entity() { Name = "parent" };

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

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

            //Assert.IsFalse(attribute.CanInherit);

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

            //Assert.IsTrue(attribute.CanInherit);
            Assert.AreEqual(1, parent.Attributes.Count);
            Assert.AreEqual(1, child.Attributes.Count);
        }
Example #3
0
        public void CannotRemoveReadOnlyEventFromInheritingEntity()
        {
            bool collectionChanged = false;

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

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parentEvent.SetProperty("Trigger", new Value("test"));
            parent.AddEvent(parentEvent);

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

            child.Events.CollectionChanged += (o, e) => collectionChanged = true;

            AbstractEvent childEvent = child.Events.Single();
            child.RemoveEvent(childEvent);

            Assert.IsFalse(collectionChanged);
            Assert.AreEqual(1, child.Events.Count);
        }
        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 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 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 #7
0
        public void CannotSetReadOnlyEventProperty()
        {
            Entity parent = new Entity() { Name = "parent" };

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parentEvent.SetProperty("Trigger", new Value("test", true));
            parent.AddEvent(parentEvent);

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

            AbstractProperty childProperty = child.Events.Single().GetProperty("Trigger");
            childProperty.Value = new Value("test2", true);

            Assert.AreEqual("test", childProperty.Value.Reader.GetStrValue());
        }
Example #8
0
        public void RemoveReadOnlyEvent()
        {
            int eventsFired = 0;

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

            Entity child = new Entity();
            child.Events.CollectionChanged += (o, e) => eventsFired++;

            child.AddPrototype(parent);

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parent.AddEvent(parentEvent);
            parent.RemoveEvent(parentEvent);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(0, parent.Events.Count);
            Assert.AreEqual(0, child.Events.Count);
        }
Example #9
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 #10
0
        public void EventsInheritedFromAllPrototypes()
        {
            int eventsFired = 0;

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

            Entity child = new Entity();
            child.Events.CollectionChanged += (o, e) => eventsFired++;

            child.AddPrototype(parent);
            child.AddPrototype(otherParent);

            parent.AddEvent(new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)));
            otherParent.AddEvent(new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)));

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(1, parent.Events.Count(x => x.IsEditable));
            Assert.AreEqual(1, otherParent.Events.Count(x => x.IsEditable));
            Assert.AreEqual(2, child.Events.Count(x => x.IsReadOnly));
        }
Example #11
0
        public void PrototypeMustHaveName()
        {
            Entity entity = new Entity();

            Entity prototype = new Entity();
            entity.AddPrototype(prototype);

            Assert.AreEqual(0, entity.Prototypes.Count());
        }
Example #12
0
        public void EntityInheritsAttributeFromPrototype()
        {
            Entity parent = new Entity() { Name = "parent" };
            parent.AddAttribute(new Attribute("test"));

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

            Assert.AreEqual(1, parent.Attributes.Where(x => x.Name == "test").Count());
            Assert.AreEqual(1, child.Attributes.Where(x => x.Name == "test").Count());
        }
Example #13
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 #14
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 #15
0
        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);
        }
Example #16
0
        public void EventsInheritedFromPrototype()
        {
            bool collectionChanged = false;

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

            Entity child = new Entity();
            child.Events.CollectionChanged += (o, e) => collectionChanged = true;

            child.AddPrototype(parent);

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parent.AddEvent(parentEvent);

            Assert.IsTrue(collectionChanged);
            Assert.AreEqual(1, parent.Events.Count(x => x.IsEditable));
            Assert.AreEqual(1, child.Events.Count(x => x.IsReadOnly));
        }
Example #17
0
        // Multiple inheritance tests
        private static Game CreateTestGame()
        {
            var game = new Game("Test Game");

            var prototypeA0 = new Entity() { Name = "prototypeA0" };
            game.AddPrototype(prototypeA0);
            var prototypeB0 = new Entity() { Name = "prototypeB0" };
            game.AddPrototype(prototypeB0);
            var prototypeC0 = new Entity() { Name = "prototypeC0" };
            game.AddPrototype(prototypeC0);

            var prototypeA1 = new Entity() { Name = "prototypeA1" };
            prototypeA1.AddPrototype(prototypeA0);
            game.AddPrototype(prototypeA1);

            var prototypeB1 = new Entity() { Name = "prototypeB1" };
            prototypeB1.AddPrototype(prototypeB0);
            prototypeB1.AddPrototype(prototypeC0);
            game.AddPrototype(prototypeB1);

            var scene = new Scene("Test Scene");
            game.FirstScene = scene;
            var testEntity = new Entity() { Name = "testEntity" };
            scene.AddEntity(testEntity);
            testEntity.AddPrototype(prototypeA1);
            testEntity.AddPrototype(prototypeB1);

            return game;
        }
Example #18
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);
        }