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); }
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); }
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() { Behavior = new CommandAccessorMock(); OwnerProperty = PropertyStub .WithBehaviors(Behavior) .Build(); OwnerVM = ViewModelStub .WithProperties(OwnerProperty) .Build(); }
public void Setup() { Behavior = new RefreshablePropertyChangedNotifierBehavior <object>(); Property = PropertyStub .WithBehaviors(Behavior) .Build(); Context = ViewModelStub .WithProperties(Property) .BuildContext(); }
public void Setup() { ValueAccessor = new ValueAccessorStub <ChildVM>(); Behavior = new DelegateViewModelAccessorBehavior <ChildVM>(); Property = PropertyStub .WithBehaviors(Behavior, ValueAccessor) .Build(); Context = ViewModelStub .WithProperties(Property) .BuildContext(); }
public void Setup() { Handler = new HandlerMock(); OwnerProperty = PropertyStub .WithBehaviors(Handler) .Build(); OwnerVM = ViewModelStub .WithProperties(OwnerProperty) .Build(); Command = new ViewModelCommand(OwnerVM, OwnerProperty); }
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() { 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 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 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 CreateBehaviorContextFor(IVMPropertyDescriptor configuredProperty) { return(ViewModelStub .WithProperties(configuredProperty) .BuildContext()); }