Exemplo n.º 1
0
        public void RegisterXMLValidationConfiguration_TestLoadXML()
        {
            //
            // TODO: Add test logic	here
            //

            WFUtilities.RegisterXMLValidationConfiguration(Environment.CurrentDirectory + "\\Validator.config");

            Assert.AreEqual(1, WFUtilities.XmlRuleSets.Count());
            Assert.AreEqual(4, WFUtilities.XmlRuleSets[0].Properties.Count);
            Assert.AreEqual(2, WFUtilities.XmlRuleSets[0].Properties[0].Validators.Count);
        }
Exemplo n.º 2
0
        public void RegisterXMLValidationConfiguration_TestClassLevelValidators()
        {
            WFUtilities.RegisterXMLValidationConfiguration(Environment.CurrentDirectory + "\\Validator3.config");
            TestParticipantClass tpc = new TestParticipantClass();

            tpc.Password        = "******";
            tpc.ConfirmPassword = "******";
            WFModelMetaData metadata = new WFModelMetaData();

            WFUtilities.TryValidateModel(tpc, "", new WFObjectValueProvider(tpc, ""), metadata, new WFXmlRuleSetRuleProvider("ClassLevelAttributes"));

            Assert.AreEqual("Password fields must match.", metadata.Errors[0]);
        }
Exemplo n.º 3
0
        public void RegisterXMLValidationConfiguration_TestXMLErrorMessage()
        {
            WFUtilities.RegisterXMLValidationConfiguration(Environment.CurrentDirectory + "\\Validator2.config");

            string resourceErrorMessage = Resources.FirstName_ErrorMessage_Test1;

            TestParticipantClass tpc = new TestParticipantClass();

            WFModelMetaData metadata = new WFModelMetaData();


            //============================= WEB FORMS SERVER CONTROL VALIDATION =================================
            Page p = new Page();

            p.Controls.Add(new TextBox()
            {
                ID = "FirstName"
            });
            p.Controls.Add(new DataAnnotationValidatorControl()
            {
                PropertyName      = "FirstName",
                ControlToValidate = "FirstName",
                XmlRuleSetName    = "MessageFromValidator",
                ErrorMessage      = "This message from control itself."
            });

            p.Validators.Add(p.Controls[1] as IValidator);


            (p.Controls[1] as BaseValidator).Validate();
            Assert.AreEqual("This message from control itself.", (p.Controls[1] as DataAnnotationValidatorControl).ErrorMessage);

            p = new Page();
            p.Controls.Add(new TextBox()
            {
                ID = "FirstName"
            });
            p.Controls.Add(new DataAnnotationValidatorControl()
            {
                PropertyName      = "FirstName",
                ControlToValidate = "FirstName",
                XmlRuleSetName    = "MessageFromXML",
            });

            p.Validators.Add(p.Controls[1] as IValidator);


            (p.Controls[1] as BaseValidator).Validate();
            Assert.AreEqual("The First Name field cannot be empty.", (p.Controls[1] as DataAnnotationValidatorControl).ErrorMessage);

            p = new Page();
            p.Controls.Add(new TextBox()
            {
                ID = "FirstName"
            });
            p.Controls.Add(new DataAnnotationValidatorControl()
            {
                PropertyName      = "FirstName",
                ControlToValidate = "FirstName",
                XmlRuleSetName    = "MessageFromResource",
            });

            p.Validators.Add(p.Controls[1] as IValidator);


            (p.Controls[1] as BaseValidator).Validate();
            Assert.AreEqual("This value from resource.", (p.Controls[1] as DataAnnotationValidatorControl).ErrorMessage);

            //====================== TryValidateModel ==============================

            WFUtilities.TryValidateModel(tpc, "", new WFObjectValueProvider(tpc, ""), metadata, new WFXmlRuleSetRuleProvider("MessageFromValidator"));
            Assert.AreEqual("The FirstName field is required.", metadata.Errors[0]);
            metadata = new WFModelMetaData();
            WFUtilities.TryValidateModel(tpc, "", new WFObjectValueProvider(tpc, ""), metadata, new WFXmlRuleSetRuleProvider("MessageFromXML"));
            Assert.AreEqual("The First Name field cannot be empty.", metadata.Errors[0]);
            metadata = new WFModelMetaData();
            WFUtilities.TryValidateModel(tpc, "", new WFObjectValueProvider(tpc, ""), metadata, new WFXmlRuleSetRuleProvider("MessageFromResource"));
            Assert.AreEqual("This value from resource.", metadata.Errors[0]);
            metadata = new WFModelMetaData();
        }
Exemplo n.º 4
0
 protected void Application_Start(object sender, EventArgs e)
 {
     WFUtilities.RegisterXMLValidationConfiguration(Server.MapPath("\\") + "RegisterRules.xml");
 }