public void GetValue_CallingGetValueWithinValueInitializer_DoesNotCallValueInitializerAgain()
        {
            PropertyStub <object> property = null;

            Func <IBehaviorContext, object> provideValueFunction = ctx => {
                return(new Object());
            };

            var behavior = new TestBehavior(provideValueFunction);
            var valueInitializerWasAlreadyInvoked = false;

            Action <IBehaviorContext> initializeValueAction = ctx => {
                Assert.IsFalse(valueInitializerWasAlreadyInvoked);
                valueInitializerWasAlreadyInvoked = true;
                property.Behaviors.GetValueNext <object>(ctx);
            };

            property = PropertyStub
                       .WithBehaviors(behavior, new TestValueInitializerBehavior(initializeValueAction))
                       .Build();

            var context = ViewModelStub
                          .WithProperties(property)
                          .BuildContext();

            behavior.GetValue(context);

            Assert.IsTrue(valueInitializerWasAlreadyInvoked);
        }
        public void GetValue_CallingGetValueWithinProvideValue_ThrowsException()
        {
            PropertyStub <object> property   = null;
            var provideValueWasAlreadyCalled = false;

            Func <IBehaviorContext, object> provideValueFunction = ctx => {
                Assert.IsFalse(provideValueWasAlreadyCalled);
                provideValueWasAlreadyCalled = true;
                property.Behaviors.GetValueNext <object>(ctx);
                return(new Object());
            };

            var behavior = new TestBehavior(provideValueFunction);

            property = PropertyStub
                       .WithBehaviors(behavior)
                       .Build();

            var context = ViewModelStub
                          .WithProperties(property)
                          .BuildContext();

            AssertHelper.Throws <InvalidOperationException>(() =>
                                                            behavior.GetValue(context)
                                                            ).WithMessage(EViewModels.ValueAccessedWithinProvideValue);

            Assert.IsTrue(provideValueWasAlreadyCalled);
        }
Example #3
0
        public void Setup()
        {
            _property = PropertyStub.Named("Test").Of <string>();

            _descriptor = new ViewModelPropertyDescriptor <string>(_property, typeof(string));
            _vm         = new ViewModelStub();
        }
        private void Setup(bool withCanExecutePredicate = false, bool canExecuteResult = false)
        {
            Func <SourceObject, bool> canExecuteFunction = null;

            if (withCanExecutePredicate)
            {
                canExecuteFunction = (so) => {
                    LastCanExecuteInvocation = new DelegateInvocation {
                        SourceObject = so
                    };
                    return(canExecuteResult);
                };
            }

            Action <SourceObject> executeAction = (so) => {
                LastExecuteInvocation = new DelegateInvocation {
                    SourceObject = so
                };
            };

            Behavior = new DelegateCommandExecutorBehavior <SourceObject>(executeAction, canExecuteFunction);
            Next     = new NextBehavior();

            Context = PropertyStub
                      .WithBehaviors(Behavior, Next)
                      .GetContext();
        }
 public void Setup()
 {
     Behavior = new ViewModelInitializerBehavior <IViewModel>();
     Next     = new NextBehaviors();
     Context  = PropertyStub
                .WithBehaviors(Behavior, Next)
                .GetContext();
 }
        public void Setup()
        {
            Behavior = new StoredViewModelAccessorBehavior <ChildVM>();

            Context = PropertyStub
                      .WithBehaviors(Behavior)
                      .GetContext();
        }
        public void HandleChange_DescendantPropertyChanged_PerformsViewModelValidation()
        {
            var args = ChangeArgs.PropertyChanged(PropertyStub.Of <string>(), null)
                       .PrependViewModel(VM)
                       .PrependViewModel(new ViewModelStub());

            Behavior.HandleChange(Context, args);
            Assert.AreEqual(HandleChangeNext + Validate + RevalidateNext, ActionLog);
        }
        public void ViewModelPropertyChanged_SetsChangeTypeAndChangedPathToProperty()
        {
            var property = PropertyStub.Build();
            var args     = ChangeArgs.ViewModelPropertyChanged(property, ValueStage.Value, null, null);

            Assert.AreEqual(ChangeType.PropertyChanged, args.ChangeType);
            Assert.AreEqual(ValueStage.Value, args.Stage);
            DomainAssert.AreEqual(Path.Empty.Append(property), args.ChangedPath);
        }
        public void ViewModelPropertyChanged_SetsOldAndNewItems()
        {
            var property = PropertyStub.Build();
            var newValue = ViewModelStub.Build();
            var args     = ChangeArgs.ViewModelPropertyChanged(property, ValueStage.ValidatedValue, null, newValue);

            CollectionAssert.AreEqual(new IViewModel[0], args.OldItems.ToArray());
            CollectionAssert.AreEqual(new IViewModel[] { newValue }, args.NewItems.ToArray());
        }
        public void Setup()
        {
            SourceAccessor = new ValueAccessorStub <ChildSource>();
            Behavior       = new WrapperViewModelAccessorBehavior <ChildVM, ChildSource>();

            Context = PropertyStub
                      .WithBehaviors(Behavior, SourceAccessor, new ServiceLocatorValueFactoryBehavior <ChildVM>())
                      .GetContext();
        }
