mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-24 01:51:02 +01:00
71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using AnyOfTypes;
|
|
using WireMock.Models;
|
|
|
|
namespace WireMock.Matchers;
|
|
|
|
/// <summary>
|
|
/// NotNullOrEmptyMatcher
|
|
/// </summary>
|
|
/// <seealso cref="IObjectMatcher" />
|
|
public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher
|
|
{
|
|
/// <inheritdoc cref="IMatcher.Name"/>
|
|
public string Name => "NotNullOrEmptyMatcher";
|
|
|
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
|
public MatchBehaviour MatchBehaviour { get; }
|
|
|
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
|
public bool ThrowException { get; }
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="NotNullOrEmptyMatcher"/> class.
|
|
/// </summary>
|
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
public NotNullOrEmptyMatcher(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
{
|
|
MatchBehaviour = matchBehaviour;
|
|
}
|
|
|
|
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
|
public double IsMatch(object? input)
|
|
{
|
|
bool match;
|
|
|
|
switch (input)
|
|
{
|
|
case string @string:
|
|
match = !string.IsNullOrEmpty(@string);
|
|
break;
|
|
|
|
case byte[] bytes:
|
|
match = bytes.Any();
|
|
break;
|
|
|
|
default:
|
|
match = input != null;
|
|
break;
|
|
}
|
|
|
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
|
|
}
|
|
|
|
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
|
public double IsMatch(string? input)
|
|
{
|
|
var match = !string.IsNullOrEmpty(input);
|
|
|
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
|
|
}
|
|
|
|
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
|
public AnyOf<string, StringPattern>[] GetPatterns()
|
|
{
|
|
return EmptyArray<AnyOf<string, StringPattern>>.Value;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public MatchOperator MatchOperator { get; } = MatchOperator.Or;
|
|
} |