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 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 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);
        }