forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceStackHandlerPathTests.cs
More file actions
103 lines (87 loc) · 3.36 KB
/
ServiceStackHandlerPathTests.cs
File metadata and controls
103 lines (87 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ServiceStack.Text;
namespace ServiceStack.ServiceHost.Tests
{
public class RequestPath
{
public RequestPath(string path, string host, string pathInfo, string rawUrl)
{
Path = path;
Host = host;
PathInfo = pathInfo;
RawUrl = rawUrl;
AbsoluteUri = "http://localhost" + rawUrl;
}
public string Path { get; set; }
public string Host { get; set; }
public string PathInfo { get; set; }
public string RawUrl { get; set; }
public string AbsoluteUri { get; set; }
}
[TestFixture]
public class ServiceStackHandlerPathTests
{
public string ResolvePath(string mode, string path)
{
return WebHost.Endpoints.Extensions.HttpRequestExtensions.
GetPathInfo(path, mode, path.Split('/').First(x => x != ""));
}
[Test]
public void Can_resolve_root_path()
{
var results = new List<string> {
ResolvePath(null, "/handler.all35"),
ResolvePath(null, "/handler.all35/"),
ResolvePath("api", "/location.api.wildcard35/api"),
ResolvePath("api", "/location.api.wildcard35/api/"),
ResolvePath("servicestack", "/location.servicestack.wildcard35/servicestack"),
ResolvePath("servicestack", "/location.servicestack.wildcard35/servicestack/"),
};
Console.WriteLine(results.Dump());
Assert.That(results.All(x => x == "/"));
}
[Test]
public void Can_resolve_metadata_paths()
{
var results = new List<string> {
ResolvePath(null, "/handler.all35/metadata"),
ResolvePath(null, "/handler.all35/metadata/"),
ResolvePath("api", "/location.api.wildcard35/api/metadata"),
ResolvePath("api", "/location.api.wildcard35/api/metadata/"),
ResolvePath("servicestack", "/location.servicestack.wildcard35/servicestack/metadata"),
ResolvePath("servicestack", "/location.servicestack.wildcard35/servicestack/metadata/"),
};
Console.WriteLine(results.Dump());
Assert.That(results.All(x => x == "/metadata"));
}
[Test]
public void Can_resolve_metadata_json_paths()
{
var results = new List<string> {
ResolvePath(null, "/handler.all35/json/metadata"),
ResolvePath(null, "/handler.all35/json/metadata/"),
ResolvePath("api", "/location.api.wildcard35/api/json/metadata"),
ResolvePath("api", "/location.api.wildcard35/api/json/metadata/"),
ResolvePath("servicestack", "/location.api.wildcard35/servicestack/json/metadata"),
ResolvePath("servicestack", "/location.api.wildcard35/servicestack/json/metadata/"),
};
Console.WriteLine(results.Dump());
Assert.That(results.All(x => x == "/json/metadata"));
}
[Test]
public void Can_resolve_paths_with_multipart_root()
{
var results = new List<string> {
WebHost.Endpoints.Extensions.HttpRequestExtensions.GetPathInfo("/api/foo/metadata", "api/foo", "api"),
WebHost.Endpoints.Extensions.HttpRequestExtensions.GetPathInfo("/api/foo/1.0/wildcard/metadata", "api/foo/1.0/wildcard", "api"),
WebHost.Endpoints.Extensions.HttpRequestExtensions.GetPathInfo("/location.api.wildcard35/api/foo/metadata", "api/foo", "api"),
WebHost.Endpoints.Extensions.HttpRequestExtensions.GetPathInfo("/this/is/very/nested/metadata", "this/is/very/nested", "api"),
};
Console.WriteLine(results.Dump());
Assert.That(results.All(x => x == "/metadata"));
}
}
}