Example #11
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);
        }
Example #12
0
        public void Setup()
        {
            Behavior = new TestDescendantsValidationBehavior(ActionLogBuilder);

            var property = PropertyStub
                           .WithBehaviors(Behavior, Next)
                           .Of <string>();

            Context = CreateBehaviorContextFor(property);
        }
Example #13
0
 private TestViewModel(
     TestRevalidationBehavior viewModelBehavior,
     TestRevalidationBehavior propertyBehavior
     )
     : this(
         PropertyStub.WithBehaviors(propertyBehavior).Of <string>(),
         viewModelBehavior
         )
 {
     ViewModelBehavior = viewModelBehavior;
     PropertyBehavior  = propertyBehavior;
 }
Example #14
0
        public void Setup()
        {
            Behavior = new RefreshablePropertyChangedNotifierBehavior <object>();

            Property = PropertyStub
                       .WithBehaviors(Behavior)
                       .Build();

            Context = ViewModelStub
                      .WithProperties(Property)
                      .BuildContext();
        }
        public void Setup()
        {
            Behavior = new CommandAccessorMock();

            OwnerProperty = PropertyStub
                            .WithBehaviors(Behavior)
                            .Build();

            OwnerVM = ViewModelStub
                      .WithProperties(OwnerProperty)
                      .Build();
        }
Example #16
0
 private TestViewModel(
     PropertyStub <string> property,
     TestRevalidationBehavior viewModelBehavior
     )
     : base(DescriptorStub
            .WithBehaviors(viewModelBehavior)
            .WithProperties(property)
            .Build()
            )
 {
     Property = property;
 }
Example #17
0
        public void Setup()
        {
            Behavior = new CollectionPropertyDescendantsValidatorBehavior <ViewModelStub>();

            ViewModelPropertyAccessor       = new ValueAccessorStub <IVMCollection <ViewModelStub> >();
            ViewModelPropertyAccessor.Value = VMCollectionStub.Build();

            var property = PropertyStub
                           .WithBehaviors(Behavior, Next, ViewModelPropertyAccessor)
                           .Of <string>();

            Context = CreateBehaviorContextFor(property);
        }
