public void HandleChange_DescendantValidationStateChanged_PerformsViewModelValidation() { var args = ChangeArgs.ValidationResultChanged() .PrependViewModel(VM) .PrependViewModel(ViewModelStub.Build()); Behavior.HandleChange(Context, args); Assert.AreEqual(HandleChangeNext + Validate + RevalidateNext, ActionLog); }
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 ItemsRemoved_SetsChangedPathToEmpty() { var collection = VMCollectionStub.Build(); var oldItems = new[] { ViewModelStub.Build() }; var args = ChangeArgs.ItemsRemoved(collection, oldItems); Assert.AreEqual(ChangeType.RemovedFromCollection, args.ChangeType); CollectionAssert.AreEqual(oldItems, args.OldItems.ToArray()); Assert.IsFalse(args.NewItems.Any()); DomainAssert.AreEqual(Path.Empty.Append(collection), args.ChangedPath); }
public void ItemsAdded_SetsChangeTypeAndNewItemsAndChangedPathToCollection() { var collection = VMCollectionStub.Build(); var newItems = new[] { ViewModelStub.Build() }; var args = ChangeArgs.ItemsAdded(collection, newItems); Assert.AreEqual(ChangeType.AddedToCollection, args.ChangeType); CollectionAssert.AreEqual(newItems, args.NewItems.ToArray()); Assert.IsFalse(args.OldItems.Any()); DomainAssert.AreEqual(Path.Empty.Append(collection), args.ChangedPath); }
public void NotifyChange_CallsNotifyChangeOfViewModelWithPrependedViewModel() { var vm = ViewModelStub.Build(); var args = CreateChangeArgs(); IBehaviorContext kernel = CreateKernel(vm); kernel.NotifyChange(args); var expectedArgs = args.PrependViewModel(vm); DomainAssert.AreEqual(expectedArgs, vm.NotifyChangeInvocations.SingleOrDefault()); }
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 ValidationStateChange_InvalidatesCache() { Behavior.GetValidationResult(Context, ValidationResultScope.All); var expectedResult = ChangeNextResultsAndReturnJoinedResults(); Behavior.HandleChange( Context, ChangeArgs.ValidationResultChanged().PrependViewModel(ViewModelStub.Build()) ); var actualResult = Behavior.GetValidationResult(Context, ValidationResultScope.All); Assert.AreEqual(expectedResult, actualResult); }
public void CollectionPopulated_SetsChangeTypeAndNewItemsAndChangedPathToCollection() { var collection = VMCollectionStub .WithItems(ViewModelStub.Build()) .Build(); var newItems = collection.ToArray(); var oldItems = new[] { ViewModelStub.Build(), ViewModelStub.Build() }; var args = ChangeArgs.CollectionPopulated(collection, oldItems); Assert.AreEqual(ChangeType.CollectionPopulated, args.ChangeType); CollectionAssert.AreEqual(newItems, args.NewItems.ToArray()); CollectionAssert.AreEqual(oldItems, args.OldItems.ToArray()); DomainAssert.AreEqual(Path.Empty.Append(collection), args.ChangedPath); }
public void HandleChange_WithItemsAddedOrRemovedFromDescendantCollection_DoesNotUpdateCachedResults() { var owner = new TestVM(); var newItem = new ViewModelStub { ValidationResult = CreateValidationResult("Irrelevant item error") }; var collectionChangeArgs = ChangeArgs .ItemsAdded(VMCollectionStub.Build(), new[] { newItem }) .PrependViewModel(ViewModelStub.Build()) .PrependViewModel(owner); owner.CallHandleChangeWith(collectionChangeArgs); AssertBehaviorResults(owner, ExpectedResults.AllValid); }
public void HandleChange_AlsoRefreshesParentCaches() { Behavior.GetValidationResult(Context, ValidationResultScope.All); var newResult = ChangeNextResultsAndReturnJoinedResults(); var childBehavior = new ValidationResultAggregatorCacheBehavior(); var childVM = ViewModelStub .WithBehaviors(childBehavior, new ValidationResultAggregatorStub()) .Build(); childVM.Kernel.Parents.Add(Context.VM); childBehavior.HandleChange( childVM.GetContext(), ChangeArgs.ValidationResultChanged().PrependViewModel(ViewModelStub.Build()) ); var actualResult = Behavior.GetValidationResult(Context, ValidationResultScope.All); Assert.AreEqual(newResult, actualResult); }
public void NotifyChange_CallsParentWithExtendedPath() { var parentVM = ViewModelStub.Build(); var vm = ViewModelStub.Build(); var parentKernel = CreateKernel(parentVM); var kernel = CreateKernel(vm); kernel.Parents.Add(parentVM); IBehaviorContext kernelContext = kernel; var args = CreateChangeArgs(); kernelContext.NotifyChange(args); var expectedArgs = args .PrependViewModel(vm) .PrependViewModel(parentVM); DomainAssert.AreEqual(expectedArgs, parentVM.NotifyChangeInvocations.SingleOrDefault()); }
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); }
public LoggingCollectionStub(StringBuilder log) : base(ViewModelStub.Build(), PropertyStub.Build()) { _log = log; }
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); }
private static VMKernel CreateKernel(IViewModel vm = null) { vm = vm ?? ViewModelStub.Build(); return(new VMKernel(vm, vm.Descriptor, ServiceLocator.Current)); }