コード例 #1
0
        public void SuccessfulValidationIncrementsValidationSuccessCounterPerSecond()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper <object>  validator = new GenericValidatorWrapper <object>(new MockValidator(false), instrumentationProvider);

            validator.Validate(this);
            Assert.AreEqual(1L, validationSucceededPerSecond.RawValue);
        }
コード例 #2
0
        public void CallingValidateIncrementsValidationCalledCounterPerSecond()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper <object>  validator = new GenericValidatorWrapper <object>(new MockValidator(false), instrumentationProvider);

            validator.Validate(this);
            Assert.AreEqual(1L, validationCallsPerSecCounter.RawValue);
        }
コード例 #3
0
        private static Validator <T> WrapAndInstrumentValidator <T>(Validator validator, IConfigurationSource configurationSource)
        {
            GenericValidatorWrapper <T> validatorWrapper = new GenericValidatorWrapper <T>(validator);

            AttachInstrumentationListener(validatorWrapper, configurationSource);

            return(validatorWrapper);
        }
コード例 #4
0
        public void FailedValidationIncrementsFailedValidationCounter()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper <object>  validator = new GenericValidatorWrapper <object>(new MockValidator(true), instrumentationProvider);

            validator.Validate(this);
            Assert.AreEqual(1L, validationFailures.RawValue);
        }
コード例 #5
0
        public void CallingValidateIncrementsNumberOfValidationCallsCounter()
        {
            GenericValidatorWrapper <object> validator = new GenericValidatorWrapper <object>(new MockValidator(false),
                                                                                              new ValidationInstrumentationProvider
                                                                                                  (true, false, formatter));

            validator.Validate(this);
            Assert.AreEqual(1L, validationCallsCounter.RawValue);
        }
コード例 #6
0
        /// <summary>
        /// Wraps a <see cref="Validator{T}"/> with a <see cref="GenericValidatorWrapper{T}"/> for instrumentation purposes.
        /// </summary>
        /// <typeparam name="T">Validator's target type.</typeparam>
        /// <param name="validator">Validator to wrap</param>
        /// <param name="unusedType">Not used in this implementation of WrapAndInstrumentValidator</param>
        /// <returns>A new, wrapped validator.</returns>
        protected virtual Validator <T> WrapAndInstrumentValidator <T>(Validator validator, Type unusedType)
        {
            var validatorWrapper = new GenericValidatorWrapper <T>(
                validator,
                InstrumentationProvider
                );

            return(validatorWrapper);
        }
コード例 #7
0
        public void SuccessfulValidationIncrementsValidationSuccessCounterPerSecond()
        {
            GenericValidatorWrapper <object>  validator = new GenericValidatorWrapper <object>(new MockValidator(false));
            ValidationInstrumentationListener instrumentationListener = new ValidationInstrumentationListener(true, false, false, formatter);

            new ReflectionInstrumentationBinder().Bind(validator.GetInstrumentationEventProvider(), instrumentationListener);

            validator.Validate(this);
            Assert.AreEqual(1L, validationSucceededPerSecond.RawValue);
        }
コード例 #8
0
        public void CallingValidateIncrementsNumberOfValidationCallsCounter()
        {
            GenericValidatorWrapper <object>  validator = new GenericValidatorWrapper <object>(new MockValidator(false));
            ValidationInstrumentationListener instrumentationListener = new ValidationInstrumentationListener(true, false, false, formatter);

            new ReflectionInstrumentationBinder().Bind(validator.GetInstrumentationEventProvider(), instrumentationListener);

            validator.Validate(this);
            Assert.AreEqual(1L, validationCallsCounter.RawValue);
        }
コード例 #9
0
        public void SuccessIsDeterminedByWrappedValidator()
        {
            string target = "";

            MockValidator <object> wrappedValidator = new MockValidator <object>(false, "message");
            Validator <string>     validator        = new GenericValidatorWrapper <string>(wrappedValidator);

            ValidationResults validationResults = validator.Validate(target);

            Assert.IsTrue(validationResults.IsValid);
            Assert.AreSame(target, wrappedValidator.ValidatedTargets[0]);
        }
