Ejemplo n.º 1
0
 public static void IsNotDefaultValue <T>(T value, string errorLocation = null, string customMessage = null)
 {
     if (!value.Equals(default(T)))
     {
         return;
     }
     GenericBase <TException> .ThrowException(customMessage ?? $"Did not expect value to be default value ({default(T)}).", errorLocation);
 }
 public static void MaybeThrowException(string message)
 {
     if (message == null)
     {
         return;
     }
     GenericBase <TException> .ThrowException(message);
 }
Ejemplo n.º 3
0
 public static void IsNotNullOrWhiteSpace(string value, string errorLocation = null, string customMessage = null)
 {
     if (!string.IsNullOrWhiteSpace(value))
     {
         return;
     }
     GenericBase <TException> .ThrowException(customMessage ?? $"Did not expect value ({value}) to be null, empty or only contain whitespace.", errorLocation);
 }
Ejemplo n.º 4
0
 public static void IsNotNull(object value, string errorLocation = null, string customMessage = null)
 {
     if (value != null)
     {
         return;
     }
     GenericBase <TException> .ThrowException(customMessage ?? "Did not expect value to be null.", errorLocation);
 }
Ejemplo n.º 5
0
 public static void IsNull(object value, string errorLocation = null, string customMessage = null)
 {
     if (value == null)
     {
         return;
     }
     GenericBase <TException> .ThrowException(customMessage ?? $"Expected value ({value}) to be null.", errorLocation);
 }
Ejemplo n.º 6
0
 public static void IsTrue(bool value, string errorLocation = null, string customMessage = null)
 {
     if (value)
     {
         return;
     }
     GenericBase <TException> .ThrowException(customMessage ?? "Expected value to be true.", errorLocation);
 }
Ejemplo n.º 7
0
 public static void AreNotEqual(object expectedValue, object actualValue, string errorLocation = null, string customMessage = null)
 {
     if (!Equals(expectedValue, actualValue))
     {
         return;
     }
     GenericBase <TException> .ThrowException(customMessage ?? $"Expected ({actualValue}) to not be equal to ({expectedValue}).", errorLocation);
 }
 public static void RequireValidated(object parameterValue, string parameterName, string customMessage = null)
 {
     if (parameterValue == null)
     {
         return;
     }
     if (!(parameterValue is IValidatable validatable))
     {
         return;
     }
     try
     {
         validatable.Validate(null, parameterValue.GetType().Name);
     }
     catch (ValidationException e)
     {
         GenericBase <TException> .ThrowException($"ContractViolation: Validation failed for {parameterName} ({e.Message}).");
     }
 }
Ejemplo n.º 9
0
 public static void IsValidated(object value, string customMessage = null)
 {
     if (value == null)
     {
         return;
     }
     if (!(value is IValidatable validatable))
     {
         return;
     }
     try
     {
         validatable.Validate(null, value.GetType().Name);
     }
     catch (ValidationException e)
     {
         GenericBase <TException> .ThrowException($"Expected validation to pass ({e.Message}).");
     }
 }
 public static void Fail(string message)
 {
     InternalContract.RequireNotNullOrWhiteSpace(message, nameof(message));
     GenericBase <TException> .ThrowException(message);
 }