Example #18
0
        public void Setup()
        {
            ValueAccessor = new ValueAccessorStub <ChildVM>();
            Behavior      = new DelegateViewModelAccessorBehavior <ChildVM>();

            Property = PropertyStub
                       .WithBehaviors(Behavior, ValueAccessor)
                       .Build();

            Context = ViewModelStub
                      .WithProperties(Property)
                      .BuildContext();
        }
        public void Setup()
        {
            Behavior = new ViewModelPropertyDescendantsValidatorBehavior <ChildVM>();

            ViewModelPropertyAccessor       = new ValueAccessorStub <ChildVM>();
            ViewModelPropertyAccessor.Value = new ChildVM();

            var property = PropertyStub
                           .WithBehaviors(Behavior, Next, ViewModelPropertyAccessor)
                           .Of <string>();

            Context = CreateBehaviorContextFor(property);
        }
Example #20
0
        private static bool HandlePropertyChangedBehaviorWasCalled(ChangeArgs args)
        {
            var mock = new PropertyChangedMock();

            var vm = ViewModelStub
                     .WithProperties(PropertyStub
                                     .WithBehaviors(mock)
                                     .Build())
                     .Build();

            vm.GetContext().NotifyChange(args);

            return(mock.PropertyChangedWasCalled);
        }
        public void ValidationStateChange_SetsChangeTypeAndChangedPath()
        {
            var args = ChangeArgs.ValidationResultChanged();

            Assert.AreEqual(ChangeType.ValidationResultChanged, args.ChangeType);
            DomainAssert.AreEqual(Path.Empty, args.ChangedPath);

            var property = PropertyStub.Build();

            args = ChangeArgs.ValidationResultChanged(property, ValueStage.ValidatedValue);
            Assert.AreEqual(ValueStage.ValidatedValue, args.Stage);
            Assert.AreEqual(ChangeType.ValidationResultChanged, args.ChangeType);
            DomainAssert.AreEqual(Path.Empty.Append(property), args.ChangedPath);
        }
Example #22
0
        public void Setup()
        {
            Handler = new HandlerMock();

            OwnerProperty = PropertyStub
                            .WithBehaviors(Handler)
                            .Build();

            OwnerVM = ViewModelStub
                      .WithProperties(OwnerProperty)
                      .Build();

            Command = new ViewModelCommand(OwnerVM, OwnerProperty);
        }
Example #23
0
        public void HandleChange_WithValidationResultChangedOfDescendantProperty_DoesNotUpdateCachedResults()
        {
            var vm = new TestVM();

            var descendantArgs = ChangeArgs
                                 .ValidationResultChanged(PropertyStub.Build(), ValueStage.ValidatedValue)
                                 .PrependViewModel(ViewModelStub.Build())
                                 .PrependViewModel(vm);

            vm.FirstPropertyResultSetup = CreateValidationResult("Irrelevant property error");
            vm.CallHandleChangeWith(descendantArgs);

            AssertBehaviorResults(vm, ExpectedResults.AllValid);
        }
        public void Setup()
        {
            ValidationResult = CreateValidationResult("Error");

            Behavior = new TestValidationSourceBehavior(ValidationStep.Value);
            Property = PropertyStub.WithBehaviors(Behavior).Of <string>();
            Executor = new ValidationExecutorStub();

            var vm = ViewModelStub
                     .WithProperties(Property)
                     .WithBehaviors(Executor)
                     .Build();

            Context = new BehaviorContextStub(vm);
        }
Example #25
0
        public void PropertyChange_DoesNotInvalidateCache()
        {
            Behavior.GetValidationResult(Context, ValidationResultScope.All);
            Counter.Invocations = 0;

            Behavior.HandleChange(
                Context,
                ChangeArgs.PropertyChanged(PropertyStub.Of <string>(), ValueStage.ValidatedValue).PrependViewModel(ViewModelStub.Build())
                );

            var actualResult   = Behavior.GetValidationResult(Context, ValidationResultScope.All);
            var expectedResult = ValidationResult.Join(new[] { PropertyResult, ViewModelResult, DescendantResult });

            Assert.AreEqual(0, Counter.Invocations);
            Assert.AreEqual(expectedResult, actualResult);
        }
