本文整理汇总了C#中Person.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# Person.Validate方法的具体用法?C# Person.Validate怎么用?C# Person.Validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.Validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PersonFirstnameValidationTest
public void PersonFirstnameValidationTest()
{
Person person = new Person();
Assert.IsNull(person.Firstname);
Assert.AreEqual(Resources.FirstnameMandatory, person.Validate("Firstname"));
person.Firstname = TestHelper.CreateString('A', 31);
Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, Resources.FirstnameMaxLength, "Firstname", 30),
person.Validate("Firstname"));
person.Firstname = TestHelper.CreateString('A', 30);
Assert.AreEqual("", person.Validate("Firstname"));
}
示例2: ValidationTest_NotMatch
public void ValidationTest_NotMatch()
{
Person person = new Person();
person.Validate();
Assert.IsFalse(person.HasErrors);
Assert.IsFalse(person.GetErrors().Any());
}
示例3: ValidationTest_Match
public void ValidationTest_Match()
{
Person person = new Person();
person.IsCouple = true;
person.Validate();
Assert.IsTrue(person.HasErrors);
Assert.AreEqual(Person.CoupleNameErrorMessage, person.GetErrors().Single().ErrorMessage);
Assert.AreEqual(Person.CoupleNameErrorMessage, person.GetErrors("CoupleName").Single().ErrorMessage);
}
示例4: ShouldThrowValidationExceptionOnFirstFailedValidation
public void ShouldThrowValidationExceptionOnFirstFailedValidation()
{
var person = new Person {Age = 25, Fouls = 10, Goals = 100, Name = "Some dude."};
TestDelegate testCode = () => person
.Validate(new ValidationOptions { StopOnFirstError = true, ThrowValidationExceptionOnValidationError = true })
.IsLesserThan(p => p.Age, 18, "You should be less than 18 years old.")
.IsGreaterThan(p => p.Goals, 200, "You should have scored more than 200 goals.");
var validationException = Assert.Throws<ValidationException>(testCode);
Assert.That(validationException.Errors.Count(), Is.EqualTo(1));
}
示例5: When_object_has_invariant_error_than_has_errors_after_validation
public void When_object_has_invariant_error_than_has_errors_after_validation()
{
//// Arrange
var person = new Person();
//// Act
person.HasInvariantError = true;
person.Validate();
//// Assert
Assert.IsTrue(person.HasErrors);
Assert.AreEqual(1, person.InvariantErrors.Count());
}
示例6: GeneralPersonTest
public void GeneralPersonTest()
{
Person person = new Person();
Assert.IsNotNull(person.Id);
person.Firstname = "Harry";
person.Lastname = "Potter";
person.Email = "[email protected]";
Assert.AreEqual("", person.Validate());
Assert.AreEqual("Harry Potter", person.ToString(null, CultureInfo.InvariantCulture));
}
示例7: When_property_has_error_than_object_has_errors_after_validation
public void When_property_has_error_than_object_has_errors_after_validation()
{
//// Arrange
var person = new Person();
person.AutoValidateProperties = false;
//// Act
person.Name = "foobar";
person.Validate();
//// Assert
Assert.IsTrue(person.HasErrors);
Assert.AreEqual(1, person.GetErrors("Name").Count());
}
示例8: PersonEmailValidationTest
public void PersonEmailValidationTest()
{
Person person = new Person();
Assert.IsNull(person.Email);
Assert.AreEqual("", person.Validate("Email"));
person.Email = TestHelper.CreateString('A', 92) + "@mail.com";
Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, Resources.EmailMaxLength, "Email", 100),
person.Validate("Email"));
person.Email = "my." + TestHelper.CreateString('A', 88) + "@mail.com";
Assert.AreEqual("", person.Validate("Email"));
person.Email = "harry.potter";
Assert.AreEqual(Resources.EmailInvalid, person.Validate("Email"));
person.Email = "[email protected]";
Assert.AreEqual(Resources.EmailInvalid, person.Validate("Email"));
person.Email = "[email protected]";
Assert.AreEqual("", person.Validate("Email"));
}
示例9: Validate_NoError
public void Validate_NoError()
{
var person = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = "Popov",
DOB = new DateTime(1953, 12, 10),
YearsInSpace = 12
};
var error = person.Validate();
Assert.IsNull( error );
}
示例10: Validate_Error_ValueList
public void Validate_Error_ValueList()
{
var person = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = "Popov",
DOB = new DateTime(1981, 2, 12),
YearsInSpace = 45,
Amount = 100,
Description="012345",
Classification = "INVALID"
};
var error = person.Validate();
Console.WriteLine( error );
Assert.IsInstanceOf(typeof(CRUDFieldValidationException), error);
Assert.AreEqual("Classification", ((CRUDFieldValidationException)error).FieldName);
Assert.IsTrue( error.Message.Contains("not in list of permitted values") );
person.Classification = "good";
Assert.IsNull( person.Validate() );
person.Classification = "bad";
Assert.IsNull( person.Validate() );
person.Classification = "ugly";
Assert.IsNull( person.Validate() );
}
示例11: Validate_Error_StringRequired
public void Validate_Error_StringRequired()
{
var person = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = null,
DOB = new DateTime(1953, 12, 10),
YearsInSpace = 12
};
var error = person.Validate();
Console.WriteLine( error );
Assert.IsInstanceOf(typeof(CRUDFieldValidationException), error);
Assert.AreEqual("LastName", ((CRUDFieldValidationException)error).FieldName);
}
示例12: Validate_Error_MaxLength
public void Validate_Error_MaxLength()
{
var person = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = "Popov",
DOB = new DateTime(1981, 2, 12),
YearsInSpace = 45,
Amount = 100,
Description="0123456789012345678901234567890"
};
var error = person.Validate();
Console.WriteLine( error );
Assert.IsInstanceOf(typeof(CRUDFieldValidationException), error);
Assert.AreEqual("Description", ((CRUDFieldValidationException)error).FieldName);
Assert.IsTrue( error.Message.Contains("exceeds max length") );
}
示例13: Validate_Error_DecimalMinMax_2
public void Validate_Error_DecimalMinMax_2()
{
var person = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = "Popov",
DOB = new DateTime(1953, 12, 10),
YearsInSpace = 45,
Amount = 2000000
};
var error = person.Validate();
Console.WriteLine( error );
Assert.IsInstanceOf(typeof(CRUDFieldValidationException), error);
Assert.AreEqual("Amount", ((CRUDFieldValidationException)error).FieldName);
Assert.IsTrue( error.Message.Contains("is above") );
}
示例14: Validate_Error_DateTimeMinMax_DifferentTarget
public void Validate_Error_DateTimeMinMax_DifferentTarget()
{
var person = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = "Popov",
DOB = new DateTime(1899, 12, 10),
YearsInSpace = 45,
Amount = 100
};
var error = person.Validate("sparta_system");
Assert.IsNull (error);
}
示例15: SuccessRiseErrorsChangedEvent
public void SuccessRiseErrorsChangedEvent()
{
Person person = new Person();
person.Validate();
AssertHelper.IsRaiseErrorChangedEvent(person, x => x.Name, () => person.Name = "Luke");
}