示例#1
0
        public void TestBindableInt()
        {
            int lastUpdated = 0;
            int orig        = 0;
            var bindable    = new ProxyBindableInt(() => orig, (v) => orig = v);

            bindable.OnValueChanged += (v, _) => lastUpdated = v;

            Assert.AreEqual(int.MinValue, bindable.MinValue);
            Assert.AreEqual(int.MaxValue, bindable.MaxValue);
            Assert.AreEqual(0, bindable.Value);

            bindable.MinValue = 1;
            Assert.AreEqual(1, bindable.MinValue);
            Assert.AreEqual(1, bindable.Value);
            Assert.AreEqual(1, lastUpdated);

            bindable.Value = 2;
            Assert.AreEqual(2, bindable.Value);
            Assert.AreEqual(2, lastUpdated);

            orig     = 5;
            bindable = new ProxyBindableInt(() => orig, (v) => orig = v, -100, 100);
            bindable.OnValueChanged += (v, _) => lastUpdated = v;

            Assert.AreEqual(-100, bindable.MinValue);
            Assert.AreEqual(100, bindable.MaxValue);
            Assert.AreEqual(5, bindable.Value);

            bindable.MaxValue = -1;
            Assert.AreEqual(-1, bindable.MaxValue);
            Assert.AreEqual(-1, bindable.Value);
            Assert.AreEqual(-1, lastUpdated);
        }
示例#2
0
        /// <summary>
        /// Instantiates a new proxy bindable, assuming a int for type T.
        /// </summary>
        private ProxyBindableInt InitIntBindable(string propertyName, int defaultValue, int minValue, int maxValue)
        {
            var bindable = new ProxyBindableInt(
                () => storage == null ? defaultValue : storage.GetInt(propertyName, defaultValue),
                (value) => storage.SetInt(propertyName, value),
                minValue,
                maxValue
                );

            allSettings.Add(bindable);
            return(bindable);
        }