Example #26
0
            public TestVM()
            {
                NextChangeHandler = new NextChangeHandlerBehavior();
                Behavior          = new CachingValidationResultAggregatorBehavior();

                FirstProperty = PropertyStub
                                .WithBehaviors(_firstPropertyResultProvider)
                                .Of <object>();

                SecondProperty = PropertyStub
                                 .WithBehaviors(_secondPropertyResultProvider)
                                 .Of <ViewModelStub>();

                Descriptor = DescriptorStub
                             .WithProperties(FirstProperty, SecondProperty)
                             .WithBehaviors(Behavior, _viewModelResultProvider, NextChangeHandler)
                             .Build();
            }
        protected void SetupFixture(
            ICollectionChangeHandlerBehavior <TItemVM> behavior,
            params IBehavior[] additionalBehaviors
            )
        {
            Behavior = behavior;

            CollectionOwner = ViewModelStub
                              .WithProperties(PropertyStub
                                              .WithBehaviors(behavior)
                                              .WithBehaviors(additionalBehaviors)
                                              .Build())
                              .Build();

            Context = BehaviorContextStub
                      .DecoratingContextOf(CollectionOwner)
                      .Build();
        }
        public void Setup()
        {
            Behavior = new ValidationResultAggregatorBehavior();

            var propertyBehavior = new ValidationResultProviderStub {
                ReturnedResult            = PropertyResult,
                ReturnedDescendantsResult = DescendantResult
            };

            var viewModelBehavior = new ValidationResultProviderStub {
                ReturnedResult = ViewModelResult
            };

            var property = PropertyStub
                           .WithBehaviors(propertyBehavior)
                           .Of <ViewModelStub>();

            Context = ViewModelStub
                      .WithProperties(property)
                      .WithBehaviors(Behavior, viewModelBehavior)
                      .BuildContext();
        }
Example #29
0
            public ItemInCollectionSetup(StringBuilder log)
            {
                ItemExecutor            = new ValidationExecutorStub();
                CollectionOwnerExecutor = new ValidationExecutorStub();

                ItemProperty = PropertyStub
                               .WithBehaviors(new RevalidationBehaviorSpy(log))
                               .Build();

                Item = ViewModelStub
                       .WithBehaviors(ItemExecutor, new RevalidationBehaviorSpy(log))
                       .WithProperties(ItemProperty)
                       .Build();

                var collectionOwner = ViewModelStub
                                      .WithBehaviors(CollectionOwnerExecutor)
                                      .Build();

                Collection = VMCollectionStub
                             .WithItems(Item)
                             .WithOwner(collectionOwner)
                             .Build();
            }
Example #30
0
        public void NotifyChange_CallsHandlePropertyChangedBehaviorOnlyIfOwnPropertyHasChanged()
        {
            var mock = new PropertyChangedMock();

            var property = PropertyStub
                           .WithBehaviors(mock)
                           .Build();

            var vm = ViewModelStub
                     .WithProperties(property)
                     .Build();

            var context = vm.GetContext();

            var args = ChangeArgs.PropertyChanged(property, ValueStage.ValidatedValue);

            context.NotifyChange(args);
            Assert.IsTrue(mock.PropertyChangedWasCalled);

            mock.PropertyChangedWasCalled = false;
            args = ChangeArgs
                   .PropertyChanged(property, ValueStage.ValidatedValue)
                   .PrependViewModel(ViewModelStub.Build());
            context.NotifyChange(args);
            Assert.IsFalse(mock.PropertyChangedWasCalled);

            mock.PropertyChangedWasCalled = false;
            args = ChangeArgs.ValidationResultChanged(property, ValueStage.Value);
            context.NotifyChange(args);
            Assert.IsFalse(mock.PropertyChangedWasCalled);

            mock.PropertyChangedWasCalled = false;
            args = ChangeArgs.ItemsAdded(VMCollectionStub.Build(), new[] { ViewModelStub.Build() });
            context.NotifyChange(args);
            Assert.IsFalse(mock.PropertyChangedWasCalled);
        }