public void DefaultsForProviderAndExtendedPropertiesAreCorrect()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            MockControl control = new MockControl();

            Assert.AreEqual(null, validationProvider.ErrorProvider);
            Assert.AreEqual("", validationProvider.RulesetName);
            Assert.AreEqual(null, validationProvider.SourceTypeName);
            Assert.AreEqual(ValidationSpecificationSource.All, validationProvider.SpecificationSource);
            Assert.AreEqual(@"{0}", validationProvider.ValidationResultFormat);
            Assert.AreEqual(false, validationProvider.GetPerformValidation(control));
            Assert.AreEqual(null, validationProvider.GetSourcePropertyName(control));
            Assert.AreEqual("Text", validationProvider.GetValidatedProperty(control));
        }
        public void GettingValueForNonMappedPropertyThrows()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(PropertyMappedControlValueAccessFixtureTestClass).AssemblyQualifiedName;
            MockControl control = new MockControl();
            control.Text = "control text";
            validationProvider.SetSourcePropertyName(control, "StringProperty");

            PropertyMappedControlValueAccess valueAccess = new PropertyMappedControlValueAccess("NonMappedProperty");

            object value;
            string valueAccessFailureMessage;
            bool status = valueAccess.GetValue(validationProvider.GetExistingValidatedControlItem(control), out value, out valueAccessFailureMessage);
        }
        public void GetsValueFromOtherRegisteredControl()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(PropertyMappedControlValueAccessFixtureTestClass).AssemblyQualifiedName;
            MockControl control1 = new MockControl();
            control1.Text = "control1 text";
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            MockControl control2 = new MockControl();
            control2.Text = "control2 text";
            validationProvider.SetSourcePropertyName(control2, "ExtraStringProperty");

            PropertyMappedControlValueAccess valueAccess = new PropertyMappedControlValueAccess("ExtraStringProperty");

            object value;
            string valueAccessFailureMessage;
            bool status = valueAccess.GetValue(validationProvider.GetExistingValidatedControlItem(control1), out value, out valueAccessFailureMessage);

            Assert.AreEqual("control2 text", value);
        }
        public void ValidatedControlItemCanGetConvertedValueFromDefaultProperty()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidatedControlItemFixtureTestClass).AssemblyQualifiedName;
            MockControl control = new MockControl();
            control.Text = "5";
            control.IntControlProperty = 5;
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "IntProperty";

            object value;
            string failureMessage;
            bool status = validatedControlItem.GetValue(out value, out failureMessage);

            Assert.IsTrue(status);
            Assert.AreEqual(5, value);
            Assert.AreEqual(null, failureMessage);
        }
        public void RetunsExpectedValuesForIValidationIntegrationProxyImplementation()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.RulesetName = "ruleset";
            validationProvider.SourceTypeName = typeof(ValidatedControlItemFixtureTestClass).AssemblyQualifiedName;
            validationProvider.SpecificationSource = ValidationSpecificationSource.Configuration;
            MockControl control = new MockControl();
            control.Text = "value";
            control.IntControlProperty = 5;
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.ValidatedPropertyName = "Text";
            validatedControlItem.SourcePropertyName = "IntProperty";

            IValidationIntegrationProxy proxy = validatedControlItem;

            Assert.AreSame(typeof(ValidatedControlItemFixtureTestClass), proxy.ValidatedType);
            Assert.AreEqual("IntProperty", proxy.ValidatedPropertyName);
            Assert.AreEqual(ValidationSpecificationSource.Configuration, proxy.SpecificationSource);
            Assert.AreEqual("ruleset", proxy.Ruleset);
            Assert.AreSame(typeof(PropertyMappedControlValueAccessBuilder), proxy.GetMemberValueAccessBuilder().GetType());
        }
        public void CanPerformCrossFieldValidation()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "cross field";
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            MockControl control2 = new MockControl();
            validationProvider.SetSourcePropertyName(control2, "ExtraStringProperty");
            ValidatedControlItem validatedControlItem1 = validationProvider.GetExistingValidatedControlItem(control1);
            Validator validator = validatedControlItem1.Validator;

            control1.Text = "aaaaaa";
            control2.Text = "aaaabb";

            Assert.IsFalse(validator.Validate(validatedControlItem1).IsValid);

            control2.Text = "aaaaaa";

            Assert.IsTrue(validator.Validate(validatedControlItem1).IsValid);
        }
        public void ValueConvertingCallbackSettingConversionErrorMessageWillUseMessageOnErrorProviderIfExists()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.ValueConvert += OnValueConvertFailing;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "IntProperty");
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            control1.Text = "5";

            validationProvider.PerformValidation(control1);

            Assert.IsNotNull(valueConvertEventArgs); // callback was called
            Assert.AreEqual(0,
                            MockValidator<object>.CreatedValidators[0].ValidatedTargets.Count); // nothing got validated
            Assert.IsFalse(validationProvider.IsValid); // but the provider is invalid
            Assert.AreEqual("failed conversion", errorProvider.GetError(control1)); // and the error was set on the error provider
        }
        public void ValueConvertingCallbackIsInvokedIfSetWhenValidatingAndTheConvertedValueIsUsedForValidation()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.ValueConvert += OnValueConvert;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "IntProperty");

            control1.Text = "5";

            validationProvider.PerformValidation(control1);

            Assert.IsNotNull(valueConvertEventArgs);
            Assert.AreEqual(typeof(int), valueConvertEventArgs.TargetType);
            Assert.AreEqual("5", valueConvertEventArgs.ValueToConvert);
            Assert.AreEqual(500, valueConvertEventArgs.ConvertedValue);
            //Assert.AreSame(control1, this.valueConvertEventArgs.ValueSource);
            Assert.AreEqual("IntProperty", valueConvertEventArgs.SourcePropertyName);

            Assert.AreEqual(500, MockValidator<object>.CreatedValidators[0].ValidatedTargets[0]);
        }
        public void ExistingValidationErrorsAreClearedWhenDisablingValidationProviderButNotSetAgainWhenEnablingTheValidationProvider()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            control1.Text = "too long";

            validationProvider.PerformValidation(control1);

            Assert.AreEqual("validation", errorProvider.GetError(control1));

            validationProvider.Enabled = false; // set validation provider to disabled

            Assert.AreEqual("", errorProvider.GetError(control1));

            validationProvider.Enabled = true; // set validation provider to enabled

            Assert.AreEqual("", errorProvider.GetError(control1));
        }
        public void ValidationWillNotBePerformedIfValidationProviderIsDisabledAndCallbackWillNotBeInvoked()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.Enabled = false; // set validation provider to disabled
            validationProvider.ValidationPerformed += OnValidationPerformed;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");

            control1.Text = "too long";

            validationProvider.PerformValidation(control1);

            Assert.IsTrue(validationProvider.IsValid);
            Assert.IsNull(validationPerformedEventArgs);
        }
        public void PerformValidationOnNonExtendedControlThrows()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            MockControl control = new MockControl();

            validationProvider.PerformValidation(control);
        }
        public void ValueConversionIsPerformedWhenRequestingValueFromValueAccess()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(PropertyMappedControlValueAccessFixtureTestClass).AssemblyQualifiedName;
            validationProvider.ValueConvert += OnValueConvert;
            MockControl control = new MockControl();
            control.Text = "control text";
            validationProvider.SetSourcePropertyName(control, "StringProperty");

            PropertyMappedControlValueAccess valueAccess = new PropertyMappedControlValueAccess("StringProperty");

            object value;
            string valueAccessFailureMessage;
            bool status = valueAccess.GetValue(validationProvider.GetExistingValidatedControlItem(control), out value, out valueAccessFailureMessage);

            Assert.AreEqual("converted control text", value);
            Assert.AreEqual("control text", valueToConvert);
        }
        public void CanValidateThroughValueAccessValidatorUsingValueAccess()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(PropertyMappedControlValueAccessFixtureTestClass).AssemblyQualifiedName;
            MockControl control = new MockControl();
            control.Text = "control text";
            validationProvider.SetSourcePropertyName(control, "StringProperty");

            MockValidator valueValidator = new MockValidator(true, "message");
            Validator validator = new ValueAccessValidator(new PropertyMappedControlValueAccess("StringProperty"), valueValidator);

            ValidationResults validationResults
                = validator.Validate(validationProvider.GetExistingValidatedControlItem(control));

            Assert.IsFalse(validationResults.IsValid);
            IList<ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);
            Assert.AreEqual(1, resultsList.Count);
            Assert.AreEqual("StringProperty", resultsList[0].Key);
            Assert.AreEqual("message", resultsList[0].Message);
            Assert.AreEqual(null, resultsList[0].Tag);
            Assert.AreSame(validationProvider.GetExistingValidatedControlItem(control), resultsList[0].Target);
            Assert.AreSame(valueValidator, resultsList[0].Validator);
            Assert.AreEqual("control text", valueValidator.ValidatedTargets[0]);
        }
        public void CanValidateInstanceWithOwnValidator()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidatedControlItemFixtureTestClass).AssemblyQualifiedName;
            MockControl control = new MockControl();
            control.Text = "value";
            control.IntControlProperty = 5;
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "StringProperty";

            Validator validator = validatedControlItem.Validator;
            Assert.IsNotNull(validator);

            ValidationResults validationResults = validator.Validate(validatedControlItem);

            Assert.IsFalse(validationResults.IsValid);
            IList<ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);
            Assert.AreEqual(1, resultsList.Count);
            Assert.AreEqual("StringProperty message", resultsList[0].Message);
            Assert.AreEqual("value", MockValidator<object>.CreatedValidators[0].ValidatedTargets[0]);
        }
        public void ValidationProviderUnregistersControlsOnDispose()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.ValidationPerformed += OnValidationPerformed;
            MockControl control = new MockControl();
            validationProvider.SetSourcePropertyName(control, "StringProperty");
            validationProvider.SetPerformValidation(control, true);

            control.Text = "too long";
            bool cancel = control.FireValidating();

            Assert.IsTrue(cancel);
            Assert.IsNotNull(validationStatusOnCallback);

            validationStatusOnCallback = null;
            validationProvider.Dispose();

            cancel = control.FireValidating();

            Assert.IsFalse(cancel);
            Assert.IsNull(validationStatusOnCallback);
        }
        public void PerformValidationOnExtendedControlWithoutSourcePropertyThrows()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            MockControl control = new MockControl();

            validationProvider.SetPerformValidation(control, true);

            validationProvider.PerformValidation(control);
        }
        public void ErrorsInErrorProviderForValidatedControlsAreClearedByValidatorProviderDispose()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            MockControl controlWithoutError = new MockControl();
            controlWithoutError.Text = "short";
            validationProvider.SetSourcePropertyName(controlWithoutError, "StringProperty");
            MockControl controlWithError = new MockControl();
            controlWithError.Text = "too long";
            validationProvider.SetSourcePropertyName(controlWithError, "StringProperty");
            MockControl controlWithoutValidation = new MockControl();
            controlWithoutValidation.Text = "too long";

            validationProvider.PerformValidation(controlWithoutError);
            validationProvider.PerformValidation(controlWithError);
            errorProvider.SetError(controlWithoutValidation, "an unmanaged error");

            Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithoutError));
            Assert.AreEqual("validation", errorProvider.GetError(controlWithError));
            Assert.AreEqual("an unmanaged error", errorProvider.GetError(controlWithoutValidation));

            validationProvider.Dispose();

            Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithoutError));
            Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithError));
            Assert.AreEqual("an unmanaged error", errorProvider.GetError(controlWithoutValidation));
        }
        public void ItemIsValidAfterPerformingSuccessfulValidationIfPreviouslyUnsucessful()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            MockControl control = new MockControl();
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "StringProperty";

            control.Text = "too long";
            validationProvider.PerformValidation(validatedControlItem);
            control.Text = "short";
            validationProvider.PerformValidation(validatedControlItem);

            Assert.IsTrue(validatedControlItem.IsValid);
        }
        public void AutomaticValidationWillNotBePerformedIfValidationProviderIsDisabled()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.Enabled = false; // set validation provider to disabled
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            validationProvider.SetPerformValidation(control1, true);

            control1.Text = "too long";

            bool cancel = control1.FireValidating();

            Assert.IsTrue(validationProvider.IsValid);
            Assert.IsFalse(cancel);
        }
        public void CallbackIsInvokedAfterPerformingUnsuccessfulValidation()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.ValidationPerformed += OnValidationPerformed;
            MockControl control = new MockControl();
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "StringProperty";

            control.Text = "too long";
            validationProvider.PerformValidation(validatedControlItem);

            Assert.IsNotNull(validationStatusOnCallback);
            Assert.AreSame(control, validationPerformedEventArgs.ValidatedControl);
            Assert.IsFalse(validationPerformedEventArgs.ValidationResults.IsValid);
        }
        public void InvalidValidationProviderBecomesValidWhenDisabledAndRemainsValidWhenReenabled()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");

            control1.Text = "too long";

            validationProvider.PerformValidation(control1);

            Assert.IsFalse(validationProvider.IsValid);

            validationProvider.Enabled = false; // set validation provider to disabled

            Assert.IsTrue(validationProvider.IsValid);

            validationProvider.Enabled = true; // set validation provider to enabled

            Assert.IsTrue(validationProvider.IsValid);
        }
        public void ErrorProviderErrorForControlIsClearedAfterPerformingSuccessfulValidation()
        {
            ErrorProvider errorProvider = new ErrorProvider();
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.ErrorProvider = errorProvider;
            MockControl control = new MockControl();
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "StringProperty";

            control.Text = "too long";
            validationProvider.PerformValidation(validatedControlItem);

            Assert.AreNotEqual(string.Empty, errorProvider.GetError(control));
        }
        public void CanGetSetPropertiesForControl()
        {
            ValidationProvider validationProvider = new ValidationProvider();

            MockControl control = new MockControl();

            validationProvider.SetPerformValidation(control, true);
            validationProvider.SetSourcePropertyName(control, "property");
            validationProvider.SetValidatedProperty(control, "controlproperty");

            Assert.AreEqual(true, validationProvider.GetPerformValidation(control));
            Assert.AreEqual("property", validationProvider.GetSourcePropertyName(control));
            Assert.AreEqual("controlproperty", validationProvider.GetValidatedProperty(control));
        }
        public void ValidationIsFiredAndCancelArgsIsSetToTrueOnValidatingEventIfExtendedControlDoesAllowValidationAndFails()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.ValidationPerformed += OnValidationPerformed;
            MockControl control = new MockControl();
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "StringProperty";
            validatedControlItem.PerformValidation = true;

            control.Text = "too long";
            bool cancel = control.FireValidating();

            Assert.IsTrue(cancel);
            Assert.IsNotNull(validationStatusOnCallback);
        }
        public void ValueConvertingCallbackSettingConversionErrorMessageWillCauseValidationToBeSkippedAndSetTheControlAsInvalid()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.ValueConvert += OnValueConvertFailing;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "IntProperty");

            control1.Text = "5";

            validationProvider.PerformValidation(control1);

            Assert.IsNotNull(valueConvertEventArgs); // callback was called
            Assert.AreEqual(0,
                            MockValidator<object>.CreatedValidators[0].ValidatedTargets.Count); // nothing got validated
            Assert.IsFalse(validationProvider.IsValid); // but the provider is invalid
        }
        public void ProviderWithMixedValidationOutcomesIsInvalid()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            MockControl control2 = new MockControl();
            validationProvider.SetSourcePropertyName(control2, "StringProperty");

            control1.Text = "short";
            control2.Text = "too long";

            validationProvider.PerformValidation(control1);
            validationProvider.PerformValidation(control2);

            Assert.IsFalse(validationProvider.IsValid);
        }
        public void RequestForExistingValidatedControlItemForNonMappedPropertyNameReturnsNull()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            MockControl control2 = new MockControl();
            validationProvider.SetSourcePropertyName(control2, "IntProperty");

            Assert.IsNull(validationProvider.GetExistingValidatedControlItem("NonMappedProperty"));
        }
        public void ProviderWithTwoUnsuccesfullyValidatedControlsBecomesValidAfterBothControlsSucceed()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            MockControl control2 = new MockControl();
            validationProvider.SetSourcePropertyName(control2, "StringProperty");

            control1.Text = "too long";
            control2.Text = "too long";
            validationProvider.PerformValidation(control1);
            validationProvider.PerformValidation(control2);

            Assert.IsFalse(validationProvider.IsValid);

            control1.Text = "short";
            validationProvider.PerformValidation(control1);

            Assert.IsFalse(validationProvider.IsValid);

            control2.Text = "short";
            validationProvider.PerformValidation(control2);

            Assert.IsTrue(validationProvider.IsValid);
        }
        public void ValidationIsClearedForControlWhenControlPropertyIsSetAndErrorIsCleared()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            ValidatedControlItem controlItem1 = validationProvider.GetExistingValidatedControlItem(control1);
            MockControl control2 = new MockControl();
            validationProvider.SetSourcePropertyName(control2, "StringProperty");
            ValidatedControlItem controlItem2 = validationProvider.GetExistingValidatedControlItem(control2);
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            control1.Text = "000000000001";
            control2.Text = "000000000001";

            validationProvider.PerformValidation(control1);
            validationProvider.PerformValidation(control2);

            Assert.IsFalse(validationProvider.IsValid);
            Assert.IsFalse(controlItem1.IsValid);
            Assert.IsFalse(controlItem2.IsValid);
            Assert.AreEqual("string property", errorProvider.GetError(control1));
            Assert.AreEqual("string property", errorProvider.GetError(control2));

            validationProvider.ValidationPerformed += OnValidationPerformed;
            validationProvider.SetSourcePropertyName(control2, "IntProperty");

            Assert.IsFalse(validationProvider.IsValid);
            Assert.IsFalse(controlItem1.IsValid);
            Assert.IsTrue(controlItem2.IsValid);
            Assert.AreEqual("string property", errorProvider.GetError(control1));
            Assert.AreEqual(string.Empty, errorProvider.GetError(control2));
            Assert.IsNull(validationPerformedEventArgs);

            validationProvider.PerformValidation(control2);

            Assert.IsFalse(validationProvider.IsValid);
            Assert.IsFalse(controlItem1.IsValid);
            Assert.IsFalse(controlItem2.IsValid);
            Assert.AreEqual("string property", errorProvider.GetError(control1));
            Assert.AreEqual("int property", errorProvider.GetError(control2));
            Assert.IsNotNull(validationPerformedEventArgs);
        }
        public void RequestForValueFromInvalidNonDefaultPropertyThrows()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidatedControlItemFixtureTestClass).AssemblyQualifiedName;
            MockControl control = new MockControl();
            control.Text = "value";
            control.IntControlProperty = 5;
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.ValidatedPropertyName = "InvalidControlProperty";
            validatedControlItem.SourcePropertyName = "IntProperty";

            object value;
            string failureMessage;
            bool status = validatedControlItem.GetValue(out value, out failureMessage);
        }