Пример #1
0
        public void AddDuplicateNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            Property prop1 = new StringProperty("Name", "Treefrog");
            Property prop2 = new StringProperty("Name", "Amphibian");

            collection.Add(prop1);
            collection.Add(prop2);
        }
Пример #2
0
        public void AddProperty()
        {
            Layer layer = new MultiTileGridLayer("layer", 16, 16, 16, 16);
            AttachEvents(layer);

            Property prop = new StringProperty("author", "Justin");
            layer.CustomProperties.Add(prop);

            Assert.AreEqual(EventFlags.Modified, _eventsFired);
        }
Пример #3
0
        public void AddProperty()
        {
            Assert.AreEqual(0, _pool.CustomProperties.Count());

            Property prop = new StringProperty("author", "Justin");

            _pool.CustomProperties.PropertyAdded += (s, e) =>
            {
                Assert.AreEqual(prop, e.Property);
            };
            _pool.CustomProperties.Add(prop);

            Assert.AreEqual(EventFlags.Modified | EventFlags.PropertyAdded, _eventsFired);
            Assert.AreEqual(1, _pool.CustomProperties.Count());
            Assert.AreEqual(PropertyCategory.Custom, _pool.LookupPropertyCategory("author"));
            Assert.AreEqual(prop, _pool.LookupProperty("author"));
        }
Пример #4
0
        public void CloneString()
        {
            Property prop = new StringProperty("test", "orange");
            AttachEvents(prop);

            Property prop2 = prop.Clone() as Property;

            StringProperty sp1 = prop as StringProperty;
            StringProperty sp2 = prop2 as StringProperty;
            Assert.AreEqual(sp1.Name, sp2.Name);
            Assert.AreEqual(sp1.Value, sp2.Value);

            // Make sure events were not cloned.
            sp2.Name = "test2";
            sp2.Value = "apple";
            Assert.AreEqual(EventFlags.None, _eventsFired);
        }
Пример #5
0
        public void AddPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            Property prop = new StringProperty("test", "orange");

            collection.PropertyAdded += (s, e) =>
            {
                Assert.AreSame(prop, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsTrue(collection.Contains("test"));
                Assert.IsTrue(collection.Contains(prop));
            };

            collection.Add(prop);

            Assert.AreEqual(EventFlags.PropertyAdded | EventFlags.Modified, _eventsFired);
        }
Пример #6
0
        public void RenameProperty()
        {
            Assert.AreEqual(0, _pool.CustomProperties.Count());

            StringProperty prop = new StringProperty("author", "Justin");
            _pool.CustomProperties.Add(prop);

            _eventsFired = EventFlags.None;

            _pool.CustomProperties.PropertyRenamed += (s, e) =>
            {
                Assert.AreEqual("author", e.OldName);
                Assert.AreEqual("developer", e.NewName);
            };
            prop.Name = "developer";

            Assert.AreEqual(EventFlags.Modified | EventFlags.PropertyRenamed, _eventsFired);
            Assert.AreEqual(1, _pool.CustomProperties.Count());

            Assert.Null(_pool.LookupProperty("author"));
            Assert.AreEqual(PropertyCategory.Custom, _pool.LookupPropertyCategory("developer"));
            Assert.AreEqual(prop, _pool.LookupProperty("developer"));
        }
Пример #7
0
        public Property LookupProperty(string name)
        {
            Property prop;

            switch (name) {
                case "Name":
                    prop = new StringProperty("Name", Name);
                    prop.ValueChanged += NamePropertyChangedHandler;
                    return prop;

                default:
                    return _properties.Contains(name) ? _properties[name] : null;
            }
        }
Пример #8
0
        public Property LookupProperty (string name)
        {
            Property prop;

            switch (name) {
                case "Name":
                    prop = new StringProperty("Name", _name);
                    prop.ValueChanged += NamePropertyChangedHandler;
                    return prop;

                case "Opacity":
                    prop = new NumberProperty("Opacity", _opacity);
                    prop.ValueChanged += OpacityPropertyChangedHandler;
                    return prop;

                case "Visible":
                    prop = new BoolProperty("Visible", _visible);
                    prop.ValueChanged += VisiblePropertyChangedHandler;
                    return prop;

                case "RasterMode":
                    prop = new StringProperty("RasterMode", _rasterMode.ToString());
                    prop.ValueChanged += RasterModePropertyChangedHandler;
                    return prop;

                default:
                    return _properties.Contains(name) ? _properties[name] : null;
            }
        }
Пример #9
0
        public void CopyConstructString()
        {
            StringProperty prop = new StringProperty("test", "orange");
            AttachEvents(prop);

            StringProperty prop2 = new StringProperty("new", prop);

            Assert.AreEqual("new", prop2.Name);
            Assert.AreEqual(prop.Value, prop2.Value);

            // Make sure events were not cloned.
            prop2.Name = "test2";
            prop2.Value = "apple";
            Assert.AreEqual(EventFlags.None, _eventsFired);
        }
