예제 #1
0
        public IEnumerable <IObservable> SetPropertyValueAfterConfirmation(SetObservablePropertyValueDelegate setValue)
        {
            if (setValue == null)
            {
                throw new ArgumentNullException(nameof(setValue));
            }

            var changedObjects = new List <IObservable>();

            if (RequiresConfirmation(calculation))
            {
                if (ConfirmPropertyChange())
                {
                    setValue();
                    PropertyChanged(calculation);
                    changedObjects.Add(calculation);
                    changedObjects.Add(calculationInput);
                }
            }
            else
            {
                setValue();
                changedObjects.Add(calculationInput);
            }

            return(changedObjects);
        }
예제 #2
0
        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();
        }
예제 #3
0
        /// <summary>
        /// Changes the property value using the <paramref name="setPropertyDelegate"/> and then notifies the observers of the objects
        /// that were affected by the change.
        /// </summary>
        /// <param name="setPropertyDelegate">The property change action.</param>
        /// <param name="changeHandler">The handler which is responsible for determining changes due to the property change.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static void ChangePropertyAndNotify(SetObservablePropertyValueDelegate setPropertyDelegate, IObservablePropertyChangeHandler changeHandler)
        {
            if (setPropertyDelegate == null)
            {
                throw new ArgumentNullException(nameof(setPropertyDelegate));
            }

            if (changeHandler == null)
            {
                throw new ArgumentNullException(nameof(changeHandler));
            }

            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(setPropertyDelegate);

            NotifyAffectedObjects(affectedObjects);
        }
예제 #4
0
        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();
        }
예제 #5
0
        public IEnumerable <IObservable> SetPropertyValueAfterConfirmation(SetObservablePropertyValueDelegate setValue)
        {
            if (setValue == null)
            {
                throw new ArgumentNullException(nameof(setValue));
            }

            var affectedObjects = new List <IObservable>();

            if (ConfirmPropertyChange())
            {
                setValue();

                affectedObjects.AddRange(ClearDuneLocationCalculationOutput());
                affectedObjects.Add(calculationsForTargetProbability);
            }

            return(affectedObjects);
        }
 public IEnumerable <IObservable> SetPropertyValueAfterConfirmation(SetObservablePropertyValueDelegate setValue)
 {
     Called = true;
     setValue();
     return(ReturnedAffectedObjects);
 }
 /// <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);
 }