public static IValidateValue <T> NotToBeEqualTo <T>(this IValidateValue <T> param, object other, string reason = null, params object[] reasonArgs) { if (object.Equals(param.Value, other)) { param.HandleValueMismatch($"be equal to '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs); } return(param); }
public static IValidateValue <T> ToBeMoreOrEqualThan <T>(this IValidateValue <T> param, T other, IComparer <T> comparer, string reason = null, params object[] reasonArgs) { if (comparer.Compare(param.Value, other) < 0) { param.HandleValueMismatch($"be more or equal than '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs); } return(param); }
public static IValidateValue <T> NotToBeSameAs <T>(this IValidateValue <T> param, object other, string reason = null, params object[] reasonArgs) where T : class { if (object.ReferenceEquals(param.Value, other)) { param.HandleValueMismatch($"be different than '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs); } return(param); }
public static IValidateValue <T> ToBeLessOrEqualThan <T>(this IValidateValue <T> param, T other, string reason = null, params object[] reasonArgs) where T : IComparable <T> { if (param.Value.CompareTo(other) > 0) { param.HandleValueMismatch($"be less or equal to '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs); } return(param); }
/// <inheritdoc /> public void HandleValueMismatch(string expectedValue, string actualValue, string reason, params object[] reasonArgs) { expectedValue = expectedValue ?? "match"; actualValue = actualValue ?? MessageFormatter.FormatValue(this.Value); var message = MessageFormatter.Format( "The parameter '{0}' value shall {1}{2} but was {3}.", this.Name, expectedValue, MessageFormatter.FormatReason(reason, reasonArgs), actualValue); throw new ArgumentOutOfRangeException(this.Name, this.Value, message); }
/// <inheritdoc /> public void HandleValueMismatch(string expectedValue, string actualValue, string reason, params object[] reasonArgs) { expectedValue = expectedValue ?? "match"; actualValue = actualValue ?? MessageFormatter.FormatValue(this.Value); var message = MessageFormatter.Format( "The return value of method '{0}' shall {1}{2} but was {3}.", this.Name, expectedValue, MessageFormatter.FormatReason(reason, reasonArgs), actualValue); throw new InvalidOperationException(message); }