public void Revalidate( IVMPropertyDescriptor property, ValidationScope scope = ValidationScope.Self ) { Revalidator.RevalidatePropertyValidations(_vm, property, scope); }
private bool Matches(IViewModel parent, PathIterator nextStep) { if (!nextStep.HasStep) { return(false); } if (!(parent.Descriptor is TDescriptor)) { return(false); } TDescriptor descriptor = (TDescriptor)parent.Descriptor; IVMPropertyDescriptor expectedProperty = _propertySelector.GetProperty(descriptor); if (nextStep.IsProperty) { return(nextStep.Property == expectedProperty); } if (!parent.Kernel.IsLoaded(expectedProperty)) { return(false); } object expectedPropertyValue = parent.Kernel.GetValue(expectedProperty); if (nextStep.IsViewModel) { if (nextStep.ViewModel == expectedPropertyValue) { return(true); } else { if (expectedPropertyValue is IVMCollection) { var parentCollection = (IVMCollection)expectedPropertyValue; return(nextStep .ViewModel .Kernel .OwnerCollections .Contains(parentCollection)); } else { return(false); } } } if (nextStep.IsCollection) { return(false); } throw new NotSupportedException(); }
internal static ChangeArgs ViewModelPropertyChanged( IVMPropertyDescriptor property, ValueStage stage, IViewModel oldValue, IViewModel newValue, IChangeReason reason = null ) { var oldItems = oldValue != null ? new[] { oldValue } : null; var newItems = newValue != null ? new[] { newValue } : null; return(new ChangeArgs( ChangeType.PropertyChanged, stage, Path.Empty.Append(property), oldItems: oldItems, newItems: newItems, reason: reason ) { ChangedProperty = property }); // TODO: Remove }
public ContextTestHelper(IViewModel viewModel = null, IVMPropertyDescriptor property = null) { if (property == null) { property = new Mock <IVMPropertyDescriptor>().Object; } var descriptor = new DescriptorStub(); InitializationContext = new BehaviorInitializationContext( descriptor, property ); var fieldValues = new Lazy <FieldValueHolder>(() => descriptor.Fields.CreateValueHolder() ); VM = viewModel ?? new ViewModelStub(); ContextMock = new Mock <IBehaviorContext>(); ContextMock .Setup(x => x.FieldValues) .Returns(() => fieldValues.Value); ContextMock .Setup(x => x.VM) .Returns(VM); Context = ContextMock.Object; Property = property; }
/// <summary> /// Gets the <see cref="BehaviorChainConfiguration"/> for the given /// <paramref name="forProperty"/>. /// </summary> /// <exception cref="KeyNotFoundException"> /// The collection does not contain a configuration for the given property. /// Make sure <see cref="RegisterProperty"/> was called. /// </exception> public BehaviorChainConfiguration this[IVMPropertyDescriptor forProperty] { get { Check.NotNull(forProperty, nameof(forProperty)); return(_propertyConfigurations[forProperty]); } }
protected override ICommand CreateCommand(IViewModel ownerVM, IVMPropertyDescriptor ownerProperty) { LastOwnerVM = ownerVM; LastOwnerProperty = ownerProperty; CommandReturnedByBaseMethod = base.CreateCommand(ownerVM, ownerProperty); return(CommandToReturn); }
public void Setup() { _property = PropertyStub.Named("Test").Of <string>(); _descriptor = new ViewModelPropertyDescriptor <string>(_property, typeof(string)); _vm = new ViewModelStub(); }
public void DependencyOnTargetPropertiesOfDescendantCollection_RefreshesAllPropertiesOfAllViewModelsInCollection() { var refreshMock = new RefreshControllerBehaviorMock(); var projectVMDescriptor = ProjectVM.CreateDescriptor(refreshMock, true); var employeeVM = CreateEmployeeVM( b => b .OnChangeOf .Properties(x => x.Name) .Refresh .Descendant(x => x.Projects) .Properties(x => x.Title, x => x.Customer), projectVMDescriptor ); var projectVM1 = CreateProjectVM(); var projectVM2 = CreateProjectVM(); employeeVM.Projects.Add(projectVM1); employeeVM.Projects.Add(projectVM2); employeeVM.Name = "TriggerChange"; var expectedRefreshedProperties = new IVMPropertyDescriptor[] { projectVM1.Descriptor.Title, projectVM1.Descriptor.Customer, projectVM1.Descriptor.Title, projectVM1.Descriptor.Customer, }; var refreshedProperties = refreshMock.RefreshedProperties; CollectionAssert.AreEquivalent(expectedRefreshedProperties, refreshedProperties); }
private bool Matches(IViewModel parent, PathIterator nextStep) { if (!nextStep.HasStep) { return(false); } if (!(parent.Descriptor is TDescriptor)) { return(false); } TDescriptor descriptor = (TDescriptor)parent.Descriptor; IVMPropertyDescriptor expectedProperty = _propertySelector.GetProperty(descriptor); if (nextStep.IsProperty) { return(nextStep.Property == expectedProperty); } object expectedPropertyValue = parent.Kernel.GetValue(expectedProperty); if (nextStep.IsViewModel) { return(nextStep.ViewModel == expectedPropertyValue); } if (nextStep.IsCollection) { return(nextStep.Collection == expectedPropertyValue); } throw new NotSupportedException(); }
private void AssertDefaultCollectionPropertyBehaviors <T>(IVMPropertyDescriptor <IVMCollection <T> > p) where T : IViewModel { AssertBasicPropertyBehaviors <IVMCollection <T> >(p); Assert.IsTrue(ContainsBehavior <CollectionFactoryBehavior <T> >(p)); Assert.IsTrue(ContainsBehavior <ItemDescriptorProviderBehavior>(p)); Assert.IsTrue(ContainsBehavior <CollectionValidationSourceBehavior <T> >(p)); }
private static PropertyDescriptor GetDescriptor(IVMPropertyDescriptor property) { return(property .Behaviors .GetNextBehavior <IPropertyDescriptorProviderBehavior>() .PropertyDescriptor); }
protected virtual ICommand CreateCommand( IViewModel ownerVM, IVMPropertyDescriptor ownerProperty ) { return(new ViewModelCommand(ownerVM, ownerProperty)); }
public void UpdateFromSource(IBehaviorContext context, IVMPropertyDescriptor property) { RequireInitialized(); throw new NotImplementedException(); //this.UpdateFromSourceNext(context, property); }
protected override void PerformValidation( Action <string> addValidationErrorAction, ValidatorType type, IViewModel owner, IViewModel targetVM, object validatorKey, IVMPropertyDescriptor targetProperty = null ) { bool validate = false; switch (type) { case ValidatorType.Property: if ((EnabledValidators & ValidatorTypes.Property) == ValidatorTypes.Property) { validate = true; } break; case ValidatorType.ViewModel: if ((EnabledValidators & ValidatorTypes.ViewModel) == ValidatorTypes.ViewModel) { validate = true; } break; } if (validate) { base.PerformValidation(addValidationErrorAction, type, owner, targetVM, validatorKey, targetProperty); } }
private void AssertBehavior <TBehavior>(IVMPropertyDescriptor property, BehaviorKey key, Action <TBehavior> assertion) where TBehavior : IBehavior { Assert.IsNotNull(property); Config .PropertyConfigurations[property] .ConfigureBehavior <TBehavior>(key, assertion); }
public void Refresh( IBehaviorContext context, IVMPropertyDescriptor property, RefreshOptions options ) { this.ViewModelRefreshNext(context, property, options); }
public void EnablePropertyValidationSourceBehavior(IVMPropertyDescriptor property) { EnableValidationExecutorBehavior(); Config .PropertyConfigurations[property] .Enable(PropertyBehaviorKeys.ValueValidationSource); }
public void Initialize(BehaviorInitializationContext context) { _property = context.Property; _resultManager = new ValidationResultManager(context, ValidationResultGroup, _stage); _invalidValueCache = new DynamicFieldAccessor <TValue>(context, InvalidValueGroup); _validationController = new DynamicFieldAccessor <ValidationController>(context, ValidationControllerGroup); this.InitializeNext(context); }
public static void SetDisplayValue( this IViewModel viewModel, IVMPropertyDescriptor property, object value ) { viewModel.Kernel.SetDisplayValue(property, value); }
/// <param name="ownerProperty"> /// The descriptor holds the collection behaviors and other metadata. /// </param> /// <param name="ownerVM"> /// The view model instance that holds this collection instance. It is /// the parent of all items. /// </param> public VMCollection(IViewModel ownerVM, IVMPropertyDescriptor ownerProperty) { Check.NotNull(ownerVM, nameof(ownerVM)); Check.NotNull(ownerProperty, nameof(ownerProperty)); OwnerVM = ownerVM; OwnerProperty = ownerProperty; }
public IValidatorInvocationBuilder Targeting <TDescriptor>( IViewModel <TDescriptor> target, Func <TDescriptor, IVMPropertyDescriptor> targetPropertySelector ) where TDescriptor : IVMDescriptor { _target = target; _targetProperty = targetPropertySelector((TDescriptor)target.Descriptor); return(this); }
private bool ContainsBehavior <T>(IVMPropertyDescriptor property) where T : IBehavior { var config = Configuration.PropertyConfigurations[property]; BehaviorChain chain = config.CreateChain(); T behavior; return(chain.TryGetBehavior <T>(out behavior)); }
public IValidatorInvocationBuilder Targeting <TDescriptor>( IVMCollectionExpression <IViewModel <TDescriptor> > target, Func <TDescriptor, IVMPropertyDescriptor> targetPropertySelector ) where TDescriptor : IVMDescriptor { _targetCollection = (IVMCollection)target; _targetProperty = targetPropertySelector((TDescriptor)_targetCollection.GetItemDescriptor()); return(this); }
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); }
public void RefreshContainer( IVMPropertyDescriptor property, bool executeRefreshDependencies = false ) { RefreshTrace.BeginManualRefresh(); RefreshInternal(property, new RefreshOptions(RefreshScope.Container, executeRefreshDependencies)); RefreshTrace.EndLastRefresh(); }
public virtual void Initialize(BehaviorInitializationContext context) { _cache = new DynamicFieldAccessor <TValue>(context, ValueCacheGroup); _isProviding = new DynamicFieldAccessor <bool>(context, IsProvidingGroup); _property = context.Property; SetInitialized(); this.InitializeNext(context); }
public void DependencyOnTargetPropertiesOfDescendantOfDescendantCollection_RefreshesSpecifiedPropertiesDescendantsInCollection() { var refreshMock = new RefreshControllerBehaviorMock(); var projectVMDescriptor = ProjectVM.CreateDescriptor(refreshMock, true); var employeeVM = CreateEmployeeVM( b => b .OnChangeOf .Properties(x => x.Name) .Refresh .Descendant(x => x.Projects) .Descendant(x => x.Customer) .Properties(x => x.Name, x => x.Rating), projectVMDescriptor ); var projectVM1 = CreateProjectVM(); var projectVM2 = CreateProjectVM(); employeeVM.Projects.Add(projectVM1); employeeVM.Projects.Add(projectVM2); var customerVM1 = CreateCustomerVM(); customerVM1.Name = "aValidName"; var customerVM2 = CreateCustomerVM(); customerVM2.Name = "aValidName"; projectVM1.Customer = customerVM1; projectVM2.Customer = customerVM2; employeeVM.Name = "TriggerChange"; var expectedRefreshedPropertiesOnCustomer1 = new IVMPropertyDescriptor[] { customerVM1.Descriptor.Name, customerVM1.Descriptor.Rating }; var expectedRefreshedPropertiesOnCustomer2 = new IVMPropertyDescriptor[] { customerVM2.Descriptor.Name, customerVM2.Descriptor.Rating }; var refreshedPropertiesOnCustomer1 = customerVM1.RefreshControllerBehaviorMock.RefreshedProperties; var refreshedPropertiesOnCustomer2 = customerVM2.RefreshControllerBehaviorMock.RefreshedProperties; CollectionAssert.AreEquivalent( expectedRefreshedPropertiesOnCustomer1, refreshedPropertiesOnCustomer1 ); CollectionAssert.AreEquivalent( expectedRefreshedPropertiesOnCustomer2, refreshedPropertiesOnCustomer2 ); }
public ValidationResultManager( BehaviorInitializationContext context, FieldDefinitionGroup fieldGroup, ValueStage stage ) { _resultField = new DynamicFieldAccessor <ValidationResult>(context, fieldGroup); _property = context.Property; _stage = stage; }
public ValidationRequest( ValidationStep step, IViewModel vm, IVMPropertyDescriptor property ) : this(step, Path.Empty.Prepend(property).Prepend(vm)) { Check.NotNull(vm, nameof(vm)); Check.NotNull(property, nameof(property)); }
public SetValueAction( IViewModel vm, IVMPropertyDescriptor property, TValue originalValue ) { _vm = vm; _property = property; _originalValue = originalValue; }