public void TestConstructor() { var errorMessage = "Error Message"; var propertyName = "Property"; var errorPath = new ErrorPath(); var instance = new SimpleValidationFailure(errorPath, errorMessage, propertyName); Assert.IsTrue(Object.ReferenceEquals(errorMessage, instance.ErrorMessage)); Assert.IsTrue(Object.ReferenceEquals(propertyName, instance.PropertyName)); Assert.IsTrue(Object.ReferenceEquals(errorPath, instance.CustomState)); }
public void TestSetByStaticLookup() { var id = 1; var value = "value"; var lookup = new StaticLookup(value, id); var instance = new ErrorPath(); instance.SetByStaticLookup(lookup); Assert.AreEqual(id, instance.SevisErrorTypeId); Assert.AreEqual(value, instance.SevisErrorTypeName); }
/// <summary> /// Creates a new instance with the given validation result. /// </summary> /// <param name="validationResult">The validation result to initialize this simple validation result with.</param> public SimpleValidationResult(ValidationResult validationResult) { Contract.Requires(validationResult != null, "The validation result must not be null."); this.IsValid = validationResult.IsValid; var errors = new List <SimpleValidationFailure>(); foreach (var error in validationResult.Errors) { ErrorPath errorPath = null; if (error.CustomState != null) { Contract.Assert(error.CustomState is ErrorPath, "The custom state object must be an error path."); errorPath = (ErrorPath)error.CustomState; } errors.Add(new SimpleValidationFailure(errorPath, error.ErrorMessage, error.PropertyName)); } this.Errors = errors.OrderBy(x => x.ErrorMessage); }
/// <summary> /// Creates a new SimpleValidationFailuren and initializes the instance properties. /// </summary> /// <param name="errorPath">The error path.</param> /// <param name="errorMessage">The error message.</param> /// <param name="propertyName">The property name.</param> public SimpleValidationFailure(ErrorPath errorPath, string errorMessage, string propertyName) : this(errorMessage, propertyName) { this.CustomState = errorPath; }