Esempio n. 1
0
        public async Task request_is_returned()
        {
            using (var server = new InMemoryHost(() =>
            {
                ResourceSpace.Has.ResourcesNamed("resource")
                .AtUri("/{id}").HandledBy <Handler>();
                ResourceSpace.Uses.Diagnostics(new DiagnosticsOptions {
                    TraceMethod = true
                });
            }))
            {
                var response = await server.ProcessRequestAsync(new InMemoryRequest()
                {
                    HttpMethod = "TRACE",
                    Uri        = new Uri("http://localhost/1"),
                    Headers    =
                    {
                        { "Accept",     "*/*"   },
                        { "User-Agent", "stuff" }
                    }
                });

                response.StatusCode.ShouldBe(200);
                response.Entity.ContentType?.MediaType.ShouldBe("message/http");
                using (var reader = new StreamReader(response.Entity.Stream, Encoding.UTF8))
                    reader.ReadToEnd().ShouldBe(
                        "TRACE /1 HTTP/1.1\r\n" +
                        "Host: http://localhost/\r\n" +
                        "Accept: */*\r\n" +
                        "User-Agent: stuff\r\n\r\n");
            }
        }
Esempio n. 2
0
 public static Task <IResponse> Get(this InMemoryHost host, string uri)
 {
     return(host.ProcessRequestAsync(new InMemoryRequest
     {
         HttpMethod = "GET",
         Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute)
     }));
 }
Esempio n. 3
0
 static Task <IResponse> ExecuteMethod(InMemoryHost host, string method, string uri, string content, string contentType)
 {
     return(host.ProcessRequestAsync(new InMemoryRequest
     {
         HttpMethod = method,
         Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute)
     }.WriteString(content, contentType)));
 }
Esempio n. 4
0
        async Task <IResponse> Get(Func <OperationResult> getter)
        {
            var server = new InMemoryHost(new ErrorApi(getter));

            return(await server.ProcessRequestAsync(new InMemoryRequest()
            {
                HttpMethod = "GET"
            }));
        }
Esempio n. 5
0
        public async Task negotiated_type_is_specific_mt()
        {
            var response = await server.ProcessRequestAsync(new InMemoryRequest
            {
                HttpMethod = "GET",
                Headers    = { { "Accept", "application/json" } },
                Uri        = new Uri("http://localhost/1")
            });

            response.Headers.ContentType.ShouldBe(MediaType.Json);
        }
        public async Task <byte[]> GetAllEventsMemory()
        {
            var response = await _memServerNoTrace.ProcessRequestAsync(new InMemoryRequest()
            {
                HttpMethod = "GET",
                Uri        = new Uri("http://localhost/events/")
            });

            var body = await response.Entity.Stream.ReadToEndAsync();

            VerifyResult(response.StatusCode, body);
            return(body);
        }
        public async Task <byte[]> MemoryHostNoTrace()
        {
            var response = await _memServerNoTrace.ProcessRequestAsync(new InMemoryRequest()
            {
                HttpMethod = "GET",
                Uri        = new Uri("http://localhost/.well-known/health")
            });

            var body = await response.Entity.Stream.ReadToEndAsync();

            VerifyResult(body);
            return(body);
        }
Esempio n. 8
0
        public async Task TestDeepHealthCheckQueryParam(string querystring, bool deepHealthChecksAttempted)
        {
            using (var host = new InMemoryHost(new TestConfig(), startup: new StartupProperties {
                OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } }
            }))
            {
                var request =
                    new InMemoryRequest
                {
                    HttpMethod = "GET",
                    Uri        = new Uri($"http://localhost/healthcheck/{querystring}")
                };
                var response = await host.ProcessRequestAsync(request);

                // response.Should().NotBeNull("whether deep checks are done or not the controller should respond");
                response.StatusCode.ShouldBe(200, "both deep and shallow checks return success");
                // DeepHealthChecks(deepHealthChecksAttempted);
            }
        }
Esempio n. 9
0
        static Task <IResponse> ExecuteMethod(InMemoryHost host, string uri, string method, string content = null,
                                              string contentType = null, Action <HttpHeaderDictionary> headers = null)
        {
            if (uri.StartsWith('/') == false)
            {
                uri = "/" + uri;
            }

            var request = new InMemoryRequest
            {
                HttpMethod = method,
                Uri        = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute)
            };

            headers?.Invoke(request.Headers);
            if (content != null)
            {
                request = request.WriteString(content, contentType);
            }
            return(host.ProcessRequestAsync(request));
        }
Esempio n. 10
0
        public async void contains_date_header()
        {
            _response = await _host.ProcessRequestAsync(new InMemoryRequest());

            _response.Headers.ContainsKey("Date").ShouldBeTrue();
        }