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 void ExecutionContext_ExecutionState() { GeneticAlgorithm algorithm = Mock.Of <GeneticAlgorithm>(); ExecutionContext context = new ExecutionContext(algorithm); PropertyChangedHelper.VerifyPropertyChangedEvent( context, nameof(ExecutionContext.ExecutionState), ExecutionState.Running, v => context.ExecutionState = v, () => context.ExecutionState); }
public void ExecutionContext_AlgorithmException() { GeneticAlgorithm algorithm = Mock.Of <GeneticAlgorithm>(); ExecutionContext context = new ExecutionContext(algorithm); PropertyChangedHelper.VerifyPropertyChangedEvent( context, nameof(ExecutionContext.AlgorithmException), new ArgumentException(), v => context.AlgorithmException = v, () => context.AlgorithmException); }
public void PropertyNotifyExtensionsRaiseEvent() { bool changedEventRaised = false; bool changingEventRaised = false; var myobj = new PropertyChangedHelper(); myobj.PropertyChanged += (sender, args) => changedEventRaised = true; myobj.PropertyChanging += (sender, args) => changingEventRaised = true; myobj.Name = "im trying to raise events"; Assert.IsTrue(changedEventRaised); Assert.IsTrue(changingEventRaised); }
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); }
protected void OnPropertyChanged <T>(Expression <Func <T> > propertyExpression) { PropertyChangedHelper.RaisePropertyChanged(this, propertyExpression, PropertyChanged); }