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 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 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);
        }
        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 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 ValidatedControlIsUnregisteredOnDispose()
        {
            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);

            validationStatusOnCallback = null;
            validatedControlItem.Dispose();

            cancel = control.FireValidating();

            Assert.IsFalse(cancel);
            Assert.IsNull(validationStatusOnCallback);
        }
        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 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 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 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 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 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 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);
        }