コード例 #10
0
        public void SuccessIsDeterminedByWrappedValidator()
        {
            string target = "";

            MockValidator<object> wrappedValidator = new MockValidator<object>(false, "message");
            Validator<string> validator = new GenericValidatorWrapper<string>(wrappedValidator);

            ValidationResults validationResults = validator.Validate(target);

            Assert.IsTrue(validationResults.IsValid);
            Assert.AreSame(target, wrappedValidator.ValidatedTargets[0]);
        }
コード例 #11
0
        public void FailureIsDeterminedByWrappedValidator()
        {
            string target = "";

            MockValidator<object> wrappedValidator = new MockValidator<object>(true, "message");
            Validator<string> validator = new GenericValidatorWrapper<string>(wrappedValidator);

            ValidationResults validationResults = validator.Validate(target);

            Assert.IsFalse(validationResults.IsValid);
            Assert.AreSame(target, wrappedValidator.ValidatedTargets[0]);
            IList<ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);
            Assert.AreEqual(1, resultsList.Count);
            Assert.AreEqual("message", resultsList[0].Message);
        }
コード例 #12
0
        public void FailureIsDeterminedByWrappedValidator()
        {
            string target = "";

            MockValidator <object> wrappedValidator = new MockValidator <object>(true, "message");
            Validator <string>     validator        = new GenericValidatorWrapper <string>(wrappedValidator);

            ValidationResults validationResults = validator.Validate(target);

            Assert.IsFalse(validationResults.IsValid);
            Assert.AreSame(target, wrappedValidator.ValidatedTargets[0]);
            IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);

            Assert.AreEqual(1, resultsList.Count);
            Assert.AreEqual("message", resultsList[0].Message);
        }
コード例 #13
0
        public void PercentageSuccessIsUpdated()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper <object>  ValidValidator          = new GenericValidatorWrapper <object>(new MockValidator(false), instrumentationProvider);
            GenericValidatorWrapper <object>  InValidValidator        = new GenericValidatorWrapper <object>(new MockValidator(true), instrumentationProvider);


            ValidValidator.Validate(this);
            ValidValidator.Validate(this);
            ValidValidator.Validate(this);

            Assert.AreEqual(100f, percentageValidationSuccesses.NextValue());

            InValidValidator.Validate(this);
            Assert.AreEqual(75f, percentageValidationSuccesses.NextValue());
        }
コード例 #14
0
        public void FailedValidationIncrementsFailedValidationCounter()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper<object> validator = new GenericValidatorWrapper<object>(new MockValidator(true), instrumentationProvider);

            validator.Validate(this);
            Assert.AreEqual(1L, validationFailures.RawValue);
        }
コード例 #15
0
        public void SuccessfulValidationIncrementsValidationSuccessCounterPerSecond()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper<object> validator = new GenericValidatorWrapper<object>(new MockValidator(false), instrumentationProvider);

            validator.Validate(this);
            Assert.AreEqual(1L, validationSucceededPerSecond.RawValue);
        }
コード例 #16
0
        public void PercentageSuccessIsUpdated()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper<object> ValidValidator = new GenericValidatorWrapper<object>(new MockValidator(false), instrumentationProvider);
            GenericValidatorWrapper<object> InValidValidator = new GenericValidatorWrapper<object>(new MockValidator(true), instrumentationProvider);


            ValidValidator.Validate(this);
            ValidValidator.Validate(this);
            ValidValidator.Validate(this);

            Assert.AreEqual(100f, percentageValidationSuccesses.NextValue());

            InValidValidator.Validate(this);
            Assert.AreEqual(75f, percentageValidationSuccesses.NextValue());
        }
コード例 #17
0
 public void CallingValidateIncrementsNumberOfValidationCallsCounter()
 {
     GenericValidatorWrapper<object> validator = new GenericValidatorWrapper<object>(new MockValidator(false),
                                                                                     new ValidationInstrumentationProvider
                                                                                         (true, false, formatter));
     validator.Validate(this);
     Assert.AreEqual(1L, validationCallsCounter.RawValue);
 }
コード例 #18
0
        public void CallingValidateIncrementsValidationCalledCounterPerSecond()
        {
            ValidationInstrumentationProvider instrumentationProvider = new ValidationInstrumentationProvider(true, false, formatter);
            GenericValidatorWrapper<object> validator = new GenericValidatorWrapper<object>(new MockValidator(false), instrumentationProvider);

            validator.Validate(this);
            Assert.AreEqual(1L, validationCallsPerSecCounter.RawValue);
        }