public void Refresh_CallsNotifyChange() { Behavior.Refresh(Context, new RefreshOptions()); var expectedChangeArgs = ChangeArgs.PropertyChanged(Property, null); DomainAssert.AreEqual(new[] { expectedChangeArgs }, Context.NotifyChangeInvocations); }
public void HandlePropertyChanged_ValidationFailed_ClearsValidationResult() { SetInvalidValue(); Behavior.NextValue = "Source value"; Behavior.HandlePropertyChanged(Context, ChangeArgs.PropertyChanged(Property, ValueStage.ValidatedValue)); Assert.AreEqual(Behavior.NextValue, Behavior.GetValue(Context)); }
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 PropertyChanged_SetsChangeTypeAndChangedPathToProperty() { var property = PropertyStub.Build(); var args = ChangeArgs.PropertyChanged(property, ValueStage.DisplayValue); Assert.AreEqual(ChangeType.PropertyChanged, args.ChangeType); Assert.AreEqual(ValueStage.DisplayValue, args.Stage); DomainAssert.AreEqual(Path.Empty.Append(property), args.ChangedPath); }
public void NotifyChange_WithPropertyChangeForDescendantProperty_DoesNothing() { VMInterface.NotifyChange(ChangeArgs .PropertyChanged(PropertyStub.Build(), ValueStage.ValidatedValue) .PrependViewModel(ViewModelStub.Build()) .PrependViewModel(VM) ); Assert.IsNull(VM.LastOnPropertyChangedInvocation); Assert.IsNull(VM.LastOnValidationStateChangedInvocation); }
public void NotifyChange_WithPropertyChangeForOwnProperty_CallsOnPropertyChanged() { var property = PropertyStub.Build(); VMInterface.NotifyChange(ChangeArgs .PropertyChanged(property, ValueStage.DisplayValue) .PrependViewModel(VM) ); Assert.AreEqual(property, VM.LastOnPropertyChangedInvocation); }
public void Refresh(IBehaviorContext context, RefreshOptions options) { context.NotifyChange( ChangeArgs.PropertyChanged( _property, ValueStage.ValidatedValue, RefreshReason.Create(options.ExecuteRefreshDependencies) ) ); this.RefreshNext(context, options); }
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); }
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 Revalidate_ValidationSucceeds_RaisesValidationStateChangedAndPropertyChanged() { SetPropertyToValidValue(); SetPropertyToInvalidValue(); VM.OnChangeInvocations.Clear(); VM.PropertyResultToReturn = ValidationResult.Valid; RevalidateProperty(); var expectedChangeNotifications = new[] { ChangeArgs .PropertyChanged(TestVM.ClassDescriptor.Property, ValueStage.ValidatedValue) .PrependViewModel(VM), ChangeArgs .ValidationResultChanged(TestVM.ClassDescriptor.Property, ValueStage.Value) .PrependViewModel(VM) }; DomainAssert.AreEqual(expectedChangeNotifications, VM.OnChangeInvocations); }
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); }
private static ChangeArgs CreateChangeArgs() { return(ChangeArgs.PropertyChanged(PropertyStub.Build(), ValueStage.ValidatedValue)); }