public void GetValue_CallingGetValueWithinProvideValue_ThrowsException() { PropertyStub <object> property = null; var provideValueWasAlreadyCalled = false; Func <IBehaviorContext, object> provideValueFunction = ctx => { Assert.IsFalse(provideValueWasAlreadyCalled); provideValueWasAlreadyCalled = true; property.Behaviors.GetValueNext <object>(ctx); return(new Object()); }; var behavior = new TestBehavior(provideValueFunction); property = PropertyStub .WithBehaviors(behavior) .Build(); var context = ViewModelStub .WithProperties(property) .BuildContext(); AssertHelper.Throws <InvalidOperationException>(() => behavior.GetValue(context) ).WithMessage(EViewModels.ValueAccessedWithinProvideValue); Assert.IsTrue(provideValueWasAlreadyCalled); }
public void GetValue_CallingGetValueWithinValueInitializer_DoesNotCallValueInitializerAgain() { PropertyStub <object> property = null; Func <IBehaviorContext, object> provideValueFunction = ctx => { return(new Object()); }; var behavior = new TestBehavior(provideValueFunction); var valueInitializerWasAlreadyInvoked = false; Action <IBehaviorContext> initializeValueAction = ctx => { Assert.IsFalse(valueInitializerWasAlreadyInvoked); valueInitializerWasAlreadyInvoked = true; property.Behaviors.GetValueNext <object>(ctx); }; property = PropertyStub .WithBehaviors(behavior, new TestValueInitializerBehavior(initializeValueAction)) .Build(); var context = ViewModelStub .WithProperties(property) .BuildContext(); behavior.GetValue(context); Assert.IsTrue(valueInitializerWasAlreadyInvoked); }
private void Setup(bool withCanExecutePredicate = false, bool canExecuteResult = false) { Func <SourceObject, bool> canExecuteFunction = null; if (withCanExecutePredicate) { canExecuteFunction = (so) => { LastCanExecuteInvocation = new DelegateInvocation { SourceObject = so }; return(canExecuteResult); }; } Action <SourceObject> executeAction = (so) => { LastExecuteInvocation = new DelegateInvocation { SourceObject = so }; }; Behavior = new DelegateCommandExecutorBehavior <SourceObject>(executeAction, canExecuteFunction); Next = new NextBehavior(); Context = PropertyStub .WithBehaviors(Behavior, Next) .GetContext(); }
public void Setup() { Behavior = new ViewModelInitializerBehavior <IViewModel>(); Next = new NextBehaviors(); Context = PropertyStub .WithBehaviors(Behavior, Next) .GetContext(); }
public void Setup() { Behavior = new StoredViewModelAccessorBehavior <ChildVM>(); Context = PropertyStub .WithBehaviors(Behavior) .GetContext(); }
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 Setup() { SourceAccessor = new ValueAccessorStub <ChildSource>(); Behavior = new WrapperViewModelAccessorBehavior <ChildVM, ChildSource>(); Context = PropertyStub .WithBehaviors(Behavior, SourceAccessor, new ServiceLocatorValueFactoryBehavior <ChildVM>()) .GetContext(); }
public void Setup() { Behavior = new TestDescendantsValidationBehavior(ActionLogBuilder); var property = PropertyStub .WithBehaviors(Behavior, Next) .Of <string>(); Context = CreateBehaviorContextFor(property); }
private TestViewModel( TestRevalidationBehavior viewModelBehavior, TestRevalidationBehavior propertyBehavior ) : this( PropertyStub.WithBehaviors(propertyBehavior).Of <string>(), viewModelBehavior ) { ViewModelBehavior = viewModelBehavior; PropertyBehavior = propertyBehavior; }
public void Setup() { Behavior = new RefreshablePropertyChangedNotifierBehavior <object>(); Property = PropertyStub .WithBehaviors(Behavior) .Build(); Context = ViewModelStub .WithProperties(Property) .BuildContext(); }
public void Setup() { Behavior = new CommandAccessorMock(); OwnerProperty = PropertyStub .WithBehaviors(Behavior) .Build(); OwnerVM = ViewModelStub .WithProperties(OwnerProperty) .Build(); }
public void Setup() { Behavior = new ViewModelPropertyDescendantsValidatorBehavior <ChildVM>(); ViewModelPropertyAccessor = new ValueAccessorStub <ChildVM>(); ViewModelPropertyAccessor.Value = new ChildVM(); var property = PropertyStub .WithBehaviors(Behavior, Next, ViewModelPropertyAccessor) .Of <string>(); Context = CreateBehaviorContextFor(property); }
public void Setup() { Behavior = new CollectionPropertyDescendantsValidatorBehavior <ViewModelStub>(); ViewModelPropertyAccessor = new ValueAccessorStub <IVMCollection <ViewModelStub> >(); ViewModelPropertyAccessor.Value = VMCollectionStub.Build(); var property = PropertyStub .WithBehaviors(Behavior, Next, ViewModelPropertyAccessor) .Of <string>(); Context = CreateBehaviorContextFor(property); }
public void Setup() { ValueAccessor = new ValueAccessorStub <ChildVM>(); Behavior = new DelegateViewModelAccessorBehavior <ChildVM>(); Property = PropertyStub .WithBehaviors(Behavior, ValueAccessor) .Build(); Context = ViewModelStub .WithProperties(Property) .BuildContext(); }
private static bool HandlePropertyChangedBehaviorWasCalled(ChangeArgs args) { var mock = new PropertyChangedMock(); var vm = ViewModelStub .WithProperties(PropertyStub .WithBehaviors(mock) .Build()) .Build(); vm.GetContext().NotifyChange(args); return(mock.PropertyChangedWasCalled); }
public void Setup() { Handler = new HandlerMock(); OwnerProperty = PropertyStub .WithBehaviors(Handler) .Build(); OwnerVM = ViewModelStub .WithProperties(OwnerProperty) .Build(); Command = new ViewModelCommand(OwnerVM, OwnerProperty); }
public void Setup() { ValidationResult = CreateValidationResult("Error"); Behavior = new TestValidationSourceBehavior(ValidationStep.Value); Property = PropertyStub.WithBehaviors(Behavior).Of <string>(); Executor = new ValidationExecutorStub(); var vm = ViewModelStub .WithProperties(Property) .WithBehaviors(Executor) .Build(); Context = new BehaviorContextStub(vm); }
protected void SetupFixture( ICollectionChangeHandlerBehavior <TItemVM> behavior, params IBehavior[] additionalBehaviors ) { Behavior = behavior; CollectionOwner = ViewModelStub .WithProperties(PropertyStub .WithBehaviors(behavior) .WithBehaviors(additionalBehaviors) .Build()) .Build(); Context = BehaviorContextStub .DecoratingContextOf(CollectionOwner) .Build(); }
public TestVM() { NextChangeHandler = new NextChangeHandlerBehavior(); Behavior = new CachingValidationResultAggregatorBehavior(); FirstProperty = PropertyStub .WithBehaviors(_firstPropertyResultProvider) .Of <object>(); SecondProperty = PropertyStub .WithBehaviors(_secondPropertyResultProvider) .Of <ViewModelStub>(); Descriptor = DescriptorStub .WithProperties(FirstProperty, SecondProperty) .WithBehaviors(Behavior, _viewModelResultProvider, NextChangeHandler) .Build(); }
public void Setup() { Behavior = new ValidationResultAggregatorBehavior(); var propertyBehavior = new ValidationResultProviderStub { ReturnedResult = PropertyResult, ReturnedDescendantsResult = DescendantResult }; var viewModelBehavior = new ValidationResultProviderStub { ReturnedResult = ViewModelResult }; var property = PropertyStub .WithBehaviors(propertyBehavior) .Of <ViewModelStub>(); Context = ViewModelStub .WithProperties(property) .WithBehaviors(Behavior, viewModelBehavior) .BuildContext(); }
public ItemInCollectionSetup(StringBuilder log) { ItemExecutor = new ValidationExecutorStub(); CollectionOwnerExecutor = new ValidationExecutorStub(); ItemProperty = PropertyStub .WithBehaviors(new RevalidationBehaviorSpy(log)) .Build(); Item = ViewModelStub .WithBehaviors(ItemExecutor, new RevalidationBehaviorSpy(log)) .WithProperties(ItemProperty) .Build(); var collectionOwner = ViewModelStub .WithBehaviors(CollectionOwnerExecutor) .Build(); Collection = VMCollectionStub .WithItems(Item) .WithOwner(collectionOwner) .Build(); }
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); }
protected BehaviorContextStub CreateContext(IBehavior collectionAccessorBehavior) { return(PropertyStub .WithBehaviors(collectionAccessorBehavior, Next) .GetContext()); }