Exemple #1
0
        public void UnregisterShouldThrowWhenPropertyIsEmpty()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.UnregisterHandler("");
        }
Exemple #2
0
        public void UnregisterShouldThrowWhenPropertyIsNull()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.UnregisterHandler((string)null);
        }
Exemple #3
0
        public void UnregisterShouldThrowWhenExpressionIsNull()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.UnregisterHandler((Expression <Func <DummyClass, object> >)null);
        }
Exemple #4
0
        public void UnregisterShouldThrowWhenExpressionIsWrong()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.UnregisterHandler(src => src);
        }
        public void UnregisterHandlerNullTest()
        {
            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            Assert.ThrowsException <ArgumentNullException>(() => po.UnregisterHandler(null));
        }
        public void UnregisterHandlerNullTest()
        {
            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            po.UnregisterHandler(null);
        }
        public void UnregisteredHandlersAreNotInvoked()
        {
            ObservableThing thing = new ObservableThing();
            PropertyObserver<ObservableThing> target = new PropertyObserver<ObservableThing>(thing);
            bool wasInvoked = false;

            target.RegisterHandler(t => t.SomeProperty, t => wasInvoked = true);
            target.UnregisterHandler(t => t.SomeProperty);
            thing.SomeProperty = "whatever";

            Assert.IsFalse(wasInvoked);
        }
Exemple #8
0
        public void UnregisteredHandlersAreNotInvoked()
        {
            ObservableThing thing = new ObservableThing();
            PropertyObserver <ObservableThing> target = new PropertyObserver <ObservableThing>(thing);
            bool wasInvoked = false;

            target.RegisterHandler(t => t.SomeProperty, t => wasInvoked = true);
            target.UnregisterHandler(t => t.SomeProperty);
            thing.SomeProperty = "whatever";

            Assert.IsFalse(wasInvoked);
        }
Exemple #9
0
        public void HandlePropertyChangedEvents()
        {
            bool       valueChanged = false;
            bool       textChanged  = false;
            DummyClass source       = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.RegisterHandler("Value", src => valueChanged        = true);
            observer.RegisterHandler(src => src.Text, src => textChanged = true);

            Assert.IsFalse(valueChanged);
            Assert.IsFalse(textChanged);

            source.Value = 10;
            Assert.IsTrue(valueChanged);
            Assert.IsFalse(textChanged);
            valueChanged = false;

            source.Text = "abc";
            Assert.IsFalse(valueChanged);
            Assert.IsTrue(textChanged);
            textChanged = false;

            source.RaisePropertyChanged();
            Assert.IsTrue(valueChanged);
            Assert.IsTrue(textChanged);
            valueChanged = false;
            textChanged  = false;

            observer.UnregisterHandler("Value");
            source.RaisePropertyChanged();
            Assert.IsFalse(valueChanged);
            Assert.IsTrue(textChanged);
            textChanged = false;

            observer.UnregisterHandler(src => src.Text);
            source.RaisePropertyChanged();
            Assert.IsFalse(valueChanged);
            Assert.IsFalse(textChanged);
        }
        public void HandlePropertyChangedEvents()
        {
            bool valueChanged = false;
            bool textChanged = false;
            DummyClass source = new DummyClass();
            PropertyObserver<DummyClass> observer = new PropertyObserver<DummyClass>(source);
            observer.RegisterHandler("Value", src => valueChanged = true);
            observer.RegisterHandler(src => src.Text, src => textChanged = true);

            Assert.IsFalse(valueChanged);
            Assert.IsFalse(textChanged);

            source.Value = 10;
            Assert.IsTrue(valueChanged);
            Assert.IsFalse(textChanged);
            valueChanged = false;

            source.Text = "abc";
            Assert.IsFalse(valueChanged);
            Assert.IsTrue(textChanged);
            textChanged = false;

            source.RaisePropertyChanged();
            Assert.IsTrue(valueChanged);
            Assert.IsTrue(textChanged);
            valueChanged = false;
            textChanged = false;

            observer.UnregisterHandler("Value");
            source.RaisePropertyChanged();
            Assert.IsFalse(valueChanged);
            Assert.IsTrue(textChanged);
            textChanged = false;

            observer.UnregisterHandler(src => src.Text);
            source.RaisePropertyChanged();
            Assert.IsFalse(valueChanged);
            Assert.IsFalse(textChanged);
        }
