Exemplo n.º 1
0
        public void NotifyPropertyChanged_ManualByStringLiteral()
        {
            var obj = ModelBaseTestHelper.CreateIniEntryObject();

            bool isInvoked = false;

            obj.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (!isInvoked)
                {
                    if (string.Compare(e.PropertyName, "Value") != 0)
                    {
                        Assert.Fail("Wrong PropertyChanged property name");
                    }
                }

                isInvoked = true;
            };

            obj.RaisePropertyChanged("Value");

            if (!isInvoked)
            {
                Assert.Fail("PropertyChanged was not invoked");
            }
        }
Exemplo n.º 2
0
        public void InvokePropertyChangedForAllRegisteredProperties()
        {
            List <string> expectedProperties = new List <string>();
            List <string> actualProperties   = new List <string>();

            expectedProperties.Add(IniEntry.GroupProperty.Name);
            expectedProperties.Add(IniEntry.KeyProperty.Name);
            expectedProperties.Add(IniEntry.ValueProperty.Name);
            expectedProperties.Add(IniEntry.IniEntryTypeProperty.Name);

            var obj = ModelBaseTestHelper.CreateIniEntryObject();

            obj.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                actualProperties.Add(e.PropertyName);
            };

            obj.RaisePropertyChangedForAllRegisteredProperties();

            Assert.AreEqual(expectedProperties.Count, actualProperties.Count);
            foreach (string property in expectedProperties)
            {
                if (!actualProperties.Contains(property))
                {
                    Assert.Fail("No PropertyChanged event for " + property);
                }
            }
        }
Exemplo n.º 3
0
        public void NotifyPropertyChanging()
        {
            var obj = ModelBaseTestHelper.CreateIniEntryObject();

            bool isInvoked = false;

            obj.PropertyChanging += (sender, e) =>
            {
                if (isInvoked)
                {
                    return;
                }

                isInvoked = true;

                // Check property
                if (string.Compare(e.PropertyName, "Value") != 0)
                {
                    Assert.Fail("Wrong PropertyChanging property name");
                }
            };

            obj.Value = "MyNewValue";

            Assert.IsTrue(isInvoked, "PropertyChanging was not invoked");
        }
Exemplo n.º 4
0
        public void CloneLevel1()
        {
            var obj       = ModelBaseTestHelper.CreateIniEntryObject();
            var clonedObj = obj.Clone();

            Assert.AreEqual(obj, clonedObj);
        }
Exemplo n.º 5
0
        public void XmlSerializationLevel1()
        {
            var originalObject = ModelBaseTestHelper.CreateIniEntryObject();
            var clonedObject   = SerializationTestHelper.SerializeAndDeserializeObject(originalObject, SerializationMode.Xml);

            Assert.AreEqual(originalObject, clonedObject);
        }
Exemplo n.º 6
0
        public void EqualsLevel1()
        {
            // Create 2 objects
            var obj1 = ModelBaseTestHelper.CreateIniEntryObject();
            var obj2 = ModelBaseTestHelper.CreateIniEntryObject();

            // Equals
            Assert.AreEqual(obj1, obj2);
        }
Exemplo n.º 7
0
        public void Equals_Generic_Null()
        {
            // Create 2 objects
            IniEntry obj1 = ModelBaseTestHelper.CreateIniEntryObject();
            IniEntry obj2 = null;

            // Equals
            Assert.IsFalse(obj1.Equals(obj2));
        }
Exemplo n.º 8
0
        public void Equals_Generic()
        {
            // Create 2 objects
            var obj1 = ModelBaseTestHelper.CreateIniEntryObject();
            var obj2 = ModelBaseTestHelper.CreateIniEntryObject();

            // Equals
            Assert.IsTrue(obj1.Equals(obj2));
            Assert.IsTrue(obj2.Equals(obj1));
        }
Exemplo n.º 9
0
            public void AppliesChangesCorrectlyForSimpleTypes()
            {
                var iniEntry = ModelBaseTestHelper.CreateIniEntryObject();
                var iniEntryAsIEditableObject = (IEditableObject)iniEntry;

                iniEntry.Value = "MyOldValue";

                iniEntryAsIEditableObject.BeginEdit();

                iniEntry.Value = "MyNewValue";

                iniEntryAsIEditableObject.EndEdit();

                Assert.AreEqual("MyNewValue", iniEntry.Value);
            }
Exemplo n.º 10
0
        public void ReadOnlyTest()
        {
            // Declare variables
            const string testValue = "new value that shouldn't exist";
            string       originalValue, actualValue;

            IniEntry iniEntry = ModelBaseTestHelper.CreateIniEntryObject();

            // Test whether the object can be set to read-only
            originalValue = iniEntry.Value;
            iniEntry.SetReadOnly(true);
            iniEntry.Value = testValue;
            actualValue    = iniEntry.Value;
            Assert.AreEqual(originalValue, actualValue);

            // Test whether the object can be set to edit mode again
            iniEntry.SetReadOnly(false);
            iniEntry.Value = testValue;
            actualValue    = iniEntry.Value;
            Assert.AreEqual(testValue, actualValue);
        }
Exemplo n.º 11
0
        public void NotifyPropertyChanged_Automatic()
        {
            var obj = ModelBaseTestHelper.CreateIniEntryObject();

            bool isInvoked = false;

            obj.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                isInvoked = true;

                if (string.Compare(e.PropertyName, "Value") != 0)
                {
                    Assert.Fail("Wrong PropertyChanged property name");
                }
            };

            obj.Value = "MyNewValue";

            if (!isInvoked)
            {
                Assert.Fail("PropertyChanged was not invoked");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        ///   Initializes the default ini file collection.
        /// </summary>
        /// <returns>New <see cref = "ObservableCollection{T}" />.</returns>
        private static ObservableCollection <IniFile> InitializeDefaultIniFileCollection()
        {
            var result = new ObservableCollection <IniFile>();

            // Add 3 files
            result.Add(ModelBaseTestHelper.CreateIniFileObject("Initial file 1", new[] { ModelBaseTestHelper.CreateIniEntryObject("G1", "K1", "V1") }));
            result.Add(ModelBaseTestHelper.CreateIniFileObject("Initial file 2", new[] { ModelBaseTestHelper.CreateIniEntryObject("G2", "K2", "V2") }));
            result.Add(ModelBaseTestHelper.CreateIniFileObject("Initial file 3", new[] { ModelBaseTestHelper.CreateIniEntryObject("G3", "K3", "V3") }));

            return(result);
        }