/// <summary> /// </summary> // ReSharper disable once MemberCanBeProtected.Global protected internal virtual void ValidateMatcher(IAsyncHttpRequestMatcher matcher) { if (matcher is null) { throw new ArgumentNullException(nameof(matcher)); } var sameTypeMatchers = _matchers .Where(m => m.GetType() == matcher.GetType()) .ToList(); if (matcher.IsExclusive && sameTypeMatchers.Any() || !matcher.IsExclusive && sameTypeMatchers.Any(m => m.IsExclusive)) { throw new InvalidOperationException($"Cannot add matcher, another matcher of type '{matcher.GetType().FullName}' already is configured."); } }
/// <summary> /// Adds a matcher. /// </summary> /// <param name="matcher">The matcher instance.</param> /// <returns>The request matching builder.</returns> // ReSharper disable once MemberCanBeProtected.Global protected internal virtual RequestMatching RegisterMatcher(IAsyncHttpRequestMatcher matcher) { if (matcher is null) { throw new ArgumentNullException(nameof(matcher)); } if (_matchers.Contains(matcher)) { return(this); } ValidateMatcher(matcher); _matchers.Add(matcher); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="NotMatcher"/> class using specified <paramref name="matcher"/>. /// </summary> /// <param name="matcher">A matcher for which the result is inverted.</param> public NotMatcher(IAsyncHttpRequestMatcher matcher) { _matcher = matcher ?? throw new ArgumentNullException(nameof(matcher)); }
protected internal override void ValidateMatcher(IAsyncHttpRequestMatcher matcher) { // Ignore validation. }
/// <summary> /// Adds a matcher. /// </summary> /// <param name="matcher">The matcher instance.</param> /// <returns>The request matching builder.</returns> public RequestMatching With(IAsyncHttpRequestMatcher matcher) { return(RegisterMatcher(matcher)); }
protected internal override RequestMatching RegisterMatcher(IAsyncHttpRequestMatcher matcher) { return(_requestMatching.RegisterMatcher(new NotMatcher(matcher))); }