Пример #1
0
        public void ObservableExpressionCallsTest()
        {
            CallsTestElement element = new CallsTestElement();
            element.Value = 1;

            Assert.AreEqual(0, element.ValueGetterCallsCount);
            Assert.AreEqual(1, element.ValueSetterCallsCount);

            ObservableExpression observer = new ObservableExpression(element, "Value");

            Assert.AreEqual(1, element.ValueGetterCallsCount);
            Assert.AreEqual(1, element.ValueSetterCallsCount);
            Assert.AreEqual(1, observer.Value);

            Assert.IsTrue(observer.TrySetValue(2));

            Assert.AreEqual(2, element.ValueGetterCallsCount);
            Assert.AreEqual(2, element.ValueSetterCallsCount);
            Assert.AreEqual(2, observer.Value);

            Assert.IsTrue(observer.TrySetValue(2));

            Assert.AreEqual(2, element.ValueGetterCallsCount);
            Assert.AreEqual(2, element.ValueSetterCallsCount);
            Assert.AreEqual(2, observer.Value);

            Assert.IsTrue(observer.TrySetValue(3));

            Assert.AreEqual(3, element.ValueGetterCallsCount);
            Assert.AreEqual(3, element.ValueSetterCallsCount);
            Assert.AreEqual(3, observer.Value);
        }
        public void ObservableExpressionCallsTest()
        {
            CallsTestElement element = new CallsTestElement();

            element.Value = 1;

            Assert.AreEqual(0, element.ValueGetterCallsCount);
            Assert.AreEqual(1, element.ValueSetterCallsCount);

            ObservableExpression observer = new ObservableExpression(element, "Value");

            Assert.AreEqual(1, element.ValueGetterCallsCount);
            Assert.AreEqual(1, element.ValueSetterCallsCount);
            Assert.AreEqual(1, observer.Value);

            Assert.IsTrue(observer.TrySetValue(2));

            Assert.AreEqual(2, element.ValueGetterCallsCount);
            Assert.AreEqual(2, element.ValueSetterCallsCount);
            Assert.AreEqual(2, observer.Value);

            Assert.IsTrue(observer.TrySetValue(2));

            Assert.AreEqual(2, element.ValueGetterCallsCount);
            Assert.AreEqual(2, element.ValueSetterCallsCount);
            Assert.AreEqual(2, observer.Value);

            Assert.IsTrue(observer.TrySetValue(3));

            Assert.AreEqual(3, element.ValueGetterCallsCount);
            Assert.AreEqual(3, element.ValueSetterCallsCount);
            Assert.AreEqual(3, observer.Value);
        }