forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomServiceRunnerTests.cs
More file actions
90 lines (76 loc) · 2.76 KB
/
Copy pathCustomServiceRunnerTests.cs
File metadata and controls
90 lines (76 loc) · 2.76 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
using Funq;
using NUnit.Framework;
using ServiceStack.Host;
namespace ServiceStack.WebHost.Endpoints.Tests
{
[TestFixture]
public class CustomServiceRunnerTests
{
string ListeningOn = Config.AbsoluteBaseUri;
private ServiceStackHost appHost;
[OneTimeSetUp]
public void TestFixtureSetUp()
{
appHost = new CustomServiceRunnerAppHost()
.Init()
.Start(ListeningOn);
}
[OneTimeTearDown]
public void TestFixtureTearDown()
{
appHost.Dispose();
}
public class CustomServiceRunnerAppHost : AppHostHttpListenerBase
{
public CustomServiceRunnerAppHost()
: base("CustomServiceRunner", typeof(CustomServiceRunnerAppHost).Assembly) { }
public override void Configure(Container container) {}
public override Web.IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
{
return new CustomServiceRunner<TRequest>(this, actionContext);
}
}
public class CustomServiceRunner<T> : ServiceRunner<T>
{
public CustomServiceRunner(IAppHost appHost, ActionContext actionContext)
: base(appHost, actionContext) {
}
public override object OnAfterExecute(Web.IRequest req, object response)
{
var dto = response as CustomRunnerResponse;
if (dto != null)
{
dto.ServiceName = base.ActionContext.ServiceType.Name;
dto.RequestName = base.ActionContext.RequestType.Name;
}
return base.OnAfterExecute(req, response);
}
}
public class CustomRunner : IReturn<CustomRunnerResponse>
{
public int Id { get; set; }
}
public class CustomRunnerResponse
{
public int Id { get; set; }
public string RequestName { get; set; }
public string ServiceName { get; set; }
}
public class CustomRunnerService : Service
{
public object Get(CustomRunner request)
{
return new CustomRunnerResponse { Id = 1 };
}
}
[Test]
public void ServiceRunner_has_Request_and_ServiceType()
{
var client = new JsonServiceClient(ListeningOn);
var response = client.Get(new CustomRunner { Id = 1 });
Assert.That(response.Id, Is.EqualTo(1));
Assert.That(response.ServiceName, Is.EqualTo(typeof(CustomRunnerService).Name));
Assert.That(response.RequestName, Is.EqualTo(typeof(CustomRunner).Name));
}
}
}