public void Refresh_OfSimpleProperty_RevalidatesPropertyValue() { ParameterizedTest .TestCase("InstanceProperty", new Func <RootVMDescriptor, IVMPropertyDescriptor>(x => x.InstanceProperty)) .TestCase("MappedProperty", x => x.MappedProperty) .TestCase("DelegateProperty", x => x.DelegateProperty) .Run(propertySelector => { var property = propertySelector(VM.Descriptor); var expectedError = "Validation error"; VM.ValidationErrors[property] = expectedError; VM.Refresh(propertySelector); ValidationAssert.ErrorMessages(VM.GetValidationResult(property), expectedError); }); }
public void VariousOperations_WhenHandlerThrowsException_RaiseLifecycleExceptionOccuredEventAndThrowLifecycleException() { ParameterizedTest .TestCase <Action <ScreenLifecycleOperations>, IEvent>(x => x.Initialize(), ScreenEvents.Initialize()) .TestCase(x => x.Initialize(new Subject()), ScreenEvents.Initialize <Subject>()) .TestCase(x => x.Activate(), ScreenEvents.Activate) .TestCase(x => x.Deactivate(), ScreenEvents.Deactivate) .TestCase(x => x.RequestClose(), ScreenEvents.RequestClose) .TestCase(x => x.Close(), ScreenEvents.Close) .Run((lifecycleAction, expectedEvent) => { List <IEvent> actualEvents = new List <IEvent>(); TestScreen screen = new TestScreen(); ScreenLifecycleOperations ops = new ScreenLifecycleOperations(Aggregator, screen); InvalidOperationException sourceException = new InvalidOperationException(); AddEventHandlerForAllEvents( screen, handlerAction: e => { actualEvents.Add(e); throw sourceException; }, includeExceptionOccured: false ); AddEventHandlerFor( ScreenEvents.LifecycleExceptionOccured, screen, handlerAction: (ev, _) => actualEvents.Add(ev) ); var exceptionExpr = AssertHelper.Throws <ScreenLifecycleException>(() => lifecycleAction(ops) ); CollectionAssert.AreEquivalent( new IEvent[] { expectedEvent, ScreenEvents.LifecycleExceptionOccured }, actualEvents ); Assert.AreEqual(sourceException, exceptionExpr.Exception.InnerException); }); }
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 GetValidationResult_Initially_ReturnsValidResults() { var vm = new TestVM(); ParameterizedTest .TestCase(ValidationResultScope.PropertiesOnly) .TestCase(ValidationResultScope.ViewModelValidationsOnly) .TestCase(ValidationResultScope.Self) .TestCase(ValidationResultScope.Descendants) .TestCase(ValidationResultScope.All) .Run(scope => { var result = vm .Behavior .GetValidationResult(vm.GetContext(), scope); ValidationAssert.IsValid(result); }); }
public void Refresh_OfCollectionProperty_CallCollectionValidatorOnlyOnceForAllItems() { ParameterizedTest .TestCase("InstanceProperty", new Func <RootVMDescriptor, IVMPropertyDescriptor <IVMCollection <ChildVM> > >(x => x.InstanceProperty)) .TestCase("WrapperProperty", x => x.WrapperProperty) .TestCase("PopulatedProperty", x => x.PopulatedProperty) .Run(propertySelector => { var collection = VM.GetValue(propertySelector); var firstItem = new ChildVM(new ChildSource()); var secondItem = new ChildVM(new ChildSource()); collection.Add(firstItem); collection.Add(secondItem); VM.PopulatedPropertyResult = new List <ChildVM> { firstItem, secondItem }; VM.ValidatorResults.Reset(); VM.ValidatorResults.ExpectInvocationOf.CollectionPropertyValidation .Targeting(collection, x => x.ChildProperty) .On(VM); VM.Refresh(propertySelector); VM.ValidatorResults.VerifyInvocationSequence(); }); }