public void ChangePropertyAndNotify_ChangeHasAffectedObjects_AffectedObjectsNotified() { // Setup SetObservablePropertyValueDelegate setAction = () => {}; var mocks = new MockRepository(); var observableA = mocks.StrictMock <IObservable>(); observableA.Expect(o => o.NotifyObservers()); var observableB = mocks.StrictMock <IObservable>(); observableB.Expect(o => o.NotifyObservers()); IObservable[] affectedObjects = { observableA, observableB }; var handler = mocks.StrictMock <IObservablePropertyChangeHandler>(); handler.Expect(h => h.SetPropertyValueAfterConfirmation(setAction)).Return(affectedObjects); mocks.ReplayAll(); // Call PropertyChangeHelper.ChangePropertyAndNotify(setAction, handler); // Assert mocks.VerifyAll(); }
public void ChangePropertyAndNotify_WithoutChangeHandler_ThrowsArgumentNullException() { // Call TestDelegate test = () => PropertyChangeHelper.ChangePropertyAndNotify(() => {}, null); // Assert var exception = Assert.Throws <ArgumentNullException>(test); Assert.AreEqual("changeHandler", exception.ParamName); }
public void ChangePropertyAndNotify_ChangeHasNoAffectedObjects_HandlerUsedForSetAction() { // Setup SetObservablePropertyValueDelegate setAction = () => {}; var mocks = new MockRepository(); var handler = mocks.StrictMock <IObservablePropertyChangeHandler>(); handler.Expect(h => h.SetPropertyValueAfterConfirmation(setAction)).Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); // Call PropertyChangeHelper.ChangePropertyAndNotify(setAction, handler); // Assert mocks.VerifyAll(); }
public void ChangePropertyAndNotify_WithoutPropertySetDelegate_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub <IObservablePropertyChangeHandler>(); mocks.ReplayAll(); // Call TestDelegate test = () => PropertyChangeHelper.ChangePropertyAndNotify(null, handler); // Assert var exception = Assert.Throws <ArgumentNullException>(test); Assert.AreEqual("setPropertyDelegate", exception.ParamName); mocks.VerifyAll(); }
/// <summary> /// Handles the property change. /// </summary> /// <param name="setPropertyDelegate">The property change action.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="setPropertyDelegate"/> /// is <c>null</c>.</exception> protected void HandleChangeProperty(SetObservablePropertyValueDelegate setPropertyDelegate) { PropertyChangeHelper.ChangePropertyAndNotify(setPropertyDelegate, propertyChangeHandler); }