public void WhenMemberChainContainsCastingOperator_ThenBuildProperListener() { var target = new NotifyingSampleObject(); var listener = new PropertyChangedHelper().BuildListener(target, x => (x.Child as NotifyingSampleObject2).Child, _dummyCallback); Assert.IsTrue(listener != null); }
public void WhenMemberChainContainsMethod_ThenThrowNotSupportedExceptionOnBuilding() { var target = new NotifyingSampleObject(); Assert.ThrowsException <NotSupportedException>(() => { var listener = new PropertyChangedHelper().BuildListener(target, x => x.SampleMethod().NotNotifyingChild, _dummyCallback); }); }
public GivenListenerWithTypedCallback() { _target = new NotifyingSampleObject() { Child = new NotifyingSampleObject() { Value = "foo" } }; _listener = new PropertyChangedHelper().BuildListener(_target, x => x.Child.Value, (o, n) => { _assertion.Invoke(o, n); }); }
public void WhenObservedPropertyChanges_ThenCallbackIsInvoked() { bool wasCalled = false; var target = new NotifyingSampleObject() { Child = new NotifyingSampleObject() { Value = "foo" } }; var listener = new PropertyChangedHelper().BuildListener(target, x => x.Child.Value, () => { wasCalled = true; }); target.Child.Value = "bar"; Assert.IsTrue(wasCalled); }
public void WhenListenerIsDisposed_ThenCallbackIsNoLongerInvoked() { bool wasCalled = false; var target = new NotifyingSampleObject() { Child = new NotifyingSampleObject() { Value = "foo" } }; var listener = new PropertyChangedHelper().BuildListener(target, x => x.Child.Value, () => wasCalled = true); listener.Dispose(); target.Child.Value = "bar"; Assert.IsFalse(wasCalled); }
public void WhenIntermediatePropertyChangesButNoChangeToObservedProperty_ThenCallbackIsNotInvoked() { var wasCalled = false; var target = new NotifyingSampleObject() { Child = new NotifyingSampleObject() { Value = "foo" } }; new PropertyChangedHelper().BuildListener(target, x => x.Child.Value, () => wasCalled = true); target.Child = new NotifyingSampleObject() { Value = "foo" }; Assert.IsFalse(wasCalled); }