public void ValidationAttribute_Fail_ResourceType_And_ErrorMessage()
        {
            DefaultTestAttribute attr = new DefaultTestAttribute()
            {
                ErrorMessage = "x", ErrorMessageResourceType = typeof(ResourceClass)
            };

            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                attr.FormatErrorMessage("");
            }, Resources.DataAnnotationsResources.ValidationAttribute_NeedBothResourceTypeAndResourceName);
        }
        public void ValidationAttribute_Fail_ResourceName_And_ErrorMessage()
        {
            DefaultTestAttribute attr = new DefaultTestAttribute()
            {
                ErrorMessage = "x", ErrorMessageResourceName = "y"
            };

            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                attr.FormatErrorMessage("");
            }, Resources.DataAnnotationsResources.ValidationAttribute_Cannot_Set_ErrorMessage_And_Resource);
        }
        public void Construction_ResourceMode_NonStringResource()
        {
            DefaultTestAttribute attr = new DefaultTestAttribute()
            {
                ErrorMessageResourceName = "NonStringResource",
                ErrorMessageResourceType = typeof(ResourceClass)
            };

            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                attr.FormatErrorMessage("");
            }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.ValidationAttribute_ResourcePropertyNotStringType, "NonStringResource", typeof(ValidationAttributeTest.ResourceClass).FullName));
        }
        public void ErrorMessageString_ResourceOverride()
        {
            var attribute = new DefaultTestAttribute()
            {
                ErrorMessageResourceName = "Resource2",
                ErrorMessageResourceType = typeof(ResourceClass)
            };

            Thread.CurrentThread.CurrentUICulture = _englishCulture;
            Assert.AreEqual <string>("Resource 2 Value", attribute.ErrorMessageString);

            Thread.CurrentThread.CurrentUICulture = _germanCulture;
            Assert.AreEqual <string>("Resource 2 Value DE", attribute.ErrorMessageString);
        }
        public void Construction_ResourceMode_PrivateResourceName()
        {
            // Setup
            DefaultTestAttribute attr = new DefaultTestAttribute()
            {
                ErrorMessageResourceName = "PrivateResource",
                ErrorMessageResourceType = typeof(ResourceClass)
            };

            // Execute & Verify
            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                attr.FormatErrorMessage("");
            }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.ValidationAttribute_ResourceTypeDoesNotHaveProperty, typeof(ValidationAttributeTest.ResourceClass).FullName, "PrivateResource"));
        }
        public void ValidationAttribute_Set_All_Props_No_Exceptions()
        {
            DefaultTestAttribute attr = new DefaultTestAttribute();

            attr.ErrorMessage             = "em";
            attr.ErrorMessageResourceName = "emName";
            attr.ErrorMessageResourceType = typeof(ResourceClass);

            attr.ErrorMessage             = string.Empty;
            attr.ErrorMessageResourceName = string.Empty;

            attr.ErrorMessage             = null;
            attr.ErrorMessageResourceName = null;
            attr.ErrorMessageResourceType = null;
        }
        public void Construction_ResourceMode_InternalResourceName()
        {
            // Setup
            DefaultTestAttribute attr = new DefaultTestAttribute()
            {
                ErrorMessageResourceName = "InternalResource",
                ErrorMessageResourceType = typeof(ResourceClass)
            };

            // Execute
            attr.FormatErrorMessage("");

            // Verify
            Assert.AreEqual("InternalResource 1", attr.ErrorMessageString);
            Assert.IsTrue(attr.CustomErrorMessageSet);
        }