Пример #1
0
        private static HttpTextResponse DoRequest(HttpMethod method, string url, Action <HttpRequest> configurer = null, Func <IJsonSerializer, string> contentFn = null)
        {
            Ensure.That(url, "url").IsNotNullOrWhiteSpace();

            var request = new HttpRequest(method);

            using (var requester = new HttpRequester(url, MessageHandlerFn?.Invoke()))
            {
                var content = contentFn?.Invoke(requester.JsonSerializer);
                if (!string.IsNullOrWhiteSpace(content))
                {
                    request.WithJsonContent(content);
                }

                configurer?.Invoke(request);

                return(requester.SendAsync(request).Result);
            }
        }
Пример #2
0
        public async void Can_PUT_form_url_encoded_content()
        {
            using (var requester = new HttpRequester($"{_server.BaseAddress}/api/relay/", _server.Handler))
            {
                var request = new HttpRequest(HttpMethod.Put);
                request.WithContent(new FormUrlEncodedContent(new Dictionary <string, string>
                {
                    { "key", "test" },
                    { "value", "42" }
                }));

                var response = await requester.SendAsync(request);

                response.TheResponse(should => should
                                     .BeSuccessful()
                                     .BeJsonResponse()
                                     .HaveSpecificValueFor("key", "test")
                                     .HaveSpecificValueFor("value", "42"));
            }
        }