コード例 #1
0
        public void TestPropertyChangeNotification()
        {
            using (var obj = new TestObjectPropertiesBase()) {
                var notificationCount = 0;

                obj.PropertyChanged += (sender, e) => {
                    Assert.That(e.PropertyName == nameof(obj.DoubleValue));
                    notificationCount++;
                };

                // IntValue does not notify of property change
                obj.IntValue = 1;
                Assert.That(notificationCount, Is.EqualTo(0));

                // likewise, setting the property from unmanged code should not
                // trigger a change either
                obj.SetProperty(nameof(obj.IntValue), 1);
                Assert.That(notificationCount, Is.EqualTo(0));

                // DoubleValue does notify
                obj.DoubleValue = 1;
                Assert.That(notificationCount, Is.EqualTo(1));

                // also make sure changing the property from unmanged code
                // notifies and that it only notifies once
                obj.SetProperty(nameof(obj.DoubleValue), 1.0);
                Assert.That(notificationCount, Is.EqualTo(2));
            }

            Utility.AssertNoGLibLog();
        }
コード例 #2
0
        public void TestPropertyComponentModelAttributes()
        {
            // check that ComponentModel attributes map to ParamSpec
            using (var baseObj = new TestObjectPropertiesBase())
                using (var baseObjClass = (ObjectClass)TypeClass.Get(baseObj.GetGType()))
                    using (var basePspec = baseObjClass.FindProperty("bool-value")) {
                        Assert.That(basePspec.Name, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyName));
                        Assert.That(basePspec.Nick, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyNick));
                        Assert.That(basePspec.Blurb, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyBlurb));
                        Assert.That(basePspec.DefaultValue.Get(),
                                    Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyDefaultValue));
                    }

            // The subclass will inherit the values of the parent class.
            // If the subclass tries to declare an attribute again, it will
            // be ignored as is the case with DefaultValueAttribute here.
            using (var subObj = new TestObjectPropertiesSubclass())
                using (var subObjClass = (ObjectClass)TypeClass.Get(subObj.GetGType()))
                    using (var subPspec = subObjClass.FindProperty("bool-value")) {
                        Assert.That(subPspec.Name, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyName));
                        Assert.That(subPspec.Nick, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyNick));
                        Assert.That(subPspec.Blurb, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyBlurb));
                        Assert.That(subPspec.DefaultValue.Get(),
                                    Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyDefaultValue));
                    }

            Utility.AssertNoGLibLog();
        }
コード例 #3
0
        public void TestSubclassPropertyRegistration()
        {
            using (var obj = new TestObjectPropertiesBase()) {
                // check if setting properties from unmanged code works
                Assume.That(obj.IntValue, Is.EqualTo(0));
                obj.SetProperty(nameof(obj.IntValue), 1);
                Assert.That(obj.IntValue, Is.EqualTo(1));

                // also make sure that non-GTypes get boxed
                Assume.That(obj.ObjectProperty, Is.Null);
                var expectedObj = new object();
                obj.SetProperty(nameof(obj.ObjectProperty), expectedObj);
                Assert.That(obj.ObjectProperty, Is.SameAs(expectedObj));
            }

            Utility.AssertNoGLibLog();
        }