public void ApplyParameters_CalledOnNonNull_WithNonNullInvalidParams_ThrowsCorrectException( List <NavigationParameterModel> parameters) { IViewModelBase viewModel = new ViewModelStub(); Assert.ThrowsAny <Exception>(() => viewModel.ApplyParameters(parameters)); }
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 InitializeValue_WhenInitialValueIsNull_DoesNothing() { ViewModelStub initialValue = null; Next.ValueToReturn = initialValue; Behavior.InitializeValue(Context); }
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 TestRaiseValidInvalidPropertyName() { var vm = new ViewModelStub(); var receivedPropertyChanged = false; var invalidPropertyNameReceived = false; vm.PropertyChanged += (s, e) => { if (e.PropertyName == ViewModelStub.RealPropertyPropertyName) { receivedPropertyChanged = true; } else { invalidPropertyNameReceived = true; } }; vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName); Assert.IsTrue(receivedPropertyChanged); Assert.IsFalse(invalidPropertyNameReceived); vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName + "1"); Assert.IsTrue(invalidPropertyNameReceived); }
public void Setup() { Behavior = new ItemProviderBehavior <TestSourceObject, TestSourceItem>(); Context = ViewModelStub .WithBehaviors(Behavior) .BuildContext(); }
public void TryPopViewModel_WithEmptyBackStack_ReturnsFalse() { IViewModelBase result = new ViewModelStub(); var popped = _backStackManager.TryPopViewModel(out result); Assert.False(popped); Assert.Null(result); }
public void SetValue_PreviousValueWasNull_AddsParentToNewValue() { var newValue = new ViewModelStub(); Next.ValueToReturn = null; Behavior.SetValue(Context, newValue); Assert.IsTrue(newValue.Kernel.Parents.Contains(Context.VM)); }
public void IDataErrorInfoErrorPropertyIsNotSupported() { Assert.Throws<NotSupportedException>(() => { ViewModelStub viewModel = new ViewModelStub(); string value = viewModel.Error; }); }
public void InitializeValue_AddsParent() { var initialValue = new ViewModelStub(); Next.ValueToReturn = initialValue; Behavior.InitializeValue(Context); Assert.IsTrue(initialValue.Kernel.Parents.Contains(Context.VM)); }
public void Setup() { var behavior = new TestBehavior(ValueStage.Value); VM = ViewModelStub.WithBehaviors(behavior).Build(); Manager = behavior.Manager; Context = new BehaviorContextStub(VM); }
public void GetManager_RootViewModelContainsBehavior_ReturnsManager() { var rootVM = new ViewModelStub(new UndoRootBehavior()); var foundManager = UndoManager.GetManager(rootVM); Assert.IsNotNull(foundManager); }
public void IndexerValidatesPropertyNameWithValidValue() { ViewModelStub viewModel = new ViewModelStub { RequiredProperty = "Some Value" }; Assert.IsNull(viewModel["RequiredProperty"]); }
public void HandleChange_DescendantValidationStateChanged_PerformsViewModelValidation() { var args = ChangeArgs.ValidationResultChanged() .PrependViewModel(VM) .PrependViewModel(ViewModelStub.Build()); Behavior.HandleChange(Context, args); Assert.AreEqual(HandleChangeNext + Validate + RevalidateNext, ActionLog); }
public void ViewModelPropertyChanged_SetsOldAndNewItems() { var property = PropertyStub.Build(); var newValue = ViewModelStub.Build(); var args = ChangeArgs.ViewModelPropertyChanged(property, ValueStage.ValidatedValue, null, newValue); CollectionAssert.AreEqual(new IViewModel[0], args.OldItems.ToArray()); CollectionAssert.AreEqual(new IViewModel[] { newValue }, args.NewItems.ToArray()); }
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 ViewModelBase_NotifiesWhenIsBusyChanges(bool initialIsBusy, bool changedIsBusy) { var vm = new ViewModelStub() { IsBusy = initialIsBusy }; Assert.PropertyChanged(vm, nameof(vm.IsBusy), () => vm.IsBusy = changedIsBusy); }
public void HandleChange_WithPropertyChangedOfOwnViewModelProperty_UpdatesCachedResults() { var owner = new TestVM(); owner.MakePropertiesAndViewModelInvalid(); var expected = owner.GetCurrentlySetupResults(); // S E T C H I L D var firstChild = new ViewModelStub { ValidationResult = CreateValidationResult("First child error") }; var propertyChangedArgs = ChangeArgs .ViewModelPropertyChanged( owner.SecondProperty, ValueStage.ValidatedValue, oldValue: null, newValue: firstChild) .PrependViewModel(owner); owner.CallHandleChangeWith(propertyChangedArgs); expected.Descenants = firstChild.ValidationResult; AssertBehaviorResults(owner, expected); // C H A N G E C H I L D var secondChild = new ViewModelStub { ValidationResult = CreateValidationResult("Second child error") }; propertyChangedArgs = ChangeArgs .ViewModelPropertyChanged( owner.SecondProperty, ValueStage.ValidatedValue, oldValue: firstChild, newValue: secondChild) .PrependViewModel(owner); owner.CallHandleChangeWith(propertyChangedArgs); expected.Descenants = secondChild.ValidationResult; AssertBehaviorResults(owner, expected); // S E T C H I L D T O N U L L propertyChangedArgs = ChangeArgs .ViewModelPropertyChanged( owner.SecondProperty, ValueStage.ValidatedValue, oldValue: secondChild, newValue: null) .PrependViewModel(owner); owner.CallHandleChangeWith(propertyChangedArgs); expected.Descenants = ValidationResult.Valid; AssertBehaviorResults(owner, expected); }
public void OnInitialized_ChangesCorrespondingProperty() { var vm = new ViewModelStub(); Assert.False(vm.IsInitialized); vm.OnInitialize(); Assert.True(vm.IsInitialized); }
public void ViewModelBase_DoesNotNotifyWhenIsBusyNotChanges(bool initialIsBusy) { var vm = new ViewModelStub() { IsBusy = initialIsBusy }; Assert.Throws <PropertyChangedException>(() => Assert.PropertyChanged(vm, nameof(vm.IsBusy), () => vm.IsBusy = initialIsBusy)); }
public void ApplyParameters_CalledOnNonNull_WithNonNullValidParams_SetsCorrectProperties() { var viewModel = new ViewModelStub(); var parameters = FluentNavigatorExtensionsTestsDataProvider.ValidNavigationParams; viewModel.ApplyParameters(parameters); Assert.Equal(FluentNavigatorExtensionsTestsDataProvider.PropertyValue1, viewModel.StringParameter); Assert.Equal(FluentNavigatorExtensionsTestsDataProvider.PropertyValue2, viewModel.IntParameter); }
protected static ViewModelStub CreateInvalidVM(ValidationResult validationResult) { var behavior = new ValidationResultAggregatorStub(); behavior.ReturnedValidationResults[ValidationResultScope.All] = validationResult; return(ViewModelStub .WithBehaviors(behavior) .Build()); }
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 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 Bind_ViewModel_ModelIsBound() { var model = new ModelStub("Test", 2); var viewModel = new ViewModelStub(); viewModel.Bind(model); _collectionViewModel.Bind(viewModel); Assert.True(_collectionViewModel.IsBound(model)); }
public void SetValue_ToNull_RemovesParentFromPreviousValue() { var previousValue = new ViewModelStub(); previousValue.Kernel.Parents.Add(Context.VM); Next.ValueToReturn = previousValue; Behavior.SetValue(Context, null); Assert.IsFalse(previousValue.Kernel.Parents.Contains(Context.VM)); }
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 IndexerReturnsErrorMessageForRequestedInvalidProperty() { ViewModelStub viewModel = new ViewModelStub { RequiredProperty = null, SomeOtherProperty = null }; string errorMessage = viewModel["SomeOtherProperty"]; Assert.AreEqual("The SomeOtherProperty field is required.", errorMessage); }
public void TryPopViewModel_WithNonEmptyBackStack_ReturnsTrueAndViewModelAndRemoves( List <IViewModelBase> viewModels, IViewModelBase expectedResult) { InitializeBackStack(viewModels); IViewModelBase result = new ViewModelStub(); var popped = _backStackManager.TryPopViewModel(out result); Assert.True(popped); Assert.Equal(viewModels.Count - 1, _backStackManager.Count); Assert.Same(expectedResult, result); }
public void Bind_ViewModel_AddedToChildrenOnce() { var model = new ModelStub("Test", 2); var viewModel = new ViewModelStub(); viewModel.Bind(model); _collectionViewModel.Bind(viewModel); var child = _collectionViewModel.Children.Single(vm => Equals(vm.ActiveModel, model)); Assert.NotNull(child); }
public void ShouldMapViewModelToDomain() { const int Id = 1; const int Value = 100; const string Name = "Name"; var viewModelStub = new ViewModelStub { Id = Id, Name1 = Name, Value1 = Value }; var domainStub = DomainViewModelMapper<DomainStub, ViewModelStub>.Map(viewModelStub); Assert.That(domainStub.Id, Is.EqualTo(Id)); Assert.That(domainStub.Name1, Is.EqualTo(Name)); Assert.That(domainStub.Value1, Is.EqualTo(Value)); }
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() { ActionLogBuilder = new StringBuilder(); Behavior = new ViewModelValidationSourceBehavior(); Next = new NextBehavior(ActionLogBuilder); Executor = new TestExecutor(ActionLogBuilder); VM = ViewModelStub .WithBehaviors(Behavior, Next, Executor) .Build(); Context = VM.GetContext(); }
public void TestReturnValueWithStringSetNoBroadcast() { var vm = new ViewModelStub(); const int firstValue = 1234; var receivedValueChanged = 0; var receivedValueChanging = 0; vm.PropertyChanged += (s, e) => { if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName) { receivedValueChanged = vm.PropertyWithStringSetNoBroadcast; } }; #if !WP71 vm.PropertyChanging += (s, e) => { if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName) { receivedValueChanging = vm.PropertyWithStringSetNoBroadcast; } }; #endif vm.PropertyWithStringSetNoBroadcast = firstValue; #if !WP71 Assert.AreEqual(-1, receivedValueChanging); #endif Assert.AreEqual(firstValue, receivedValueChanged); Assert.IsTrue(vm.SetRaisedPropertyChangedEvent); vm.PropertyWithStringSetNoBroadcast = firstValue; #if !WP71 Assert.AreEqual(-1, receivedValueChanging); #endif Assert.AreEqual(firstValue, receivedValueChanged); Assert.IsFalse(vm.SetRaisedPropertyChangedEvent); vm.PropertyWithStringSetNoBroadcast = firstValue + 1; #if !WP71 Assert.AreEqual(firstValue, receivedValueChanging); #endif Assert.AreEqual(firstValue + 1, receivedValueChanged); Assert.IsTrue(vm.SetRaisedPropertyChangedEvent); }
public void TestSetWithStringNoBroadcast() { Messenger.Reset(); var vm = new ViewModelStub(); const int expectedValue = 1234; var receivedValueChanged = 0; var receivedValueChanging = 0; var receivedValueWithMessenger = 0; Messenger.Default.Register<PropertyChangedMessage<int>>(this, msg => receivedValueWithMessenger = msg.NewValue); vm.PropertyChanged += (s, e) => { if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName) { receivedValueChanged = vm.PropertyWithStringSetNoBroadcast; } }; #if !WP71 vm.PropertyChanging += (s, e) => { if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName) { receivedValueChanging = vm.PropertyWithStringSetNoBroadcast; } }; #endif vm.PropertyWithStringSetNoBroadcast = expectedValue; Assert.AreEqual(expectedValue, receivedValueChanged); #if !WP71 Assert.AreEqual(-1, receivedValueChanging); #endif Assert.AreEqual(0, receivedValueWithMessenger); }
public void TestRaiseValidInvalidPropertyName() { var vm = new ViewModelStub(); var receivedPropertyChanged = false; var invalidPropertyChangedNameReceived = false; var receivedPropertyChanging = false; var invalidPropertyChangingNameReceived = false; vm.PropertyChanged += (s, e) => { if (e.PropertyName == ViewModelStub.RealPropertyPropertyName) { receivedPropertyChanged = true; } else { invalidPropertyChangedNameReceived = true; } }; #if !WP71 vm.PropertyChanging += (s, e) => { if (e.PropertyName == ViewModelStub.RealPropertyPropertyName) { receivedPropertyChanging = true; } else { invalidPropertyChangingNameReceived = true; } }; vm.RaisePropertyChanging(ViewModelStub.RealPropertyPropertyName); #endif vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName); Assert.IsTrue(receivedPropertyChanged); Assert.IsFalse(invalidPropertyChangedNameReceived); #if !WP71 Assert.IsTrue(receivedPropertyChanging); Assert.IsFalse(invalidPropertyChangingNameReceived); #endif try { #if !WP71 vm.RaisePropertyChanging(ViewModelStub.RealPropertyPropertyName + "1"); #endif #if DEBUG Assert.Fail("ArgumentException was expected"); #else #if !WP71 Assert.IsTrue(invalidPropertyChangingNameReceived); #endif #endif } catch (ArgumentException) { } try { vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName + "1"); #if DEBUG Assert.Fail("ArgumentException was expected"); #else Assert.IsTrue(invalidPropertyChangedNameReceived); #endif } catch (ArgumentException) { } }
public void IndexerValidatesPropertyNameWithInvalidValue() { ViewModelStub viewModel = new ViewModelStub(); Assert.IsNotNull(viewModel["RequiredProperty"]); }
public void TestSetBroadcast() { Messenger.Reset(); var vm = new ViewModelStub(); const int expectedValue = 1234; var receivedValue = 0; var receivedValueWithMessenger = 0; Messenger.Default.Register<PropertyChangedMessage<int>>(this, msg => receivedValueWithMessenger = msg.NewValue); vm.PropertyChanged += (s, e) => { if (e.PropertyName == ViewModelStub.PropertyWithSetBroadcastPropertyName) { receivedValue = expectedValue; } }; vm.PropertyWithSetBroadcast = expectedValue; Assert.AreEqual(expectedValue, receivedValue); Assert.AreEqual(expectedValue, receivedValueWithMessenger); }