Beispiel #1
0
        public void Refresh_OfCollectionProperty_RevalidatesItems()
        {
            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 item       = new ChildVM(new ChildSource());
                collection.Add(item);
                VM.PopulatedPropertyResult = new List <ChildVM> {
                    item
                };

                VM.ValidatorResults.Reset();
                VM.Refresh(propertySelector);
                VM.ValidatorResults.VerifySetupValidationResults();

                VM.ValidatorResults.SetupFailing().CollectionPropertyValidation
                .Targeting(item, x => x.ChildProperty)
                .On(VM);
                VM.Refresh(propertySelector);
                VM.ValidatorResults.VerifySetupValidationResults();
            });
        }
Beispiel #2
0
        public void VariousOperations_PublishCorrectEvents()
        {
            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);

                AddEventHandlerForAllEvents(
                    screen,
                    handlerAction: actualEvents.Add,
                    includeExceptionOccured: true
                    );

                lifecycleAction(ops);

                IEvent actualEvent = actualEvents.SingleOrDefault();
                Assert.AreEqual(expectedEvent, actualEvent);
            });
        }
 public void ExceptionState_HandlesEventsCorrectly()
 {
     ParameterizedTest
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.LifecycleException))
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.Initialize))
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.InitializeSubject))
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.Activate))
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.Deactivate))
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.RequestClose))
     .TestCase(InvalidStateException(LifecycleState.ExceptionOccured, TriggerEvent.Close))
     .Run(ExecuteTestCase);
 }
 public void InitializedState_HandlesEventsCorrectly()
 {
     ParameterizedTest
     .TestCase(Success(LifecycleState.Initialized, TriggerEvent.Initialize, LifecycleState.Initialized))
     .TestCase(Success(LifecycleState.Initialized, TriggerEvent.InitializeSubject, LifecycleState.Initialized))
     .TestCase(Success(LifecycleState.Initialized, TriggerEvent.Activate, LifecycleState.Activated, ScreenEvents.Activate))
     .TestCase(Success(LifecycleState.Initialized, TriggerEvent.Close, LifecycleState.Closed, ScreenEvents.Close))
     .TestCase(Success(LifecycleState.Initialized, TriggerEvent.RequestClose, LifecycleState.Initialized, ScreenEvents.RequestClose))
     .TestCase(Success(LifecycleState.Initialized, TriggerEvent.LifecycleException, LifecycleState.ExceptionOccured, ScreenEvents.Close))
     .TestCase(InvalidStateException(LifecycleState.Initialized, TriggerEvent.Deactivate))
     .Run(ExecuteTestCase);
 }
        public void SetValue_RaisesAppropriateChangeNotifications()
        {
            ValueStage noChangeNotifciation = null;

            EmployeeVM vm = EmployeeVM.Create(b => {
                b.Check(x => x.NumericProperty).ValueInRange(min: 1, max: 10);
            });

            Action <int, int, int, ValueStage> testCode = (
                oldValue,
                oldSourceValue,
                newValue,
                expectedChangeNotification
                ) => {
                vm.SetValue(x => x.NumericProperty, oldSourceValue);
                vm.SetValue(x => x.NumericProperty, oldValue);
                vm.OnChangeInvocations.Clear();

                vm.SetValue(x => x.NumericProperty, newValue);

                IEnumerable <ChangeArgs> args = vm
                                                .OnChangeInvocations
                                                .Where(x => x.ChangeType == ChangeType.PropertyChanged);

                if (expectedChangeNotification != null)
                {
                    Assert.AreEqual(1, args.Count(), "Expected a single change notification.");

                    ChangeArgs arg = args.Single();
                    Assert.AreEqual(expectedChangeNotification, arg.Stage);
                }
                else
                {
                    Assert.AreEqual(0, args.Count(), "Expected no change notification.");
                }
            };

            // Valid values: { 5, 6 }, invalid values: { 77, 78 }
            ParameterizedTest
            // oldValue | oldSourceValue | newValue | expectedChange
            .TestCase(5, 5, 5, noChangeNotifciation)
            .TestCase(5, 5, 6, ValueStage.ValidatedValue)
            .TestCase(5, 5, 77, ValueStage.Value)
            .TestCase(77, 5, 77, noChangeNotifciation)
            .TestCase(77, 5, 78, ValueStage.Value)
            .TestCase(77, 5, 5, ValueStage.Value)
            .TestCase(77, 5, 6, ValueStage.ValidatedValue)
            .Run(testCode);
        }
        public void Refresh_OfViewModelProperty_RevalidatesPropertyValue()
        {
            ParameterizedTest
            .TestCase("InstanceProperty", new Func <RootVMDescriptor, IVMPropertyDescriptor>(x => x.InstanceProperty))
            .TestCase("MappedProperty", x => x.WrapperProperty)
            .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 ConvertFrom_String()
      {
         ParameterizedTest<string, OutlinerVersion> tester = new ParameterizedTest<string, OutlinerVersion>();
         tester.Method = delegate(string input)
         {
            OutlinerVersionConverter converter = new OutlinerVersionConverter();
            return converter.ConvertFrom(input) as OutlinerVersion;
         };

         tester.Test("1.0.0", new OutlinerVersion(1, 0, 0));
         tester.Test("1.0.0    ", new OutlinerVersion(1, 0, 0));
         tester.Test("1.0.0 alpha", new OutlinerVersion(1, 0, 0, ReleaseStage.Alpha));
         tester.Test("1.0.0 beta", new OutlinerVersion(1, 0, 0, ReleaseStage.Beta));
         tester.Test("2.3.4", new OutlinerVersion(2, 3, 4));
      }
Beispiel #8
0
        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 CompareTo()
      {
         ParameterizedTest<OutlinerVersion, OutlinerVersion, int> tester = new ParameterizedTest<OutlinerVersion, OutlinerVersion, int>();
         tester.Method = delegate(OutlinerVersion vX, OutlinerVersion vY)
         {
            return vX.CompareTo(vY);
         };

         tester.Test(new OutlinerVersion(), null, 1);
         tester.Test(new OutlinerVersion(), new OutlinerVersion(), 0);
         tester.Test(new OutlinerVersion(1, 0, 0), new OutlinerVersion(2, 0, 0), -1);
         tester.Test(new OutlinerVersion(1, 0, 0), new OutlinerVersion(1, 1, 0), -1);
         tester.Test(new OutlinerVersion(1, 0, 0), new OutlinerVersion(1, 0, 1), -1);
         tester.Test(new OutlinerVersion(1, 0, 0, ReleaseStage.Alpha), new OutlinerVersion(1, 0, 0, ReleaseStage.Beta), -1);
         tester.Test(new OutlinerVersion(1, 0, 0, ReleaseStage.Beta), new OutlinerVersion(1, 0, 0, ReleaseStage.Release), -1);
         tester.Test(new OutlinerVersion(2, 0, 0), new OutlinerVersion(1, 0, 0, 0), 1);
      }
        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);
            });
        }
Beispiel #11
0
        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);
            });
        }
Beispiel #12
0
        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();
            });
        }