Пример #1
0
        public override void Setup(MockHttpMessageHandler handler)
        {
            var response = new SequenceResponseManager(Responses);

            MockedRequest mocked;

            if (!Method.HasValue)
            {
                mocked = handler.When(Url);
            }
            else
            {
                mocked = handler.When(new HttpMethod(Method.Value.ToString()), Url);
            }

            mocked.Respond(re => response.GetContent());
        }
        /// <summary>
        /// Configures the initial conditions.
        /// </summary>
        /// <param name="handler">The HttpMessageHandler.</param>
        public override void Setup(MockHttpMessageHandler handler)
        {
            var response = new SequenceResponseManager(Responses);

            MockedRequest mocked;

            if (!Method.HasValue)
            {
                mocked = handler.When(Url);
            }
            else
            {
                mocked = handler.When(new HttpMethod(Method.Value.ToString()), Url);
            }

            if (!string.IsNullOrEmpty(Body))
            {
                if (Method == HttpRequest.HttpMethod.DELETE || Method == HttpRequest.HttpMethod.GET)
                {
                    throw new ArgumentException("GET and DELETE don't support matching body!");
                }

                if (MatchType == BodyMatchType.Exact)
                {
                    mocked = mocked.WithContent(Body);
                }
                else if (MatchType == BodyMatchType.Partial)
                {
                    mocked = mocked.WithPartialContent(Body);
                }
                else
                {
                    throw new InvalidEnumArgumentException($"{nameof(MatchType)} does not support {MatchType} yet!");
                }
            }

            mocked.Respond(re => response.GetMessage());
        }