Пример #10
0
        public void RenameReservedNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[] { "Name" });
            Property prop = new StringProperty("Author", "Treefrog");
            collection.Add(prop);

            prop.Name = "Name";
        }
Пример #11
0
        public void RenameDuplicateNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            Property prop1 = new StringProperty("Author", "Treefrog");
            Property prop2 = new StringProperty("Developer", "Justin");
            collection.Add(prop1);
            collection.Add(prop2);

            prop1.Name = "Developer";
        }
Пример #12
0
 public void StringToString()
 {
     Property prop = new StringProperty("test", "orange");
     Assert.AreEqual("orange", prop.ToString());
 }
Пример #13
0
        public void ParseString()
        {
            Property prop = new StringProperty("test", "orange");
            AttachEvents(prop);

            prop.ValueChanged += (s, e) =>
            {
                Assert.AreSame(prop, s);
                Assert.AreEqual("green", ((StringProperty)prop).Value);
            };

            prop.Parse("green");

            Assert.AreEqual("green", ((StringProperty)prop).Value);
            Assert.AreEqual(EventFlags.ValueChanged | EventFlags.Modified, _eventsFired);
        }
Пример #14
0
        public void ModifyStringSame()
        {
            StringProperty prop = new StringProperty("test", "orange");
            AttachEvents(prop);

            prop.Value = "orange";

            Assert.AreEqual(EventFlags.None, _eventsFired);
        }
Пример #15
0
 public void ModifyNameNull()
 {
     Property prop = new StringProperty("test", "orange");
     prop.Name = null;
 }
Пример #16
0
        public void ModifyName()
        {
            Property prop = new StringProperty("test", "orange");
            AttachEvents(prop);

            prop.NameChanged += (s, e) =>
            {
                Assert.AreSame(prop, s);
                Assert.AreEqual("test", e.OldName);
                Assert.AreEqual("cake", e.NewName);
                Assert.AreEqual("cake", prop.Name);
            };

            prop.Name = "cake";

            Assert.AreEqual("cake", prop.Name);
            Assert.AreEqual(EventFlags.NameChanged, _eventsFired);
        }
Пример #17
0
 public void CreateStringProperty()
 {
     StringProperty prop = new StringProperty("test", "orange");
     Assert.AreEqual("orange", prop.Value);
 }
Пример #18
0
        public void ModifyPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            StringProperty prop = new StringProperty("test", "orange");

            collection.PropertyModified += (s, e) =>
            {
                Assert.AreSame(prop, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsTrue(collection.Contains("test"));
                Assert.IsTrue(collection.Contains(prop));
                Assert.AreEqual("blue", e.Property.ToString());
            };

            collection.Add(prop);

            _eventsFired = EventFlags.None;

            prop.Value = "blue";

            Assert.AreEqual(EventFlags.PropertyModified | EventFlags.Modified, _eventsFired);
        }
Пример #19
0
        public void RemovePropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            Property prop1 = new StringProperty("test", "orange");
            Property prop2 = new StringProperty("two", "number");

            collection.Add(prop1);
            collection.Add(prop2);

            collection.PropertyRemoved += (s, e) =>
            {
                Assert.AreSame(prop1, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsFalse(collection.Contains("test"));
                Assert.IsTrue(collection.Contains("two"));
                Assert.IsFalse(collection.Contains(prop1));
                Assert.IsTrue(collection.Contains(prop2));
            };

            _eventsFired = EventFlags.None;

            collection.Remove(prop1);

            Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired);
        }
Пример #20
0
        public void CloneLayerTest()
        {
            Layer layer = new MultiTileGridLayer("layer", 16, 16, 16, 16);

            layer.Opacity = 0.5f;
            layer.IsVisible = false;

            Property prop = new StringProperty("author", "Justin");
            layer.CustomProperties.Add(prop);

            Layer layer2 = layer.Clone() as Layer;

            Assert.AreEqual(layer.Opacity, layer2.Opacity);
            Assert.AreEqual(layer.IsVisible, layer2.IsVisible);
            Assert.AreEqual(1, layer2.CustomProperties.Count);
            Assert.AreNotSame(prop, layer2.CustomProperties["author"]);
            Assert.AreEqual("Justin", layer2.CustomProperties["author"].ToString());
        }
Пример #21
0
        public void RenamePropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            StringProperty prop = new StringProperty("test", "orange");

            collection.PropertyRenamed += (s, e) =>
            {
                Assert.AreEqual("test", e.OldName);
                Assert.AreEqual("two", e.NewName);
                Assert.AreEqual(1, collection.Count);
                Assert.IsFalse(collection.Contains("test"));
                Assert.IsTrue(collection.Contains("two"));
                Assert.IsTrue(collection.Contains(prop));
            };

            collection.Add(prop);

            _eventsFired = EventFlags.None;

            prop.Name = "two";

            Assert.AreEqual(EventFlags.PropertyRenamed | EventFlags.Modified, _eventsFired);
        }
