Skip to content

Commit

Permalink
#86
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Feb 4, 2018
1 parent b248c8c commit 95a2015
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/WireMock.Net/Matchers/SimMetricsMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType =
/// <param name="simMetricType">The SimMetric Type</param>
public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
{
Check.NotEmpty(patterns, nameof(patterns));
Check.NotNullOrEmpty(patterns, nameof(patterns));

_patterns = patterns;
_simMetricType = simMetricType;
Expand Down
5 changes: 4 additions & 1 deletion src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class AspNetCoreSelfHost : IOwinSelfHost
public AspNetCoreSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
{
Check.NotNull(options, nameof(options));
Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
Check.NotNullOrEmpty(uriPrefixes, nameof(uriPrefixes));

foreach (string uriPrefix in uriPrefixes)
{
Expand All @@ -51,8 +51,11 @@ public Task StartAsync()
.Configure(appBuilder =>
{
appBuilder.UseMiddleware<GlobalExceptionMiddleware>();
_options.PreWireMockMiddlewareInit?.Invoke(appBuilder);
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
_options.PostWireMockMiddlewareInit?.Invoke(appBuilder);
})
.UseKestrel(options =>
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Owin/OwinSelfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class OwinSelfHost : IOwinSelfHost
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
{
Check.NotNull(options, nameof(options));
Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
Check.NotNullOrEmpty(uriPrefixes, nameof(uriPrefixes));

foreach (string uriPrefix in uriPrefixes)
{
Expand Down
30 changes: 15 additions & 15 deletions src/WireMock.Net/RequestBuilders/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public T GetRequestMessageMatcher<T>() where T : IRequestMatcher
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithClientIP(params IMatcher[] matchers)
{
Check.NotEmpty(matchers, nameof(matchers));
Check.NotNullOrEmpty(matchers, nameof(matchers));

_requestMatchers.Add(new RequestMessageClientIPMatcher(matchers));
return this;
Expand All @@ -74,7 +74,7 @@ public IRequestBuilder WithClientIP(params IMatcher[] matchers)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithClientIP(params string[] clientIPs)
{
Check.NotEmpty(clientIPs, nameof(clientIPs));
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));

_requestMatchers.Add(new RequestMessageClientIPMatcher(clientIPs));
return this;
Expand All @@ -87,7 +87,7 @@ public IRequestBuilder WithClientIP(params string[] clientIPs)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
{
Check.NotEmpty(funcs, nameof(funcs));
Check.NotNullOrEmpty(funcs, nameof(funcs));

_requestMatchers.Add(new RequestMessageClientIPMatcher(funcs));
return this;
Expand All @@ -100,7 +100,7 @@ public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithPath(params IMatcher[] matchers)
{
Check.NotEmpty(matchers, nameof(matchers));
Check.NotNullOrEmpty(matchers, nameof(matchers));

_requestMatchers.Add(new RequestMessagePathMatcher(matchers));
return this;
Expand All @@ -113,7 +113,7 @@ public IRequestBuilder WithPath(params IMatcher[] matchers)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithPath(params string[] paths)
{
Check.NotEmpty(paths, nameof(paths));
Check.NotNullOrEmpty(paths, nameof(paths));

_requestMatchers.Add(new RequestMessagePathMatcher(paths));
return this;
Expand All @@ -126,7 +126,7 @@ public IRequestBuilder WithPath(params string[] paths)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
{
Check.NotEmpty(funcs, nameof(funcs));
Check.NotNullOrEmpty(funcs, nameof(funcs));

_requestMatchers.Add(new RequestMessagePathMatcher(funcs));
return this;
Expand All @@ -139,7 +139,7 @@ public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithUrl(params IMatcher[] matchers)
{
Check.NotEmpty(matchers, nameof(matchers));
Check.NotNullOrEmpty(matchers, nameof(matchers));

_requestMatchers.Add(new RequestMessageUrlMatcher(matchers));
return this;
Expand All @@ -152,7 +152,7 @@ public IRequestBuilder WithUrl(params IMatcher[] matchers)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithUrl(params string[] urls)
{
Check.NotEmpty(urls, nameof(urls));
Check.NotNullOrEmpty(urls, nameof(urls));

_requestMatchers.Add(new RequestMessageUrlMatcher(urls));
return this;
Expand All @@ -165,7 +165,7 @@ public IRequestBuilder WithUrl(params string[] urls)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithUrl(params Func<string, bool>[] funcs)
{
Check.NotEmpty(funcs, nameof(funcs));
Check.NotNullOrEmpty(funcs, nameof(funcs));

_requestMatchers.Add(new RequestMessageUrlMatcher(funcs));
return this;
Expand Down Expand Up @@ -228,7 +228,7 @@ public IRequestBuilder UsingAnyVerb()
/// <inheritdoc cref="IMethodRequestBuilder.UsingVerb"/>
public IRequestBuilder UsingVerb(params string[] verbs)
{
Check.NotEmpty(verbs, nameof(verbs));
Check.NotNullOrEmpty(verbs, nameof(verbs));

_requestMatchers.Add(new RequestMessageMethodMatcher(verbs));
return this;
Expand Down Expand Up @@ -328,7 +328,7 @@ public IRequestBuilder WithParam(string key, params string[] values)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithParam(params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
{
Check.NotEmpty(funcs, nameof(funcs));
Check.NotNullOrEmpty(funcs, nameof(funcs));

_requestMatchers.Add(new RequestMessageParamMatcher(funcs));
return this;
Expand Down Expand Up @@ -363,7 +363,7 @@ public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCas
public IRequestBuilder WithHeader(string name, params IMatcher[] matchers)
{
Check.NotNull(name, nameof(name));
Check.NotEmpty(matchers, nameof(matchers));
Check.NotNullOrEmpty(matchers, nameof(matchers));

_requestMatchers.Add(new RequestMessageHeaderMatcher(name, matchers));
return this;
Expand All @@ -376,7 +376,7 @@ public IRequestBuilder WithHeader(string name, params IMatcher[] matchers)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithHeader(params Func<IDictionary<string, string[]>, bool>[] funcs)
{
Check.NotEmpty(funcs, nameof(funcs));
Check.NotNullOrEmpty(funcs, nameof(funcs));

_requestMatchers.Add(new RequestMessageHeaderMatcher(funcs));
return this;
Expand All @@ -403,7 +403,7 @@ public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase =
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithCookie(string name, params IMatcher[] matchers)
{
Check.NotEmpty(matchers, nameof(matchers));
Check.NotNullOrEmpty(matchers, nameof(matchers));

_requestMatchers.Add(new RequestMessageCookieMatcher(name, matchers));
return this;
Expand All @@ -416,7 +416,7 @@ public IRequestBuilder WithCookie(string name, params IMatcher[] matchers)
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
public IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs)
{
Check.NotEmpty(funcs, nameof(funcs));
Check.NotNullOrEmpty(funcs, nameof(funcs));

_requestMatchers.Add(new RequestMessageCookieMatcher(funcs));
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/ResponseBuilders/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public IResponseBuilder WithDelay(int milliseconds)
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(string, string)"/>
public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null)
{
Check.NotEmpty(proxyUrl, nameof(proxyUrl));
Check.NotNullOrEmpty(proxyUrl, nameof(proxyUrl));

ProxyUrl = proxyUrl;
ClientX509Certificate2ThumbprintOrSubjectName = clientX509Certificate2ThumbprintOrSubjectName;
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void AddHeader(string name, string value)
/// <param name="values">The values.</param>
public void AddHeader(string name, params string[] values)
{
Check.NotEmpty(values, nameof(values));
Check.NotNullOrEmpty(values, nameof(values));

var newHeaderValues = Headers.TryGetValue(name, out WireMockList<string> existingValues)
? values.Union(existingValues).ToArray()
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Server/FluentMockServer.Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void WatchStaticMappings([CanBeNull] string folder = null)
{
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(args.FullPath);
if (Guid.TryParse(filenameWithoutExtension, out var guidFromFilename))
if (Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
{
DeleteMapping(guidFromFilename);
}
Expand Down
6 changes: 3 additions & 3 deletions src/WireMock.Net/Server/FluentMockServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static FluentMockServer Start([CanBeNull] int? port = 0, bool ssl = false
[PublicAPI]
public static FluentMockServer Start(params string[] urls)
{
Check.NotEmpty(urls, nameof(urls));
Check.NotNullOrEmpty(urls, nameof(urls));

return new FluentMockServer(new FluentMockServerSettings
{
Expand Down Expand Up @@ -127,7 +127,7 @@ public static FluentMockServer StartWithAdminInterface(int? port = 0, bool ssl =
[PublicAPI]
public static FluentMockServer StartWithAdminInterface(params string[] urls)
{
Check.NotEmpty(urls, nameof(urls));
Check.NotNullOrEmpty(urls, nameof(urls));

return new FluentMockServer(new FluentMockServerSettings
{
Expand All @@ -144,7 +144,7 @@ public static FluentMockServer StartWithAdminInterface(params string[] urls)
[PublicAPI]
public static FluentMockServer StartWithAdminInterfaceAndReadStaticMappings(params string[] urls)
{
Check.NotEmpty(urls, nameof(urls));
Check.NotNullOrEmpty(urls, nameof(urls));

return new FluentMockServer(new FluentMockServerSettings
{
Expand Down
27 changes: 12 additions & 15 deletions src/WireMock.Net/Validation/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static T Condition<T>([NoEnumeration] T value, [NotNull] Predicate<T> con

if (!condition(value))
{
NotEmpty(parameterName, nameof(parameterName));
NotNullOrEmpty(parameterName, nameof(parameterName));

throw new ArgumentOutOfRangeException(parameterName);
}
Expand All @@ -36,7 +36,7 @@ public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotN
{
if (ReferenceEquals(value, null))
{
NotEmpty(parameterName, nameof(parameterName));
NotNullOrEmpty(parameterName, nameof(parameterName));

throw new ArgumentNullException(parameterName);
}
Expand All @@ -45,15 +45,12 @@ public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotN
}

[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));
}
Expand All @@ -62,13 +59,13 @@ public static T NotNull<T>(
}

[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));
}
Expand All @@ -77,7 +74,7 @@ public static IList<T> NotEmpty<T>(IList<T> value, [InvokerParameterName] [NotNu
}

[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))
Expand All @@ -91,7 +88,7 @@ public static string NotEmpty(string value, [InvokerParameterName] [NotNull] str

if (e != null)
{
NotEmpty(parameterName, nameof(parameterName));
NotNullOrEmpty(parameterName, nameof(parameterName));

throw e;
}
Expand All @@ -104,7 +101,7 @@ public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNu
if (!ReferenceEquals(value, null)
&& (value.Length == 0))
{
NotEmpty(parameterName, nameof(parameterName));
NotNullOrEmpty(parameterName, nameof(parameterName));

throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
}
Expand All @@ -119,7 +116,7 @@ public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName] [Not

if (value.Any(e => e == null))
{
NotEmpty(parameterName, nameof(parameterName));
NotNullOrEmpty(parameterName, nameof(parameterName));

throw new ArgumentException(parameterName);
}
Expand All @@ -131,7 +128,7 @@ public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull]
{
if (!value.GetTypeInfo().IsClass)
{
NotEmpty(parameterName, nameof(parameterName));
NotNullOrEmpty(parameterName, nameof(parameterName));

throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
}
Expand Down
18 changes: 8 additions & 10 deletions src/WireMock.Net/Validation/CoreStrings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Globalization;
using JetBrains.Annotations;

// copied from https:/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore/Properties/CoreStrings.resx
namespace WireMock.Validation
Expand All @@ -11,33 +9,33 @@ internal static class CoreStrings
/// <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.";
}
}
}

0 comments on commit 95a2015

Please sign in to comment.