Esempio n. 1
0
        private void SetupForProperty(ValueStage stage)
        {
            var behavior = new TestBehavior(stage);

            Property = PropertyStub.WithBehaviors(behavior).Of <object>();
            VM       = ViewModelStub.WithProperties(Property).Build();
            Manager  = behavior.Manager;
            Context  = new BehaviorContextStub(VM);
        }
Esempio n. 2
0
 public ValidationResultManager(
     BehaviorInitializationContext context,
     FieldDefinitionGroup fieldGroup,
     ValueStage stage
     )
 {
     _resultField = new DynamicFieldAccessor <ValidationResult>(context, fieldGroup);
     _property    = context.Property;
     _stage       = stage;
 }
Esempio n. 3
0
        public override void NotifyPropertyChanged(IBehaviorContext context, ValueStage stage, TValue oldValue, TValue newValue)
        {
            var args = ChangeArgs.ViewModelPropertyChanged(
                _property,
                stage,
                oldValue,
                newValue,
                reason: null
                );

            context.NotifyChange(args);
        }
        public void SetValue_RaisesAppropriateChangeNotifications()
        {
            ValueStage noChangeNotifciation = null;

            EmployeeVM vm = EmployeeVM.Create(b => {
                b.Check(x => x.NumericProperty).ValueInRange(min: 1, max: 10);
            });

            Action <int, int, int, ValueStage> testCode = (
                oldValue,
                oldSourceValue,
                newValue,
                expectedChangeNotification
                ) => {
                vm.SetValue(x => x.NumericProperty, oldSourceValue);
                vm.SetValue(x => x.NumericProperty, oldValue);
                vm.OnChangeInvocations.Clear();

                vm.SetValue(x => x.NumericProperty, newValue);

                IEnumerable <ChangeArgs> args = vm
                                                .OnChangeInvocations
                                                .Where(x => x.ChangeType == ChangeType.PropertyChanged);

                if (expectedChangeNotification != null)
                {
                    Assert.AreEqual(1, args.Count(), "Expected a single change notification.");

                    ChangeArgs arg = args.Single();
                    Assert.AreEqual(expectedChangeNotification, arg.Stage);
                }
                else
                {
                    Assert.AreEqual(0, args.Count(), "Expected no change notification.");
                }
            };

            // Valid values: { 5, 6 }, invalid values: { 77, 78 }
            ParameterizedTest
            // oldValue | oldSourceValue | newValue | expectedChange
            .TestCase(5, 5, 5, noChangeNotifciation)
            .TestCase(5, 5, 6, ValueStage.ValidatedValue)
            .TestCase(5, 5, 77, ValueStage.Value)
            .TestCase(77, 5, 77, noChangeNotifciation)
            .TestCase(77, 5, 78, ValueStage.Value)
            .TestCase(77, 5, 5, ValueStage.Value)
            .TestCase(77, 5, 6, ValueStage.ValidatedValue)
            .Run(testCode);
        }
Esempio n. 5
0
        public static void NotifyPropertyChangedNext <TValue>(
            this Behavior behavior,
            IBehaviorContext context,
            ValueStage stage,
            TValue oldValue,
            TValue newValue
            )
        {
            IChangeNotifierBehavior <TValue> next;

            if (behavior.TryGetBehavior(out next))
            {
                next.NotifyPropertyChanged(context, stage, oldValue, newValue);
            }
        }
Esempio n. 6
0
 public TestBehavior(ValueStage stage)
 {
     _stage = stage;
 }