Пример #22
0
        public void ClearPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            Property prop1 = new StringProperty("test", "orange");
            Property prop2 = new StringProperty("two", "number");

            collection.Add(prop1);
            collection.Add(prop2);

            int rmCount = 0;
            collection.PropertyRemoved += (s, e) =>
            {
                rmCount++;
            };

            _eventsFired = EventFlags.None;

            collection.Clear();

            Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired);
            Assert.AreEqual(2, rmCount);
            Assert.AreEqual(0, collection.Count);
        }
Пример #23
0
        public void ActionAddCustomProperty()
        {
            if (CanAddProperty) {
                Property property = new StringProperty(FindDefaultPropertyName(), "");
                _provider.CustomProperties.Add(property);

                _selectedProperty = property.Name;
            }

            OnSyncPropertyActions(EventArgs.Empty);
            OnSyncPropertyList(EventArgs.Empty);
        }
Пример #24
0
        /// <summary>
        /// Returns a <see cref="Property"/> given its name.
        /// </summary>
        /// <param name="name">The name of a property to look up.</param>
        /// <returns>Returns either a predefined or custom <see cref="Property"/>, or <c>null</c> if the property doesn't exist.</returns>
        public Property LookupProperty (string name)
        {
            Property prop;

            switch (name) {
                case "Name":
                    prop = new StringProperty("Name", _name.Name);
                    prop.ValueChanged += NamePropertyChangedHandler;
                    return prop;

                /*case "OriginX":
                    prop = new NumberProperty("OriginX", OriginX);
                    prop.ValueChanged += PredefPropertyValueChangedHandler;
                    return prop;

                case "OriginY":
                    prop = new NumberProperty("OriginY", Width);
                    prop.ValueChanged += PredefPropertyValueChangedHandler;
                    return prop;

                case "Height":
                    prop = new NumberProperty("Height", OriginY);
                    prop.ValueChanged += PredefPropertyValueChangedHandler;
                    return prop;

                case "Width":
                    prop = new NumberProperty("Width", Height);
                    prop.ValueChanged += PredefPropertyValueChangedHandler;
                    return prop;*/

                default:
                    return _properties.Contains(name) ? _properties[name] : null;
            }
        }
Пример #25
0
 public void AddReservedNameTest()
 {
     PropertyCollection collection = new PropertyCollection(new string[] { "Name" });
     Property prop = new StringProperty("Name", "Treefrog");
     collection.Add(prop);
 }
Пример #26
0
        public void ModifyPropertyValue()
        {
            Assert.AreEqual(0, _pool.CustomProperties.Count());

            StringProperty prop = new StringProperty("author", "Justin");
            _pool.CustomProperties.Add(prop);

            _eventsFired = EventFlags.None;

            _pool.CustomProperties.PropertyModified += (s, e) =>
            {
                Assert.AreEqual(prop, e.Property);
                Assert.AreEqual("Andy", e.Property.ToString());
            };
            prop.Value = "Andy";

            Assert.AreEqual(EventFlags.Modified | EventFlags.PropertyModified, _eventsFired);
            Assert.AreEqual(1, _pool.CustomProperties.Count());
            Assert.AreEqual(PropertyCategory.Custom, _pool.LookupPropertyCategory("author"));
            Assert.AreEqual(prop, _pool.LookupProperty("author"));
        }
Пример #27
0
 public StringProperty(string name, StringProperty property)
     : base(name, property)
 {
     _value = property._value;
 }
Пример #28
0
        public void RemoveProperty()
        {
            Assert.AreEqual(0, _pool.CustomProperties.Count());

            Property prop1 = new StringProperty("author", "Justin");
            Property prop2 = new StringProperty("date", "May");
            _pool.CustomProperties.Add(prop1);
            _pool.CustomProperties.Add(prop2);

            Assert.AreEqual(2, _pool.CustomProperties.Count());

            _eventsFired = EventFlags.None;
            _pool.CustomProperties.PropertyRemoved += (s, e) =>
            {
                Assert.AreEqual(prop1, e.Property);
            };
            _pool.CustomProperties.Remove("author");

            Assert.AreEqual(EventFlags.Modified | EventFlags.PropertyRemoved, _eventsFired);
            Assert.AreEqual(1, _pool.CustomProperties.Count());

            Assert.Null(_pool.LookupProperty("author"));
            Assert.AreEqual(PropertyCategory.Custom, _pool.LookupPropertyCategory("date"));
            Assert.AreEqual(prop2, _pool.LookupProperty("date"));
        }
Пример #29
0
        private void NamePropertyChangedHandler(object sender, EventArgs e)
        {
            StringProperty property = sender as StringProperty;

            TrySetName(property.Value);
        }
Пример #30
0
 public StringProperty(string name, StringProperty property)
     : base(name, property)
 {
     _value = property._value;
 }