Beispiel #1
0
        public void HandleChange_WithPropertyChangedOfOwnViewModelProperty_UpdatesCachedResults()
        {
            var owner = new TestVM();

            owner.MakePropertiesAndViewModelInvalid();
            var expected = owner.GetCurrentlySetupResults();

            //   S E T   C H I L D
            var firstChild = new ViewModelStub {
                ValidationResult = CreateValidationResult("First child error")
            };

            var propertyChangedArgs = ChangeArgs
                                      .ViewModelPropertyChanged(
                owner.SecondProperty,
                ValueStage.ValidatedValue,
                oldValue: null,
                newValue: firstChild)
                                      .PrependViewModel(owner);

            owner.CallHandleChangeWith(propertyChangedArgs);

            expected.Descenants = firstChild.ValidationResult;
            AssertBehaviorResults(owner, expected);

            //   C H A N G E   C H I L D
            var secondChild = new ViewModelStub {
                ValidationResult = CreateValidationResult("Second child error")
            };

            propertyChangedArgs = ChangeArgs
                                  .ViewModelPropertyChanged(
                owner.SecondProperty,
                ValueStage.ValidatedValue,
                oldValue: firstChild,
                newValue: secondChild)
                                  .PrependViewModel(owner);

            owner.CallHandleChangeWith(propertyChangedArgs);

            expected.Descenants = secondChild.ValidationResult;
            AssertBehaviorResults(owner, expected);

            //   S E T   C H I L D   T O   N U L L
            propertyChangedArgs = ChangeArgs
                                  .ViewModelPropertyChanged(
                owner.SecondProperty,
                ValueStage.ValidatedValue,
                oldValue: secondChild,
                newValue: null)
                                  .PrependViewModel(owner);

            owner.CallHandleChangeWith(propertyChangedArgs);

            expected.Descenants = ValidationResult.Valid;
            AssertBehaviorResults(owner, expected);
        }
Beispiel #2
0
        public void HandleChange_WithItemsAddedOrRemovedFromOwnCollection_UpdatesCachedResults()
        {
            var owner = new TestVM();

            owner.MakePropertiesAndViewModelInvalid();
            var expected = owner.GetCurrentlySetupResults();

            //   F I R S T   A D D
            var firstNewItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("First new item error")
            };

            var collectionChangeArgs = ChangeArgs
                                       .ItemsAdded(VMCollectionStub.Build(), new[] { firstNewItem })
                                       .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            expected.Descenants = firstNewItem.ValidationResult;
            AssertBehaviorResults(owner, expected);

            //   S E C O N D   A D D
            var secondNewItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("Second new Item error")
            };

            collectionChangeArgs = ChangeArgs
                                   .ItemsAdded(VMCollectionStub.Build(), new[] { secondNewItem })
                                   .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            expected.Descenants = ValidationResult.Join(
                firstNewItem.ValidationResult,
                secondNewItem.ValidationResult
                );

            AssertBehaviorResults(owner, expected);

            //   R E M O V AL
            collectionChangeArgs = ChangeArgs
                                   .ItemsRemoved(VMCollectionStub.Build(), new[] { firstNewItem })
                                   .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            expected.Descenants = secondNewItem.ValidationResult;
            AssertBehaviorResults(owner, expected);
        }
Beispiel #3
0
        public void HandleChange_WithValidationResultChangedOfOwnViewModel_UpdatesBehaviorOfParentViewModel()
        {
            var child  = new TestVM();
            var parent = new TestVM();

            parent.MakePropertiesAndViewModelInvalid();
            child.ViewModelResultSetup = CreateValidationResult("View model error");

            child.Kernel.Parents.Add(parent);
            child.CallHandleChangeForViewModel();

            var expectedParentResult = parent.GetCurrentlySetupResults();

            expectedParentResult.Descenants = child.ValidationResult;

            AssertBehaviorResults(parent, expectedParentResult);
        }
Beispiel #4
0
        public void HandleChange_WithItemsAddedToOwnCollection_UpdatesBehaviorOfParentViewModel()
        {
            var parent = new TestVM();
            var owner  = new TestVM();

            parent.MakePropertiesAndViewModelInvalid();
            owner.Kernel.Parents.Add(parent);

            var newItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("New item error")
            };

            var collectionChangeArgs = ChangeArgs
                                       .ItemsAdded(VMCollectionStub.Build(), new[] { newItem })
                                       .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            var expectedParentResult = parent.GetCurrentlySetupResults();

            expectedParentResult.Descenants = newItem.ValidationResult;
            AssertBehaviorResults(parent, expectedParentResult);
        }