Ejemplo n.º 1
0
        /// <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.");
            }
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 /// <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));
 }
Ejemplo n.º 4
0
 protected internal override void ValidateMatcher(IAsyncHttpRequestMatcher matcher)
 {
     // Ignore validation.
 }
Ejemplo n.º 5
0
 /// <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));
 }
Ejemplo n.º 6
0
 protected internal override RequestMatching RegisterMatcher(IAsyncHttpRequestMatcher matcher)
 {
     return(_requestMatching.RegisterMatcher(new NotMatcher(matcher)));
 }