public void TestForErrorCodeMessages() { foreach (int code in Enum.GetValues(typeof(ErrorCodes))) { var message = ErrorCode.GetErrorCodeString(code); Assert.AreNotEqual( INVALIDMESSAGE, message, $"Code {code} has an undefined or invalid message in GetErrorCodeString"); } Assert.AreEqual(INVALIDMESSAGE, ErrorCode.GetErrorCodeString(-1), "Error Code -1 should be undefined."); }
/// <summary> /// Adds an error code and message to the validation step. /// </summary> /// <param name="IRuleBuilderOptions<TEntity"></param> /// <param name="rule"></param> /// <param name="errorCode">The error code to use for the validation step.</param> /// <param name="propertyName">The property being validated - user friendly name for displaying in error message.</param> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TProperty"></typeparam> /// <returns></returns> public static IRuleBuilderOptions <TEntity, TProperty> AddError <TEntity, TProperty>(this IRuleBuilderOptions <TEntity, TProperty> rule, ErrorCode errorCode, string propertyName = null) => rule .WithErrorCode(errorCode.GetErrorCodeString()) .WithMessage(errorCode.GetErrorMessage(propertyName));