예제 #1
0
            public void ThrowsArgumentNullExceptionForNullValidator()
            {
                var compositeValidatorProvider = new CompositeValidatorProvider();

                ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(
                    () => compositeValidatorProvider.Remove(null));
            }
예제 #2
0
            public void EliminatesAnAlreadyAddedValidator()
            {
                var compositeValidatorProvider = new CompositeValidatorProvider();
                var validatorProviderMock1     = new Moq.Mock <IValidatorProvider>();
                var validatorProviderMock2     = new Moq.Mock <IValidatorProvider>();

                compositeValidatorProvider.Add(validatorProviderMock1.Object);
                compositeValidatorProvider.Add(validatorProviderMock2.Object);

                compositeValidatorProvider.Remove(validatorProviderMock1.Object);
                Assert.IsFalse(compositeValidatorProvider.Contains(validatorProviderMock1.Object));
            }
예제 #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // TODO: Using a custom IoC container like Unity? Register it here:
            // Catel.IoC.ServiceLocator.Instance.RegisterExternalContainer(MyUnityContainer);

            LogManager.AddDebugListener();

            var serviceLocator = IoC.ServiceLocator.Default;

            // Initialize composite validator provider to enable multiple validator sources
            var provider = new CompositeValidatorProvider();

            provider.Add(new ValidatorProvider());

            // serviceLocator.RegisterType<IValidatorProvider, ValidatorProvider>();
            serviceLocator.RegisterInstance <IValidatorProvider>(provider);

            base.OnStartup(e);
        }
예제 #4
0
            public void RetrieveTheRightSingleValidator()
            {
                var compositeValidatorProvider = new CompositeValidatorProvider();
                var validatorMock1             = new Moq.Mock <IValidator>();

                var validatorProviderMock1 = new Moq.Mock <IValidatorProvider>();

                validatorProviderMock1.Setup(provider => provider.GetValidator(typeof(FooViewModel))).Returns(validatorMock1.Object);

                var validatorProviderMock2 = new Moq.Mock <IValidatorProvider>();

                validatorProviderMock2.Setup(provider => provider.GetValidator(typeof(FooViewModel))).Returns(default(IValidator));

                compositeValidatorProvider.Add(validatorProviderMock1.Object);
                compositeValidatorProvider.Add(validatorProviderMock2.Object);

                IValidator validator = (compositeValidatorProvider as IValidatorProvider).GetValidator <FooViewModel>();

                Assert.AreEqual(validator, validatorMock1.Object);
            }
예제 #5
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            StyleHelper.CreateStyleForwardersForDefaultStyles();

            // TODO: Using a custom IoC container like Unity? Register it here:
            // Catel.IoC.ServiceLocator.Instance.RegisterExternalContainer(MyUnityContainer);

            LogManager.RegisterDebugListener();

            var serviceLocator = IoC.ServiceLocator.Default;

            // Initialize composite validator provider to enable multiple validator sources
            var provider = new CompositeValidatorProvider();
            provider.Add(new ValidatorProvider());
            provider.Add(new FluentValidatorProvider());

            // serviceLocator.RegisterType<IValidatorProvider, ValidatorProvider>();
            serviceLocator.RegisterInstance<IValidatorProvider>(provider);

            base.OnStartup(e);
        }
예제 #6
0
            public void RetrieveTheRightValidatorComposition()
            {
                var compositeValidatorProvider = new CompositeValidatorProvider();
                var validatorMock1             = new Moq.Mock <IValidator>();
                var validatorMock2             = new Moq.Mock <IValidator>();

                var validatorProviderMock1 = new Moq.Mock <IValidatorProvider>();

                validatorProviderMock1.Setup(provider => provider.GetValidator(typeof(FooViewModel))).Returns(validatorMock1.Object);

                var validatorProviderMock2 = new Moq.Mock <IValidatorProvider>();

                validatorProviderMock2.Setup(provider => provider.GetValidator(typeof(FooViewModel))).Returns(validatorMock2.Object);

                compositeValidatorProvider.Add(validatorProviderMock1.Object);
                compositeValidatorProvider.Add(validatorProviderMock2.Object);

                IValidator validator = (compositeValidatorProvider as IValidatorProvider).GetValidator <FooViewModel>();

                Assert.IsInstanceOfType(validator, typeof(CompositeValidator));
                ((CompositeValidator)validator).Contains(validatorMock1.Object);
                ((CompositeValidator)validator).Contains(validatorMock2.Object);
            }