mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 23:41:19 +02:00
This commit is contained in:
@@ -23,7 +23,7 @@ namespace WireMock.Validation
|
||||
|
||||
if (!condition(value))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentOutOfRangeException(parameterName);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace WireMock.Validation
|
||||
{
|
||||
if (ReferenceEquals(value, null))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentNullException(parameterName);
|
||||
}
|
||||
@@ -45,15 +45,12 @@ namespace WireMock.Validation
|
||||
}
|
||||
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static T NotNull<T>(
|
||||
[NoEnumeration] T value,
|
||||
[InvokerParameterName] [NotNull] string parameterName,
|
||||
[NotNull] string propertyName)
|
||||
public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName, [NotNull] string propertyName)
|
||||
{
|
||||
if (ReferenceEquals(value, null))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotEmpty(propertyName, nameof(propertyName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(propertyName, nameof(propertyName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
|
||||
}
|
||||
@@ -62,13 +59,13 @@ namespace WireMock.Validation
|
||||
}
|
||||
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static IList<T> NotEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
public static IList<T> NotNullOrEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
{
|
||||
NotNull(value, parameterName);
|
||||
|
||||
if (value.Count == 0)
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
|
||||
}
|
||||
@@ -77,7 +74,7 @@ namespace WireMock.Validation
|
||||
}
|
||||
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
public static string NotNullOrEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
{
|
||||
Exception e = null;
|
||||
if (ReferenceEquals(value, null))
|
||||
@@ -91,7 +88,7 @@ namespace WireMock.Validation
|
||||
|
||||
if (e != null)
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw e;
|
||||
}
|
||||
@@ -104,7 +101,7 @@ namespace WireMock.Validation
|
||||
if (!ReferenceEquals(value, null)
|
||||
&& (value.Length == 0))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
|
||||
}
|
||||
@@ -119,7 +116,7 @@ namespace WireMock.Validation
|
||||
|
||||
if (value.Any(e => e == null))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(parameterName);
|
||||
}
|
||||
@@ -131,7 +128,7 @@ namespace WireMock.Validation
|
||||
{
|
||||
if (!value.GetTypeInfo().IsClass)
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
// copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore/Properties/CoreStrings.resx
|
||||
namespace WireMock.Validation
|
||||
@@ -11,33 +9,33 @@ namespace WireMock.Validation
|
||||
/// <summary>
|
||||
/// The property '{property}' of the argument '{argument}' cannot be null.
|
||||
/// </summary>
|
||||
public static string ArgumentPropertyNull([CanBeNull] string property, [CanBeNull] string argument)
|
||||
public static string ArgumentPropertyNull(string property, string argument)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The property '{property}' of the argument '{argument}' cannot be null.", property, argument);
|
||||
return $"The property '{property}' of the argument '{argument}' cannot be null.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The string argument '{argumentName}' cannot be empty.
|
||||
/// </summary>
|
||||
public static string ArgumentIsEmpty([CanBeNull] string argumentName)
|
||||
public static string ArgumentIsEmpty(string argumentName)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The string argument '{argumentName}' cannot be empty.", argumentName);
|
||||
return $"The string argument '{argumentName}' cannot be empty.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.
|
||||
/// </summary>
|
||||
public static string InvalidEntityType([CanBeNull] Type type, [CanBeNull] string argumentName)
|
||||
public static string InvalidEntityType(Type type, string argumentName)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.", type, argumentName);
|
||||
return $"The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection argument '{argumentName}' must contain at least one element.
|
||||
/// </summary>
|
||||
public static string CollectionArgumentIsEmpty([CanBeNull] string argumentName)
|
||||
public static string CollectionArgumentIsEmpty(string argumentName)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The collection argument '{argumentName}' must contain at least one element.", argumentName);
|
||||
return $"The collection argument '{argumentName}' must contain at least one element.";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user