예제 #1
0
        public void NotifyPropertyChanged_Expression_Integer_AutoActivate_True()
        {
            var actionRaised = false;
            var notifyPropertyChangedTestObject = new ParameterTestObject();

            using var observer1 = ParameterObserver.Observes(
                      notifyPropertyChangedTestObject.IntParameterExpression,
                      () => actionRaised = true);
            Assert.False(actionRaised);
            notifyPropertyChangedTestObject.IntParameter.Value = 2;
            Assert.True(actionRaised);
        }
예제 #2
0
        public void NotifyPropertyChanged_IntParameter_Integer_True()
        {
            var count = 0;
            var notifyPropertyChangedTestObject = new ParameterTestObject();

            using var observer1 = ParameterObserver.Observes(() => notifyPropertyChangedTestObject.IntParameter,
                                                             () => count++, false);
            Assert.AreEqual(0, count);
            notifyPropertyChangedTestObject.IntParameter.Value = 2;
            Assert.AreEqual(0, count);
            observer1.Subscribe(true);
            notifyPropertyChangedTestObject.IntParameter.Value = 3;
            Assert.AreEqual(1, count);
            observer1.Unsubscribe();
            notifyPropertyChangedTestObject.IntParameter.Value = 4;
            Assert.AreEqual(1, count);
        }
예제 #3
0
        ReactiveParameterObservers_ReplayParameterObserver_OwnerExpression_ComplexProperty_Value_Integer_AutoActivate_True4()
        {
            var value = (int?)null;
            var count = 0;
            var notifyPropertyChangedTestObject = new ParameterTestObject();

            using var observer1 = ReplayObserverFactory.Observes(
                      notifyPropertyChangedTestObject,
                      o => o.ComplexProperty.Value.IntProperty.Value);

            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.IntParameter.Value = 1");
            notifyPropertyChangedTestObject.IntParameter.Value = 1;

            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value = new ComplexParameterType()");
            notifyPropertyChangedTestObject.ComplexProperty.Value = new ComplexParameterType();

            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 1");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 1;
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 2");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 2;

            Assert.AreEqual(null, value);
            Assert.AreEqual(0, count);

            TestContext.Out.WriteLine($"observer1.Subscribe");
            using var d = observer1.Subscribe(
                      v =>
            {
                count++;
                value = v;
                TestContext.Out.WriteLine($"Count: {count}, Value " + (v.HasValue ? v.ToString() : "null"));
            });

            Assert.AreEqual(2, value);
            Assert.AreEqual(3, count);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 3");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 3;

            Assert.AreEqual(3, value);
            Assert.AreEqual(4, count);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value = null");
            notifyPropertyChangedTestObject.ComplexProperty.Value = null;

            Assert.AreEqual(null, value);
        }
예제 #4
0
        ReactiveParameterObservers_BehaviorParameterObserver_OwnerExpression_ComplexProperty_Value_Integer_AutoActivate_True4()
        {
            int?value = 0;
            var notifyPropertyChangedTestObject = new ParameterTestObject();

            notifyPropertyChangedTestObject.IntParameter.Value    = 1;
            notifyPropertyChangedTestObject.ComplexProperty.Value = new ComplexParameterType();
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 1;

            using var observer1 = BehaviorObserverFactory.Observes(
                      notifyPropertyChangedTestObject,
                      o => o.ComplexProperty.Value.IntProperty.Value);
            using var d = observer1.Subscribe(v => value = v);

            Assert.AreEqual(1, value);
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 2;
            Assert.AreEqual(2, value);
        }
예제 #5
0
        public void NotifyPropertyChanged_OwnerExpression_ComplexProperty_Value_Integer_AutoActivate_True()
        {
            var actionRaised = false;
            var notifyPropertyChangedTestObject = new ParameterTestObject();

            notifyPropertyChangedTestObject.IntParameter.Value    = 10;
            notifyPropertyChangedTestObject.ComplexProperty.Value = new ComplexParameterType();
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 11;

            using var observer1 = ParameterObserver.Observes(
                      notifyPropertyChangedTestObject,
                      o => o.ComplexProperty.Value.IntProperty.Value,
                      () => { actionRaised = true; });
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.ValueChanged += (sender, args) =>
            {
                var i = 1;
            };
            Assert.False(actionRaised);
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 2;
            Assert.True(actionRaised);
        }
예제 #6
0
        ReactiveParameterObservers_ReplayParameterObserver_Timspan2_OwnerExpression_ComplexProperty_Value_Integer_AutoActivate_True4()
        {
            var value = (int?)null;
            var count = 0;
            var notifyPropertyChangedTestObject = new ParameterTestObject();

            using var observer1 = ReplayObserverFactory.Observes(
                      notifyPropertyChangedTestObject,
                      o => o.ComplexProperty.Value.IntProperty.Value, TimeSpan.FromMilliseconds(150));

            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.IntParameter.Value = 1");
            notifyPropertyChangedTestObject.IntParameter.Value = 1;
            Thread.Sleep(50);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value = new ComplexParameterType()");
            notifyPropertyChangedTestObject.ComplexProperty.Value = new ComplexParameterType();
            Thread.Sleep(50);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 1");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 1;
            Thread.Sleep(50);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 2");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 2;
            Thread.Sleep(50);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 3");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 3;
            Thread.Sleep(50);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 4");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 4;

            Assert.AreEqual(null, value);
            Assert.AreEqual(0, count);

            TestContext.Out.WriteLine($"observer1.Subscribe");
            using var d1 = observer1.Subscribe(
                      v =>
            {
                count++;
                value = v;
                TestContext.Out.WriteLine($"Count: {count}, Value " + (v.HasValue ? v.ToString() : "null"));
            });

            Assert.AreEqual(4, value);
            Assert.AreEqual(3, count);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 5");
            notifyPropertyChangedTestObject.ComplexProperty.Value.IntProperty.Value = 5;

            Assert.AreEqual(5, value);
            Assert.AreEqual(4, count);
            TestContext.Out.WriteLine($"notifyPropertyChangedTestObject.ComplexProperty.Value = null");
            notifyPropertyChangedTestObject.ComplexProperty.Value = null;

            Assert.AreEqual(5, count);
            Assert.AreEqual(null, value);
            TestContext.Out.WriteLine($"observer1.Unubscribe");

            observer1.Unsubscribe();
            TestContext.Out.WriteLine($"observer1.Subscribe");

            using var d2 = observer1.Subscribe(v =>
            {
                count++;
                value = v;
                TestContext.Out.WriteLine($"Count: {count}, Value " + (v.HasValue ? v.ToString() : "null"));
            });
            Thread.Sleep(100);
            Assert.AreEqual(10, count);
            Assert.AreEqual(null, value);
        }