protected location_header(string appPath = null) { var server = new InMemoryHost(() => ResourceSpace.Has.ResourcesNamed("root") .AtUri("/resource/") .And.AtUri("/resource/async/").Named("async") .HandledBy <T>()) { ApplicationVirtualPath = appPath ?? "/" }; Response = server.Get($"{server.ApplicationVirtualPath}resource/"); ResponseAsync = server.Get($"{server.ApplicationVirtualPath}resource/async/"); server.Close(); }
protected location_header(string appPath = null) { _server = new InMemoryHost( () => ResourceSpace.Has.ResourcesNamed("root") .AtUri("/resource/") .And.AtUri("/resource/async/").Named("async") .HandledBy <T>(), startup: new StartupProperties { OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } } }) { ApplicationVirtualPath = appPath ?? "/" }; Response = _server.Get($"{_server.ApplicationVirtualPath}resource/"); ResponseAsync = _server.Get($"{_server.ApplicationVirtualPath}resource/async/"); }
public async Task location_header_is_relative_uri_rel_path() { var server = new InMemoryHost(() => ResourceSpace.Has.ResourcesNamed("root") .AtUri("/resource/") .HandledBy <RelUriRelPath>()); (await server.Get("/resource/")).Headers["Location"].ShouldBe("http://localhost/resource/relPathResource"); }
public async Task location_header_is_absolute_uri() { var server = new InMemoryHost(() => ResourceSpace.Has.ResourcesNamed("root") .AtUri("/resource/") .HandledBy <AbsUriHandler>()); (await server.Get("/resource/")).Headers["Location"].ShouldBe("http://localhost/absResource"); }
public static async Task <string> GetJsonLdString(this InMemoryHost host, string uri) { var response = await host.Get(uri, "application/ld+json"); if (response.StatusCode / 100 != 2) { throw new InvalidOperationException($"Returned a {response.StatusCode} status code"); } return(response.ReadString()); }
public static async Task <JToken> GetJsonLdContent(this InMemoryHost host, string uri) { var response = await host.Get(uri, "application/ld+json"); if (response.StatusCode / 100 != 2) { throw new InvalidOperationException($"Returned a {response.StatusCode} status code"); } var responseBody = response.ReadString(); return(JObject.Parse(responseBody)); }
public async Task location_header_abs_path_is_relative_to_app_base() { var server = new InMemoryHost(() => ResourceSpace.Has.ResourcesNamed("root") .AtUri("/resource/") .HandledBy <RelUriAbsPath>()) { ApplicationVirtualPath = "/myApp/" }; (await server.Get("/resource/")).Headers["Location"].ShouldBe("http://localhost/myApp/absPathResource"); }
public async Task is_processed() { var server = new InMemoryHost(() => ResourceSpace.Has .ResourcesOfType <DemoResource>() .AtUri("/demo") .HandledBy <DemoResourceHandler>() .TranscodedBy <DemoResourceWriter>().ForMediaType("*/*")); var response = await server.Get("/demo"); response.StatusCode.ShouldBe(200); (await response.Entity.Stream.ReadToEndAsync()) .ShouldBe(new byte[] { 42 }); }
public static async Task <(IResponse, JToken)> GetJsonLd(this InMemoryHost host, string uri) { var response = await host.Get(uri, "application/ld+json"); if (response.StatusCode / 100 != 2) { throw new InvalidOperationException($"Returned a {response.StatusCode} status code"); } var responseBody = response.ReadString(); Console.WriteLine(responseBody); return(response, JObject.Parse(responseBody, new JsonLoadSettings() { DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error })); }
public exception_with_logging_in_memory_host() { _fakeLogger = new FakeLogger(); var server = new InMemoryHost(() => { ResourceSpace.Uses.Resolver.AddDependencyInstance( typeof(ILogger), _fakeLogger, DependencyLifetime.Singleton); ResourceSpace.Has.ResourcesNamed("root") .AtUri("/") .HandledBy <ThrowingHandler>().TranscodedBy <TextPlainCodec>(); }); _response = server.Get(server.ApplicationVirtualPath).Result; }
public async Task content_type_in_extension_overrides_conneg() { var server = new InMemoryHost(() => { ResourceSpace.Uses.UriDecorator <ContentTypeExtensionUriDecorator>(); ResourceSpace.Has.ResourcesOfType <object>() .WithoutUri .AsXmlDataContract().ForMediaType(MediaType.Xml.WithQuality(0.9f)).ForExtension("xml") .And .AsJsonDataContract().ForMediaType(MediaType.Json.WithQuality(1.0f)).ForExtension("json"); ResourceSpace.Has.ResourcesOfType <MyResource>() .AtUri("/stuff") .HandledBy <MyResourceHandler>(); }); var response = await server.Get("/stuff.xml"); response.StatusCode.ShouldBe(500); response.Entity.ContentType.MediaType.ShouldBe(MediaType.Xml.MediaType); }
public async Task negotiated_type_is_specific_mt() { var response = await server.Get("/1"); response.Headers.ContentType.ShouldBe(MediaType.Json); }
public async Task negotiated_type_is_default() { var response = await server.Get("/1"); response.Headers.ContentType.ShouldBe(MediaType.ApplicationOctetStream); }
public async Task get_without_qs_gets_Selected() { var response = await server.Get("/account/"); response.ReadString().ShouldBe("GET"); }