Esempio n. 1
0
 /// <summary>
 /// Creates a <see cref="RequestMatcher"/> that expect the given request body content.
 /// </summary>
 /// <param name="body">The request body.</param>
 /// <returns>The request matcher.</returns>
 public static RequestMatcher MatchBody(string body)
 {
     return(delegate(IClientHttpRequest request)
     {
         MockClientHttpRequest mockRequest = request as MockClientHttpRequest;
         AssertionUtils.AreEqual(body, mockRequest.GetBodyAsString(), "Unexpected body content");
     });
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a <see cref="RequestMatcher"/> that expect to contain the given request body content.
 /// </summary>
 /// <param name="body">The substring that must appear in the body content.</param>
 /// <returns>The request matcher.</returns>
 public static RequestMatcher MatchBodyContains(string body)
 {
     return(delegate(IClientHttpRequest request)
     {
         MockClientHttpRequest mockRequest = request as MockClientHttpRequest;
         string actualBody = mockRequest.GetBodyAsString();
         AssertionUtils.IsTrue(actualBody.Contains(body), String.Format("Body didn't contain expected content [expected:<{0}> in:<{1}>]", body, actualBody));
     });
 }
        internal MockClientHttpRequest ExpectNewRequest()
        {
            if (this.requestEnumerator != null)
            {
                throw new InvalidCastException("Can not expect another request, the test is already underway");
            }

            MockClientHttpRequest request = new MockClientHttpRequest();
            this.expectedRequests.Add(request);
            return request;
        }
Esempio n. 4
0
        internal MockClientHttpRequest ExpectNewRequest()
        {
            if (this.requestEnumerator != null)
            {
                throw new InvalidCastException("Can not expect another request, the test is already underway");
            }

            MockClientHttpRequest request = new MockClientHttpRequest();

            this.expectedRequests.Add(request);
            return(request);
        }
Esempio n. 5
0
        /// <summary>
        /// Create a new <see cref="IClientHttpRequest"/> for the specified URI and HTTP method.
        /// </summary>
        /// <param name="uri">The URI to create a request for.</param>
        /// <param name="method">The HTTP method to execute.</param>
        /// <returns>The created request.</returns>
        public IClientHttpRequest CreateRequest(Uri uri, HttpMethod method)
        {
            ArgumentUtils.AssertNotNull(uri, "uri");
            ArgumentUtils.AssertNotNull(method, "method");

            if (this.requestEnumerator == null)
            {
                requestEnumerator = expectedRequests.GetEnumerator();
            }
            if (!this.requestEnumerator.MoveNext())
            {
                throw new AssertionException("No further requests expected");
            }

            MockClientHttpRequest currentRequest = this.requestEnumerator.Current;

            currentRequest.Uri    = uri;
            currentRequest.Method = method;
            return(currentRequest);
        }
        /// <summary>
        /// Returns a <see cref="IRequestActions"/> object that allows for creating the response, or to set up request expectations.
        /// </summary>
        /// <returns>The response actions.</returns>
        public IRequestActions ExpectNewRequest()
        {
            MockClientHttpRequest request = this.mockRequestFactory.ExpectNewRequest();

            return(request);
        }