public void Refresh_CallsNotifyChange() { Behavior.Refresh(Context, new RefreshOptions()); var expectedChangeArgs = ChangeArgs.PropertyChanged(Property, null); DomainAssert.AreEqual(new[] { expectedChangeArgs }, Context.NotifyChangeInvocations); }
public void Refresh_OfDelegateProperty_CallsNotifyChangeWhenViewModelInstanceHasChanged() { var oldChild = new ChildVM(); var newChild = new ChildVM(); VM.DelegatePropertyResult = oldChild; VM.Load(x => x.DelegateProperty); VM.DelegatePropertyResult = newChild; VM.OnChangeInvocations.Clear(); VM.Refresh(x => x.DelegateProperty); var expectedArgs = ChangeArgs .ViewModelPropertyChanged( RootVM.ClassDescriptor.DelegateProperty, ValueStage.ValidatedValue, oldChild, newChild) .PrependViewModel(VM); DomainAssert.AreEqual( new[] { expectedArgs }, VM.OnChangeInvocations ); }
public void Refresh_OfWrapperProperty_DoesNotCallNotifyChange() { VM.SetValue(x => x.WrapperProperty, new ChildVM()); VM.OnChangeInvocations.Clear(); VM.Refresh(x => x.WrapperProperty); DomainAssert.AreEqual(new ChangeArgs[0], VM.OnChangeInvocations); }
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 User RegisterNewUser(string username, string password) { DomainAssert.NotNullOrEmpty(username, "Username cannot be empty."); DomainAssert.NotNullOrEmpty(password, "Password cannot be empty."); var pwdHash = _pwd.HashPassword(password); return(new User(username, pwdHash, _timestamper.GetTimestamp())); }
public void Revalidate_InvokesExecutorWithCorrectArguments() { InvokeRevalidate(); Assert.AreEqual(Validate + RevalidateNext, ActionLog); Assert.IsNotNull(Executor.LastContext); Assert.AreEqual(ValidationStep.ViewModel, Executor.LastRequest.Step); DomainAssert.AreEqual(Path.Empty.Append(VM), Executor.LastRequest.TargetPath); }
public void Refresh_OfDelegateProperty_DoesNotCallNotifyChangeIfViewModelInstanceHasNotChanged() { VM.SetValue(x => x.DelegateProperty, new ChildVM()); VM.OnChangeInvocations.Clear(); VM.Refresh(x => x.DelegateProperty); DomainAssert.AreEqual(new ChangeArgs[0], VM.OnChangeInvocations); }
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 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 Validate_CallsAddedValidatorWithCorrectArgs() { var vm = new ViewModelWithValidatorExecutor(); var validator = CreateValidator(); var request = CreateRequest(); vm.Behavior.AddValidator(validator); vm.Behavior.Validate(vm.GetContext(), request); Assert.AreEqual(1, validator.Invocations, "Validator was not called."); DomainAssert.AreEqual(request, validator.LastRequest); }
public void UpdateValidationResult_AsPropertyBehavior_CallsNotifyChangeWithCorrectArgs() { SetupForProperty(ValueStage.DisplayValue); var oldResult = CreateValidationResult("New result"); Manager.UpdateValidationResult(Context, oldResult); DomainAssert.AreEqual( ChangeArgs.ValidationResultChanged(Property, ValueStage.DisplayValue), Context.NotifyChangeInvocations.LastOrDefault() ); }
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 UpdateValidationResult_AsViewModelBehavior_CallsNotifyChangeWithCorrectArgs() { SetupForViewModel(); var oldResult = CreateValidationResult("New result"); Manager.UpdateValidationResult(Context, oldResult); DomainAssert.AreEqual( ChangeArgs.ValidationResultChanged(), Context.NotifyChangeInvocations.LastOrDefault() ); }
public void Refresh_ViewModelInstanceHasChanged_RaisesNotifyChange() { var oldChild = new ChildVM(); var newChild = new ChildVM(); ValueAccessor.Value = oldChild; Behavior.GetValue(Context); ValueAccessor.Value = newChild; InvokeRefresh(); var expectedChangeArgs = ChangeArgs.ViewModelPropertyChanged(Property, ValueStage.ValidatedValue, oldChild, newChild, null); DomainAssert.AreEqual(new[] { expectedChangeArgs }, Context.NotifyChangeInvocations); }
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); }
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 GetResult_ForViewModel_ExecutesViewModelValidatorsAndCollectionValidators() { var setup = SetupItemInCollection(); Controller.GetResult(ValidationStep.Value, setup.Item); var collectionPath = Path.Empty .Append(setup.Collection.OwnerVM) .Append(setup.Collection); var propertyRequest = new ValidationRequest(ValidationStep.Value, setup.Item); var collectionRequest = new ValidationRequest(ValidationStep.Value, collectionPath); DomainAssert.AreEqual(new[] { propertyRequest }, setup.ItemExecutor.Requests); DomainAssert.AreEqual(new[] { collectionRequest }, setup.CollectionOwnerExecutor.Requests); }
public void Revalidate_ValidationFails_RaisesOnlyValidationStateChanged() { SetPropertyToValidValue(); SetPropertyToInvalidValue(); VM.OnChangeInvocations.Clear(); VM.PropertyResultToReturn = InvalidValidationResult; RevalidateProperty(); var expectedChangeNotifications = new[] { ChangeArgs .ValidationResultChanged(TestVM.ClassDescriptor.Property, ValueStage.Value) .PrependViewModel(VM) }; DomainAssert.AreEqual(expectedChangeNotifications, VM.OnChangeInvocations); }
public void Refresh_OfSimpleProperty_CallsNotifyChange() { ParameterizedTest .TestCase("InstanceProperty", new Func <RootVMDescriptor, IVMPropertyDescriptor>(x => x.InstanceProperty)) .TestCase("MappedProperty", x => x.MappedProperty) .TestCase("DelegateProperty", x => x.DelegateProperty) .Run(propertySelector => { VM.OnChangeInvocations.Clear(); VM.Refresh(propertySelector); var expectedChangaArgs = ChangeArgs .PropertyChanged(propertySelector(VM.Descriptor), ValueStage.ValidatedValue) .PrependViewModel(VM); DomainAssert.AreEqual(new[] { expectedChangaArgs }, VM.OnChangeInvocations); }); }
public void Validate_CallsParentWithExtendedPath() { var parentVM = new ViewModelWithValidatorExecutor(); var vm = new ViewModelWithValidatorExecutor(parents: parentVM); var validator = CreateValidator(); parentVM.Behavior.AddValidator(validator); var originalPath = Path.Empty; vm.Behavior.Validate(vm.GetContext(), CreateRequest(originalPath)); var expectedPath = originalPath.Prepend(parentVM); Assert.AreEqual(1, validator.Invocations, "Parent was not called."); DomainAssert.AreEqual(expectedPath, validator.LastRequest.TargetPath); }
public void Refresh_OfPopulatedCollectionProperty_CallsNotifyChangeForCollectionPopulation() { var oldItems = new[] { new ChildVM() }; VM.PopulatedPropertyResult = oldItems; VM.Load(x => x.PopulatedProperty); VM.OnChangeInvocations.Clear(); var newItems = new[] { new ChildVM() }; VM.PopulatedPropertyResult = newItems; VM.Refresh(x => x.PopulatedProperty); var expectedChangeArgs = new[] { ChangeArgs .CollectionPopulated(VM.PopulatedProperty, oldItems) .PrependViewModel(VM) }; DomainAssert.AreEqual(expectedChangeArgs, VM.OnChangeInvocations); }
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 Refresh_OfWrapperCollectionProperty_CallsNotifyChangeForCollectionPopulation() { var oldItem = new ChildVM(new ChildSource()); VM.WrapperProperty.Add(oldItem); var oldItems = VM.WrapperProperty.ToArray(); VM.OnChangeInvocations.Clear(); VM.WrapperPropertySource = new List <ChildSource> { new ChildSource() }; VM.Refresh(x => x.WrapperProperty); var newItems = VM.WrapperProperty.ToArray(); var expectedChangeArgs = new[] { ChangeArgs .CollectionPopulated(VM.WrapperProperty, new[] { oldItem }) .PrependViewModel(VM) }; DomainAssert.AreEqual(expectedChangeArgs, VM.OnChangeInvocations); }
public void Refresh_OfInstanceProperty_DoesNotCallNotifyChange() { VM.Refresh(x => x.InstanceProperty); DomainAssert.AreEqual(new ChangeArgs[0], VM.OnChangeInvocations); }
private void AssertChangeArgs(params ChangeArgs[] expected) { DomainAssert.AreEqual(expected, Context.NotifyChangeInvocations); }