/// <summary> /// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="value">The value.</param> public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value) { Check.NotNull(value, nameof(value)); ValueAsBytes = value; MatchBehaviour = matchBehaviour; }
/// <summary> /// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="value">The value.</param> public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] object value) { Check.NotNull(value, nameof(value)); ValueAsObject = value; MatchBehaviour = matchBehaviour; }
/// <summary> /// Initializes a new instance of the <see cref="JmesPathMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="patterns">The patterns.</param> public JmesPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns) { Check.NotNull(patterns, nameof(patterns)); MatchBehaviour = matchBehaviour; _patterns = patterns; }
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, bool, string[])"/> public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, bool ignoreCase = false, params string[] values) { Check.NotNull(key, nameof(key)); _requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, ignoreCase, values)); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="methods">The methods.</param> public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods) { Check.NotNull(methods, nameof(methods)); _matchBehaviour = matchBehaviour; Methods = methods; }
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(MatchBehaviour, string[])"/> public IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, params string[] methods) { Check.NotNullOrEmpty(methods, nameof(methods)); _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, methods)); return(this); }
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, bool, MatchBehaviour)"/> public IRequestBuilder WithParam(string key, bool ignoreCase, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) { Check.NotNull(key, nameof(key)); _requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, ignoreCase)); return(this); }
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(string[])"/> public IRequestBuilder WithClientIP(MatchBehaviour matchBehaviour, params string[] clientIPs) { Check.NotNullOrEmpty(clientIPs, nameof(clientIPs)); _requestMatchers.Add(new RequestMessageClientIPMatcher(matchBehaviour, clientIPs)); return(this); }
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(MatchBehaviour, string[])"/> public IRequestBuilder WithPath(MatchBehaviour matchBehaviour, params string[] paths) { Check.NotNullOrEmpty(paths, nameof(paths)); _requestMatchers.Add(new RequestMessagePathMatcher(matchBehaviour, paths)); return(this); }
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(MatchBehaviour, string[])"/> public IRequestBuilder WithUrl(MatchBehaviour matchBehaviour, params string[] urls) { Check.NotNullOrEmpty(urls, nameof(urls)); _requestMatchers.Add(new RequestMessageUrlMatcher(matchBehaviour, urls)); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="JsonMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="value">The value to check for equality.</param> public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] string value) { Check.NotNull(value, nameof(value)); MatchBehaviour = matchBehaviour; _value = value; }
/// <summary> /// Initializes a new instance of the <see cref="JsonMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="value">The object value to check for equality.</param> public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] object value) { Check.NotNull(value, nameof(value)); MatchBehaviour = matchBehaviour; Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="methods">The methods.</param> public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods) { Check.NotNull(methods, nameof(methods)); _matchBehaviour = matchBehaviour; Methods = methods.Select(v => v.ToLower()).ToArray(); }
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, IStringMatcher[])"/> public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, params IStringMatcher[] matchers) { Check.NotNull(key, nameof(key)); _requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, matchers)); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param> /// <param name="value">The value.</param> public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value, bool throwException = false) { Check.NotNull(value, nameof(value)); MatchBehaviour = matchBehaviour; ThrowException = throwException; ValueAsBytes = value; }
/// <summary> /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="patterns">The patterns.</param> /// <param name="simMetricType">The SimMetric Type</param> public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein) { Check.NotNullOrEmpty(patterns, nameof(patterns)); MatchBehaviour = matchBehaviour; _patterns = patterns; _simMetricType = simMetricType; }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="key">The key.</param> /// <param name="matchers">The matchers.</param> public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] IStringMatcher[] matchers) { Check.NotNull(key, nameof(key)); _matchBehaviour = matchBehaviour; Key = key; Matchers = matchers; }
/// <summary> /// Initializes a new instance of the <see cref="ExactMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param> /// <param name="values">The values.</param> public ExactMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params string[] values) { Check.HasNoNulls(values, nameof(values)); MatchBehaviour = matchBehaviour; ThrowException = throwException; _values = values; }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="key">The key.</param> /// <param name="values">The values.</param> public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] IEnumerable <string> values) { Check.NotNull(key, nameof(key)); _matchBehaviour = matchBehaviour; Key = key; Values = values; }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCodeMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="patterns">The patterns.</param> public CSharpCodeMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns) { Check.NotNull(patterns, nameof(patterns)); MatchBehaviour = matchBehaviour; ThrowException = false; _patterns = patterns; }
/// <summary> /// Initializes a new instance of the <see cref="ExactMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param> /// <param name="values">The values.</param> public ExactMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf <string, StringPattern>[] values) { Check.NotNull(values, nameof(values)); MatchBehaviour = matchBehaviour; ThrowException = throwException; _values = values; }
/// <summary> /// Initializes a new instance of the <see cref="JsonPathMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param> /// <param name="patterns">The patterns.</param> public JsonPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf <string, StringPattern>[] patterns) { Check.NotNull(patterns, nameof(patterns)); MatchBehaviour = matchBehaviour; ThrowException = throwException; _patterns = patterns; }
/// <summary> /// Initializes a new instance of the <see cref="JsonMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="value">The object value to check for equality.</param> /// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param> public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false) { Check.NotNull(value, nameof(value)); MatchBehaviour = matchBehaviour; Value = value; IgnoreCase = ignoreCase; }
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(string, IStringMatcher[])"/> public IRequestBuilder WithHeader(string name, bool ignoreCase, MatchBehaviour matchBehaviour, params IStringMatcher[] matchers) { Check.NotNull(name, nameof(name)); Check.NotNullOrEmpty(matchers, nameof(matchers)); _requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, ignoreCase, matchers)); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="name">The name.</param> /// <param name="pattern">The pattern.</param> /// <param name="ignoreCase">The ignoreCase.</param> public RequestMessageCookieMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase = true) { Check.NotNull(name, nameof(name)); Check.NotNull(pattern, nameof(pattern)); _matchBehaviour = matchBehaviour; Name = name; Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) }; }
/// <summary> /// Converts the specified match behaviour and match value to a new match value. /// /// if AcceptOnMatch --> return match (default) /// if RejectOnMatch and match = 0.0 --> return 1.0 /// if RejectOnMatch and match = 0.? --> return 0.0 /// if RejectOnMatch and match = 1.0 --> return 0.0 /// </summary> /// /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="match">The match.</param> /// <returns>match value</returns> internal static double Convert(MatchBehaviour matchBehaviour, double match) { if (matchBehaviour == MatchBehaviour.AcceptOnMatch) { return(match); } return(match <= MatchScores.Tolerance ? MatchScores.Perfect : MatchScores.Mismatch); }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="patterns">The patterns.</param> /// <param name="ignoreCase">Ignore the case from the pattern.</param> /// <param name="matchBehaviour">The match behaviour.</param> public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string[] patterns, bool ignoreCase) { Check.NotNull(name, nameof(name)); Check.NotNull(patterns, nameof(patterns)); _matchBehaviour = matchBehaviour; Name = name; Matchers = patterns.Select(pattern => new WildcardMatcher(matchBehaviour, pattern, ignoreCase)).Cast <IStringMatcher>().ToArray(); }
public static IMatcher Map([CanBeNull] MatcherModel matcher) { if (matcher == null) { return(null); } string[] parts = matcher.Name.Split('.'); string matcherName = parts[0]; string matcherType = parts.Length > 1 ? parts[1] : null; string[] stringPatterns = matcher.Patterns != null?matcher.Patterns.Cast <string>().ToArray() : new[] { matcher.Pattern as string }; MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch; switch (matcherName) { case "LinqMatcher": return(new LinqMatcher(matchBehaviour, stringPatterns)); case "ExactMatcher": return(new ExactMatcher(matchBehaviour, stringPatterns)); case "ExactObjectMatcher": var bytePattern = Convert.FromBase64String(stringPatterns[0]); return(new ExactObjectMatcher(matchBehaviour, bytePattern)); case "RegexMatcher": return(new RegexMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true)); case "JsonMatcher": return(new JsonMatcher(matchBehaviour, matcher.Pattern)); case "JsonPathMatcher": return(new JsonPathMatcher(matchBehaviour, stringPatterns)); case "JmesPathMatcher": return(new JmesPathMatcher(matchBehaviour, stringPatterns)); case "XPathMatcher": return(new XPathMatcher(matchBehaviour, (string)matcher.Pattern)); case "WildcardMatcher": return(new WildcardMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true)); case "SimMetricsMatcher": SimMetricType type = SimMetricType.Levenstein; if (!string.IsNullOrEmpty(matcherType) && !Enum.TryParse(matcherType, out type)) { throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported."); } return(new SimMetricsMatcher(matchBehaviour, (string)matcher.Pattern, type)); default: throw new NotSupportedException($"Matcher '{matcherName}' is not supported."); } }
/// <summary> /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="patterns">The patterns.</param> /// <param name="simMetricType">The SimMetric Type</param> /// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param> public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein, bool throwException = false) { Check.NotNullOrEmpty(patterns, nameof(patterns)); MatchBehaviour = matchBehaviour; ThrowException = throwException; _patterns = patterns; _simMetricType = simMetricType; }
/// <summary> /// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class. /// </summary> /// <param name="matchBehaviour">The match behaviour.</param> /// <param name="name">The name.</param> /// <param name="matchers">The matchers.</param> /// <param name="ignoreCase">Ignore the case from the pattern.</param> public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, bool ignoreCase, [NotNull] params IStringMatcher[] matchers) { Check.NotNull(name, nameof(name)); Check.NotNull(matchers, nameof(matchers)); _matchBehaviour = matchBehaviour; Name = name; Matchers = matchers; _ignoreCase = ignoreCase; }