Exemple #11
0
        public void SourceIsWeakReference()
        {
            bool       valueChanged = false;
            bool       textChanged  = false;
            DummyClass source       = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.RegisterHandler("Value", src => valueChanged        = true);
            observer.RegisterHandler(src => src.Text, src => textChanged = true);
            source.RaisePropertyChanged();
            Assert.IsTrue(valueChanged);
            Assert.IsTrue(textChanged);

            Assert.IsFalse(_dummyClassFinalized);
            source = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            Assert.IsTrue(_dummyClassFinalized);

            observer.UnregisterHandler("Value");
            observer.UnregisterHandler(src => src.Text);
        }
        public void UnregisterHandlerTest()
        {
            string actualValue = null;

            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            WeakReference wr = new WeakReference(obj);

            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            po.RegisterHandler(o => o.SValue, (oo) => actualValue = oo.SValue);

            obj.SValue = "1";
            Assert.AreEqual("1", actualValue);

            po.UnregisterHandler(o => o.SValue);
            obj.SValue = "2";
            Assert.AreEqual("1", actualValue);
        }
        public void RegisterHandlerTest()
        {
            int    actualInt   = 0;
            string actualValue = null;

            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };

            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            po.RegisterHandler(o => o.SValue, (oo) => actualValue = oo.SValue);
            po.RegisterHandler(o => o.IValue, (oo) => actualInt   = oo.IValue);

            obj.SValue = "1";
            Assert.AreEqual("1", actualValue);
            obj.IValue = 5;
            Assert.AreEqual(5, actualInt);

            po.UnregisterHandler(o => o.SValue);
            obj.SValue = "2";
            Assert.AreEqual("1", actualValue);
        }
        public void SourceIsWeakReference()
        {
            bool valueChanged = false;
            bool textChanged = false;
            DummyClass source = new DummyClass();
            PropertyObserver<DummyClass> observer = new PropertyObserver<DummyClass>(source);
            observer.RegisterHandler("Value", src => valueChanged = true);
            observer.RegisterHandler(src => src.Text, src => textChanged = true);
            source.RaisePropertyChanged();
            Assert.IsTrue(valueChanged);
            Assert.IsTrue(textChanged);

            Assert.IsFalse(_dummyClassFinalized);
            source = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            Assert.IsTrue(_dummyClassFinalized);

            observer.UnregisterHandler("Value");
            observer.UnregisterHandler(src => src.Text);
        }
 public void UnregisterShouldThrowWhenExpressionIsNull()
 {
     DummyClass source = new DummyClass();
     PropertyObserver<DummyClass> observer = new PropertyObserver<DummyClass>(source);
     observer.UnregisterHandler((Expression<Func<DummyClass, object>>)null);
 }
 public void UnregisterShouldThrowWhenExpressionIsWrong()
 {
     DummyClass source = new DummyClass();
     PropertyObserver<DummyClass> observer = new PropertyObserver<DummyClass>(source);
     observer.UnregisterHandler(src => src);
 }
 public void UnregisterShouldThrowWhenPropertyIsEmpty()
 {
     DummyClass source = new DummyClass();
     PropertyObserver<DummyClass> observer = new PropertyObserver<DummyClass>(source);
     observer.UnregisterHandler("");
 }
 public void UnregisterShouldThrowWhenPropertyIsNull()
 {
     DummyClass source = new DummyClass();
     PropertyObserver<DummyClass> observer = new PropertyObserver<DummyClass>(source);
     observer.UnregisterHandler((string)null);
 }