コード例 #1
0
        public void Create_SimpleExpression_WrongValueSet_CallsOnError()
        {
            var source = new GenericNotifyPropertyChanged<GenericNotifyPropertyChanged<int>>();
            source.Value = new GenericNotifyPropertyChanged<int>();
            var expected = (new int[] { 0, 1 }).ToObservable();
            // TODO: Add this to expected sequence after SequenceEqual is switched
            // to somethin more elaborate
            //.Concat<int>(Observable.Throw<int>(new NullReferenceException()));

            var actual = ObservableEx.Create(() => source.Value.Value);

            bool completed = false;
            Exception error = null;
            using (actual.SequenceEqual(expected)
                .ObserveOn(Scheduler.Immediate).Subscribe(
                Assert.IsTrue,
                e => error = e,
                () => completed = true))
            {
                source.Value.Value = 1;
                source.Value = null;
            }

            Assert.IsNotNull(error, "OnError not called");
            Assert.IsInstanceOfType(error, typeof(NullReferenceException), "Wrong type of exception");
            Assert.IsFalse(completed, "Sequence complete");
        }
コード例 #2
0
        public void BindFromExpression_ComplexBinding_WrongInitialValue_ThrowsExeption()
        {
            var target = new GenericBindingTarget<int>();
            var source1 = new GenericNotifyPropertyChanged<int>();
            var source2 = new GenericNotifyPropertyChanged<GenericNotifyPropertyChanged<int>>();

            BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value.Value);
        }
コード例 #3
0
        public void BindFromExpression_ComplexBinding()
        {
            var target = new GenericBindingTarget<int>();
            var source1 = new GenericNotifyPropertyChanged<int>();
            var source2 = new GenericNotifyPropertyChanged<int>();

            BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value);

            Assert.AreEqual(0, target.Value);
            source1.Value = 1;
            Assert.AreEqual(1, target.Value);
            source2.Value = 1;
            Assert.AreEqual(2, target.Value);
        }
コード例 #4
0
        public void Create_SimpleExpression()
        {
            var source = new GenericNotifyPropertyChanged<int>();
            var expected = (new int[] {0, 1, 2}).ToObservable();

            var actual = ObservableEx.Create(() => source.Value);

            using (actual.SequenceEqual(expected)
                .ObserveOn(Scheduler.Immediate)
                .Subscribe(Assert.IsTrue, Assert.Fail))
            {
                source.Value = 1;
                source.Value = 2;
            }
        }
コード例 #5
0
        public void BindFromExpression_ComplexBinding_DisposeSubsription_RemovesBinding()
        {
            var target = new GenericBindingTarget<int>();
            var source1 = new GenericNotifyPropertyChanged<int>();
            var source2 = new GenericNotifyPropertyChanged<int>();

            using (BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value))
            {
                Assert.AreEqual(0, target.Value);
                source1.Value = 1;
                Assert.AreEqual(1, target.Value);
                source2.Value = 1;
                Assert.AreEqual(2, target.Value);
            }
            source1.Value = 2;
            source2.Value = 2;
            // Value should be reseted to 0
            Assert.AreEqual(0, target.Value);
        }
コード例 #6
0
        public void Create_ComplexExpression()
        {
            var source1 = new GenericNotifyPropertyChanged<int>();
            var source2 = new GenericNotifyPropertyChanged<int>();
            var expected = (new int[] { 0, 1, 2 }).ToObservable();

            var actual = ObservableEx.Create(() => source1.Value + source2.Value);

            bool completed = false;
            using (actual.Take(3).SequenceEqual(expected)
                .ObserveOn(Scheduler.Immediate)
                .Subscribe(Assert.IsTrue, e => Assert.Fail("Exception occured"), () => completed = true))
            {
                source1.Value = 1;
                source2.Value = 1;
            }

            Assert.IsTrue(completed, "Sequence not complete");
        }
コード例 #7
0
        public void Create_SimpleExpression_WrongInitialValue_CallsOnError()
        {
            var source = new GenericNotifyPropertyChanged<GenericNotifyPropertyChanged<int>>();

            var actual = ObservableEx.Create(() => source.Value.Value);

            bool completed = false;
            Exception error = null;
            using (actual.Subscribe(
                i => Assert.Fail("OnNext"),
                e => error = e,
                () => completed = true))
            {
                source.Value = new GenericNotifyPropertyChanged<int>();
                source.Value.Value = 1;
            }

            Assert.IsNotNull(error, "OnError not called");
            Assert.IsInstanceOfType(error, typeof(NullReferenceException), "Wrong type of exception");
            Assert.IsFalse(completed, "Sequence complete");
        }
コード例 #8
0
        public void FromExpression_SimpleBinding()
        {
            var target = new GenericBindingTarget<int>();
            var source = new GenericNotifyPropertyChanged<int>();

            BindingBase binding = BindingEx.FromExpression(() => source.Value);
            target.SetBinding(GenericBindingTarget<int>.ValueProperty, binding);

            Assert.AreEqual(0, target.Value);
            source.Value = 1;
            Assert.AreEqual(1, target.Value);
        }
コード例 #9
0
        public void BindFromExpression_SimpleBinding_WrongValueSet_ThrowsExeption()
        {
            var target = new GenericBindingTarget<int>();
            var source = new GenericNotifyPropertyChanged<GenericNotifyPropertyChanged<int>>();
            source.Value = new GenericNotifyPropertyChanged<int>();

            BindingEx.BindFromExpression(() => target.Value == source.Value.Value);

            Assert.AreEqual(0, target.Value);
            source.Value.Value = 1;
            Assert.AreEqual(1, target.Value);
            source.Value = null;
        }