示例#1
0
        public void CloneTest()
        {
            string             expectedDesc      = "desc";
            bool               expectedIsEnabled = true;
            string             expectedName      = "name";
            PropertyDictionary expectedPd        = new PropertyDictionary()
            {
                { "key1", "value1" }
            };

            ClientProperties target = new ClientProperties()
            {
                Description = expectedDesc,
                IsEnabled   = expectedIsEnabled,
                Name        = expectedName,
                Properties  = expectedPd
            };

            ClientProperties actual = target.Clone();

            Assert.AreEqual(expectedDesc, actual.Description, "Description");
            Assert.AreEqual(expectedIsEnabled, actual.IsEnabled, "IsEnabled");
            Assert.AreEqual(expectedName, actual.Name, "Name");

            foreach (var item in actual.Properties)
            {
                Assert.IsTrue(expectedPd.ContainsKey(item.Key), "Key " + item.Key + " not found.");
                Assert.AreEqual(expectedPd[item.Key], item.Value, "Value " + expectedPd[item.Key] + " not equal to " + item.Value);
            }
        }
        public void TestContainsKey_PropertyStatic_ReturnsFalse()
        {
            StaticType         t          = new StaticType();
            PropertyDictionary dictionary = new PropertyDictionary(t);
            bool result = dictionary.ContainsKey("Static");

            Assert.IsFalse(result, "The property name was found.");
        }
        public void TestContainsKey_PropertyInherited_ReturnsTrue()
        {
            BaseType           b          = new DerivedType();
            PropertyDictionary dictionary = new PropertyDictionary(b);
            bool result = dictionary.ContainsKey("Inherited");

            Assert.IsTrue(result, "The property name was not found.");
        }
        public void TestContainsKey_PropertyPrivate_ReturnsFalse()
        {
            PrivateType        t          = new PrivateType();
            PropertyDictionary dictionary = new PropertyDictionary(t);
            bool result = dictionary.ContainsKey("Hidden");

            Assert.IsFalse(result, "The property name was found.");
        }
示例#5
0
 /// <summary>
 /// Property accessor. Use this for observable properties.
 /// </summary>
 /// <typeparam name="T">Property type.</typeparam>
 /// <param name="propertyName">Property name.</param>
 /// <returns>Property value.</returns>
 protected T Get <T>([CallerMemberName] string propertyName = null)
 {
     if (_propertyValues.ContainsKey(propertyName))
     {
         return((T)_propertyValues[propertyName]);
     }
     return(default(T));
 }
        public void TestContainsKey_PropertyMissing_ReturnsFalse()
        {
            var person = new {};
            PropertyDictionary dictionary = new PropertyDictionary(person);
            bool result = dictionary.ContainsKey("Name");

            Assert.IsFalse(result, "The property name was found.");
        }
示例#7
0
 /// <summary>
 /// Property accessor. Use this for observable properties.
 /// </summary>
 /// <typeparam name="T">Property type.</typeparam>
 /// <param name="propertyName">Property name.</param>
 /// <returns>Property value.</returns>
 protected T Get <T>([CallerMemberName] string propertyName = null)
 {
     if (_propertyValues.ContainsKey(propertyName))
     {
         return(_propertyValues[propertyName] is IReactiveProperty ? (T)(_propertyValues[propertyName] as IReactiveProperty).Value : (T)_propertyValues[propertyName]);
     }
     return(default(T));
 }
        public void TestPropertyDictionary_AccessPropertiesViaIndexer()
        {
            var person = new
            {
                Name     = "Bob",
                Age      = 23,
                Birthday = new DateTime(2012, 03, 12)
            };
            PropertyDictionary wrapper = new PropertyDictionary(person);

            Assert.AreEqual(3, wrapper.Count, "The wrong number of properties were created.");

            Assert.IsTrue(wrapper.ContainsKey("Name"));
            Assert.IsTrue(wrapper.ContainsKey("Age"));
            Assert.IsTrue(wrapper.ContainsKey("Birthday"));

            Assert.AreEqual(person.Name, wrapper["Name"], "The name was not wrapped.");
            Assert.AreEqual(person.Age, wrapper["Age"], "The age was not wrapped.");
            Assert.AreEqual(person.Birthday, wrapper["Birthday"], "The birthday was not wrapped.");
        }
        public void TestContainsKey_PropertyExists_ReturnsTrue()
        {
            var person = new
            {
                Name = "Bob",
            };
            PropertyDictionary dictionary = new PropertyDictionary(person);
            bool result = dictionary.ContainsKey("Name");

            Assert.IsTrue(result, "The property name was not found.");
        }
示例#10
0
        public void _AppSettings_SettingChanging(object sender, PropertyChangedEventArgs e)
        {
            if (!_saving)
            {
                try
                {
                    var newSetting = PropertyDictionary <string, object> .Convert(sender);

                    object newVal = newSetting[e.PropertyName];

                    if (newVal != null)
                    {
                        if (!newVal.Equals(OldSettings[e.PropertyName]))
                        {
                            try
                            {
                                if (!_changedSettings.ContainsKey(e.PropertyName))
                                {
                                    AppSettings[e.PropertyName] = newVal;
                                    _changedSettings.Add(e.PropertyName, newVal);
                                }
                            }
                            catch
                            {
                                AppSettings[e.PropertyName] = newVal;
                                _changedSettings.Add(e.PropertyName, newVal);
                            }
                        }
                        else
                        {
                            try
                            {
                                _changedSettings.Remove(e.PropertyName);
                            }
                            catch
                            { }
                        }

                        if (!_applyAlwaysEnabled)
                        {
                            ApplyBtn.Enabled = _changedSettings.Count > 0;
                        }
                    }
                }
                catch
                { }
            }
        }
示例#11
0
        /// <summary>
        /// Checks whether a changed property value is equal to a value.
        /// </summary>
        /// <param name="propPath">Property path of the changed property.</param>
        /// <param name="value">Value to compare with.</param>
        /// <returns>True if the changed property value is equal to the given value.</returns>
        internal bool IsEqualToChangedPropertyValue(string propPath, object value)
        {
            string valueToCompare = Serialize(value);

            if (_changedProperties.ContainsKey(propPath))
            {
                var changedPropertyValue = _changedProperties[propPath] is IReactiveProperty ?
                                           (_changedProperties[propPath] as IReactiveProperty).Value : _changedProperties[propPath];

                var  changedValue = changedPropertyValue?.ToString() ?? string.Empty;
                bool isEqual      = changedValue == valueToCompare;

                // If property is an array type, use Json serializer to compare the values.
                if (!isEqual && changedPropertyValue?.GetType().IsArray == true)
                {
                    isEqual = JsonConvert.SerializeObject(changedPropertyValue) != valueToCompare;
                }

                return(isEqual);
            }
            return(false);
        }
        public void TestContainsKeyWithClassWithRecursiveProperties()
        {
            IPropertyDictionary dict = new PropertyDictionary(new ClassWithRecursiveProperties(), PropertyDictionaryOptions.IncludeNestedProperties);

            Assert.IsTrue(dict.ContainsKey("B.B.B"));
        }