コード例 #1
0
        /// <summary>
        /// Performs HTTP Put method (async)
        /// </summary>
        /// <param name="action">URL action value. It will be concatenated with base URL to create request URL.</param>
        /// <param name="content">Content object to be serialized as request body.</param>
        /// <param name="headers">HTTP headers to be included in the request.</param>
        /// <param name="contentType">Content type of the payload.</param>
        /// <typeparam name="T">The type to use when deserializing the response. Use type <see cref="Empty" /> if the response is not expected to have a body.</typeparam>
        /// <returns>Deserialized to type T object from response body.</returns>
        public async Task <T> PutAsync <T>(string action, object content, Dictionary <string, string> headers = null, ContentType contentType = ContentType.JSON)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Put, BuildUri(action))
            {
                Content = RestfulContent.GetHttpContent(content, contentType)
            };

            return(await PerformRequestAsync <T>(httpRequest, headers));
        }
コード例 #2
0
        /// <summary>
        /// Creates a fake response handler
        /// </summary>
        /// <param name="code">Status code of the mocked response.</param>
        /// <param name="endpoint">Request endpoint.</param>
        /// <param name="content">Request content.</param>
        /// <param name="contentType">Request content type.</param>
        /// <returns>Mocked response handler.</returns>
        public static FakeResponseHandler Create(HttpStatusCode code, string endpoint, object content = null, ContentType contentType = ContentType.JSON)
        {
            var fakeResponseMessage = new HttpResponseMessage(code);

            if (content != null)
            {
                fakeResponseMessage.Content = RestfulContent.GetHttpContent(content, contentType);
            }

            var fakeResponseHandler = new FakeResponseHandler();

            fakeResponseHandler.AddFakeResponse(new Uri(endpoint), fakeResponseMessage);

            return(fakeResponseHandler);
        }