private ModelValidator GetValidator(ModelMetadata metadata, ControllerContext context, ValidatorData item)
        {
            DataAnnotationsModelValidationFactory factory;
            if (item.GetType().Name == "NotNullValidatorData")
            {
                ValidationAttribute attribute = new RequiredAttribute { ErrorMessage = item.MessageTemplate };
                if (AttributeFactories.TryGetValue(attribute.GetType(), out factory))
                    return factory(metadata, context, attribute);
            }
            else if (item.GetType().Name == "RegexValidatorData")
            {
                RegexValidatorData regexData = (RegexValidatorData)item;

                RegularExpressionAttribute regexAttribute = new RegularExpressionAttribute(regexData.Pattern) { ErrorMessage = item.GetMessageTemplate() };

                if (AttributeFactories.TryGetValue(regexAttribute.GetType(), out factory))
                    return factory(metadata, context, regexAttribute);
            }

            return null;
        }
        public void Entity_Invoke_Validates_Required_Properties()
        {
            TestEntityContainer container = new TestEntityContainer();
            var invocableCity = new City();
            container.GetEntitySet<City>().Add(invocableCity);

            RequiredAttribute expectedAttribute = new RequiredAttribute();
            string expectedMember = "CityName";
            string expectedError = expectedAttribute.FormatErrorMessage(expectedMember);

            ExceptionHelper.ExpectValidationException(delegate
            {
                invocableCity.AssignCityZone("West");
            }, expectedError, expectedAttribute.GetType(), null);
        }