public void BindWeakThrowsIfTargetIsCompilerGenerated()
        {
            var    c1     = new NotifyingClass();
            string newVal = null;

            Assert.Throws <InvalidOperationException>(() => c1.BindWeak(x => x.Foo, (o, e) => newVal = e.NewValue));
        }
        public void BindWeakPassesSender()
        {
            var c1 = new NotifyingClass();

            c1.BindWeak(x => x.Foo, (o, e) => this.sender = o);
            c1.Foo = "foo";
            Assert.AreEqual(c1, this.sender);
        }
        public void WeakBindingBinds()
        {
            var c1 = new NotifyingClass();

            c1.BindWeak(x => x.Foo, (o, e) => this.newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.AreEqual("bar", this.newVal);
        }
 public void DoesClassImplementingINotifyPropertyChangedWorks()
 {
     string propertyName = null;
     NotifyingClass cls = new NotifyingClass();
     cls.PropertyChanged +=
         delegate(object sender, PropertyChangedEventArgs e) { propertyName = e.PropertyName; };
     cls.PropertyWithNotify = "dummy";
     Assert.AreEqual(propertyName, "PropertyWithNotify", "Event not triggered succesfully through INotifyPropertyChanged.");
 }
        public void StrongBindingBinds()
        {
            string newVal = null;
            var c1 = new NotifyingClass();
            c1.Bind(x => x.Foo, (o, e) => newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.AreEqual("bar", newVal);
        }
        public void WeakBindingIgnoresOtherProperties()
        {
            var c1 = new NotifyingClass();

            c1.BindWeak(x => x.Bar, (o, e) => this.newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.IsNull(this.newVal);
        }
        public void StrongBindingIgnoresOtherProperties()
        {
            string newVal = null;
            var c1 = new NotifyingClass();
            c1.Bind(x => x.Bar, (o, e) => newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.AreEqual(null, newVal);
        }
예제 #8
0
        public void StrongBindingPassesTarget()
        {
            var    c1     = new NotifyingClass();
            object sender = null;

            c1.Bind(x => x.Foo, (o, e) => sender = o);
            c1.Foo = "foo";
            Assert.AreEqual(c1, sender);
        }
        public void WeakBindingUnbinds()
        {
            var c1      = new NotifyingClass();
            var binding = c1.BindWeak(x => x.Bar, (o, e) => this.newVal = e.NewValue);

            binding.Unbind();
            c1.Bar = "bar";

            Assert.IsNull(this.newVal);
        }
        public void StrongBindingListensToEmptyString()
        {
            string newVal = null;
            var c1 = new NotifyingClass();
            c1.Bar = "bar";
            c1.Bind(x => x.Bar, (o, e) => newVal = e.NewValue);
            c1.NotifyAll();

            Assert.AreEqual("bar", newVal);
        }
예제 #11
0
        public void StrongBindingBinds()
        {
            string newVal = null;
            var    c1     = new NotifyingClass();

            c1.Bind(x => x.Foo, (o, e) => newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.AreEqual("bar", newVal);
        }
예제 #12
0
        public void StrongBindingIgnoresOtherProperties()
        {
            string newVal = null;
            var    c1     = new NotifyingClass();

            c1.Bind(x => x.Bar, (o, e) => newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.AreEqual(null, newVal);
        }
        public void WeakBindingListensToEmptyString()
        {
            var c1 = new NotifyingClass();

            c1.Bar = "bar";
            c1.BindWeak(x => x.Bar, (o, e) => this.newVal = e.NewValue);
            c1.NotifyAll();

            Assert.AreEqual("bar", this.newVal);
        }
        public void StrongBindingListensToEmptyString()
        {
            string newVal = null;
            var    c1     = new NotifyingClass();

            c1.Bar = "bar";
            c1.Bind(x => x.Bar, (o, e) => newVal = e.NewValue);
            c1.NotifyAll();

            Assert.AreEqual("bar", newVal);
        }
예제 #15
0
        public void StrongBindingUnbinds()
        {
            string newVal  = null;
            var    c1      = new NotifyingClass();
            var    binding = c1.Bind(x => x.Bar, (o, e) => newVal = e.NewValue);

            binding.Unbind();
            c1.Bar = "bar";

            Assert.AreEqual(null, newVal);
        }
        public void WeakBindingDoesNotRetainNotifier()
        {
            var binding   = new BindingClass();
            var notifying = new NotifyingClass();
            // Means of determining whether the class has been disposed
            var weakNotifying = new WeakReference <NotifyingClass>(notifying);
            // Retain binder, as that shouldn't affect anything
            var binder = binding.BindWeak(notifying);

            notifying = null;
            GC.Collect();
            Assert.IsFalse(weakNotifying.TryGetTarget(out notifying));
        }
예제 #17
0
        public void StrongBindingDoesNotRetainNotifier()
        {
            var binding   = new BindingClass();
            var notifying = new NotifyingClass();
            // Means of determining whether the class has been disposed
            var weakNotifying = new WeakReference <NotifyingClass>(notifying);
            // Retain the IPropertyChangedBinding, in case that causes NotifyingClass to be retained
            var binder = binding.BindStrong(notifying);

            notifying = null;
            GC.Collect();
            Assert.IsFalse(weakNotifying.TryGetTarget(out notifying));
        }
예제 #18
0
        public void BindAndInvokeInvokes()
        {
            var c1 = new NotifyingClass()
            {
                Foo = "FooVal",
            };
            PropertyChangedExtendedEventArgs <string> ea = null;

            c1.BindAndInvoke(s => s.Foo, (o, e) => ea = e);

            Assert.NotNull(ea);
            Assert.AreEqual("Foo", ea.PropertyName);
            Assert.AreEqual("FooVal", ea.NewValue);
        }
        public void WeakBindingDoesNotRetainBindingClass()
        {
            var binding = new BindingClass();

            // Means of determining whether the class has been disposed
            var weakBinding = new WeakReference <BindingClass>(binding);

            var notifying = new NotifyingClass();

            binding.BindWeak(notifying);



            binding = null;
            GC.Collect();
            Assert.IsFalse(weakBinding.TryGetTarget(out binding));
        }
        public void StrongBindingDoesNotRetainNotifier()
        {
            WeakReference Test(out IEventBinding binder)
            {
                var binding   = new BindingClass();
                var notifying = new NotifyingClass();

                // Retain the IPropertyChangedBinding, in case that causes NotifyingClass to be retained
                binder = binding.BindStrong(notifying);
                return(new WeakReference(notifying));
            }

            var weakNotifying = Test(out var retained);

            GC.Collect();

            Assert.IsFalse(weakNotifying.IsAlive);
            GC.KeepAlive(retained);
        }
        public void WeakBindingDoesNotRetainBindingClass()
        {
            var binding = new BindingClass();

            // Means of determining whether the class has been disposed
            var weakBinding = new WeakReference<BindingClass>(binding);

            var notifying = new NotifyingClass();
            binding.BindWeak(notifying);

            

            binding = null;
            GC.Collect();
            Assert.IsFalse(weakBinding.TryGetTarget(out binding));
        }
        public void WeakBindingIgnoresOtherProperties()
        {
            var c1 = new NotifyingClass();
            c1.BindWeak(x => x.Bar, (o, e) => this.newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.IsNull(this.newVal);
        }
        public void WeakBindingUnbinds()
        {
            var c1 = new NotifyingClass();
            var binding = c1.BindWeak(x => x.Bar, (o, e) => this.newVal = e.NewValue);
            binding.Unbind();
            c1.Bar = "bar";

            Assert.IsNull(this.newVal);
        }
        public void WeakBindingDoesNotRetainNotifier()
        {
            var binding = new BindingClass();
            var notifying = new NotifyingClass();
            // Means of determining whether the class has been disposed
            var weakNotifying = new WeakReference<NotifyingClass>(notifying);
            // Retain binder, as that shouldn't affect anything
            var binder = binding.BindWeak(notifying);

            notifying = null;
            GC.Collect();
            Assert.IsFalse(weakNotifying.TryGetTarget(out notifying));
        }
예제 #25
0
 public IEventBinding BindStrong(NotifyingClass notifying)
 {
     // Must make sure the compiler doesn't generate an inner class for this, otherwise we're not testing the right thing
     return(notifying.Bind(x => x.Foo, (o, e) => this.LastFoo = e.NewValue));
 }
 public void BindWeakPassesSender()
 {
     var c1 = new NotifyingClass();
     c1.BindWeak(x => x.Foo, (o, e) => this.sender = o);
     c1.Foo = "foo";
     Assert.AreEqual(c1, this.sender);
 }
 public IEventBinding BindStrong(NotifyingClass notifying)
 {
     // Must make sure the compiler doesn't generate an inner class for this, otherwise we're not testing the right thing
     return notifying.Bind(x => x.Foo, (o, e) => this.LastFoo = e.NewValue);
 }
 public void BindWeakThrowsIfTargetIsCompilerGenerated()
 {
     var c1 = new NotifyingClass();
     string newVal = null;
     Assert.Throws<InvalidOperationException>(() => c1.BindWeak(x => x.Foo, (o, e) => newVal = e.NewValue));
 }
 public IEventBinding BindWeak(NotifyingClass notifying)
 {
     return(notifying.BindWeak(x => x.Foo, (o, e) => this.LastFoo = e.NewValue));
 }
 public IEventBinding BindWeak(NotifyingClass notifying)
 {
     return notifying.BindWeak(x => x.Foo, (o, e) => this.LastFoo = e.NewValue);
 }
        public void StrongBindingUnbinds()
        {
            string newVal = null;
            var c1 = new NotifyingClass();
            var binding = c1.Bind(x => x.Bar, (o, e) => newVal = e.NewValue);
            binding.Unbind();
            c1.Bar = "bar";

            Assert.AreEqual(null, newVal);
        }
        public void WeakBindingBinds()
        {
            var c1 = new NotifyingClass();
            c1.BindWeak(x => x.Foo, (o, e) => this.newVal = e.NewValue);
            c1.Foo = "bar";

            Assert.AreEqual("bar", this.newVal);
        }
        public void StrongBindingDoesNotRetainNotifier()
        {
            var binding = new BindingClass();
            var notifying = new NotifyingClass();
            // Means of determining whether the class has been disposed
            var weakNotifying = new WeakReference<NotifyingClass>(notifying);
            // Retain the IPropertyChangedBinding, in case that causes NotifyingClass to be retained
            var binder = binding.BindStrong(notifying);

            notifying = null;
            GC.Collect();
            Assert.IsFalse(weakNotifying.TryGetTarget(out notifying));
        }
 public void StrongBindingPassesTarget()
 {
     var c1 = new NotifyingClass();
     object sender = null;
     c1.Bind(x => x.Foo, (o, e) => sender = o);
     c1.Foo = "foo";
     Assert.AreEqual(c1, sender);
 }
        public void WeakBindingListensToEmptyString()
        {
            var c1 = new NotifyingClass();
            c1.Bar = "bar";
            c1.BindWeak(x => x.Bar, (o, e) => this.newVal = e.NewValue);
            c1.NotifyAll();

            Assert.AreEqual("bar", this.newVal);
        }