forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedServiceTests.cs
More file actions
73 lines (58 loc) · 1.77 KB
/
Copy pathNestedServiceTests.cs
File metadata and controls
73 lines (58 loc) · 1.77 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
using System.Threading.Tasks;
using NUnit.Framework;
using ServiceStack.WebHost.Endpoints.Tests.Support.Host;
namespace ServiceStack.WebHost.Endpoints.Tests
{
[TestFixture]
public class NestedServiceTests
{
protected const string ListeningOn = "http://localhost:1337/";
ExampleAppHostHttpListener appHost;
[TestFixtureSetUp]
public void OnTestFixtureSetUp()
{
appHost = new ExampleAppHostHttpListener();
appHost.Init();
appHost.Start(ListeningOn);
}
[TestFixtureTearDown]
public void OnTestFixtureTearDown()
{
appHost.Dispose();
}
[Test]
public void Can_call_nested_service_with_ServiceClient()
{
var client = new JsonServiceClient(ListeningOn);
var reqRoot = new Root { Id = 1 };
Assert.That(reqRoot.ToGetUrl(), Is.EqualTo("/root/1"));
var reqNested = new Root.Nested { Id = 2 };
Assert.That(reqNested.ToGetUrl(), Is.EqualTo("/root.nested/2"));
var root = client.Get(reqRoot);
Assert.That(root.Id, Is.EqualTo(1));
var nested = client.Get(reqNested);
Assert.That(nested.Id, Is.EqualTo(2));
}
}
[Route("/root/{Id}")]
public class Root : IReturn<Root>
{
public int Id { get; set; }
[Route("/root.nested/{Id}")]
public class Nested : IReturn<Root.Nested>
{
public int Id { get; set; }
}
}
public class NestedService : Service
{
public object Any(Root request)
{
return request;
}
public object Any(Root.Nested request)
{
return request;
}
}
}