Exemplo n.º 1
0
        public void IsValid_EqualValue()
        {
            AttributesModel   model   = new AttributesModel();
            ValidationContext context = new ValidationContext(model);

            Assert.Null(attribute.GetValidationResult(model.Sum, context));
        }
Exemplo n.º 2
0
        public void GetValidationResult_EqualValue()
        {
            ValidationContext context = new ValidationContext(new AllTypesView {
                StringField = "Test"
            });

            Assert.Null(attribute.GetValidationResult("Test", context));
        }
Exemplo n.º 3
0
        public void GetValidationResult_EqualValue()
        {
            ValidationContext context = new ValidationContext(new AdaptersModel {
                EqualTo = "Test"
            });

            Assert.Null(attribute.GetValidationResult("Test", context));
        }
Exemplo n.º 4
0
        public void GetValidationResult_NoProperty_Error()
        {
            attribute = new EqualToAttribute("Temp");
            ValidationContext context = new ValidationContext(new AllTypesView());

            String actual   = attribute.GetValidationResult("Test", context).ErrorMessage;
            String expected = Validation.For("EqualTo", context.DisplayName, "Temp");

            Assert.Equal(expected, actual);
        }
Exemplo n.º 5
0
        public void GetValidationResult_NoProperty_Error()
        {
            attribute = new EqualToAttribute("Temp");
            ValidationContext context = new ValidationContext(new AdaptersModel());

            String actual   = attribute.GetValidationResult("Test", context).ErrorMessage;
            String expected = String.Format(Validations.EqualTo, context.DisplayName, "Temp");

            Assert.Equal(expected, actual);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }