Inheritance: System.ComponentModel.DataAnnotations.ValidationAttribute
        public void ValidateDoesNotThrowWhenComparedObjectsAreEqual()
        {
            object otherObject = new CompareObject("test");
            CompareObject currentObject = new CompareObject("test");
            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            EqualToAttribute attr = new EqualToAttribute("CompareProperty");
            attr.Validate(currentObject.CompareProperty, testContext);
        }
        public void ValidateThrowsWhenComparedObjectsAreNotEqual()
        {
            CompareObject currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            EqualToAttribute attr = new EqualToAttribute("CompareProperty");

            attr.Validate(currentObject.CompareProperty, testContext);
        }
        public void ErrorMessageTest()
        {
            var currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessage = "SampleErrorMessage"
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual("SampleErrorMessage", result.ErrorMessage);
        }
        public void ErrorResourcesTest()
        {
            var currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
                                {
                                    ErrorMessageResourceName = "ErrorMessage",
                                    ErrorMessageResourceType = typeof (ErrorResources)
                                };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage);
        }
        public void GlobalizedErrorResourcesTest()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");

            var currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessageResourceName = "ErrorMessage",
                ErrorMessageResourceType = typeof(ErrorResources)
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual("mensaje de error", result.ErrorMessage);
        }