forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceClientTestBase.cs
More file actions
51 lines (42 loc) · 1.12 KB
/
ServiceClientTestBase.cs
File metadata and controls
51 lines (42 loc) · 1.12 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
using System;
using NUnit.Framework;
namespace ServiceStack.WebHost.Endpoints.Tests.Support
{
public abstract class ServiceClientTestBase : IDisposable
{
protected const string BaseUrl = "http://127.0.0.1:8083/";
private AppHostHttpListenerBase appHost;
public abstract AppHostHttpListenerBase CreateListener();
[OneTimeSetUp]
public virtual void TestFixtureSetUp()
{
appHost = CreateListener();
appHost.Init();
appHost.Start(BaseUrl);
}
[OneTimeTearDown]
public void OnTestFixtureTearDown()
{
Dispose();
}
public void Dispose()
{
if (appHost == null) return;
appHost.Dispose();
}
public void Send<TRes>(object request, Action<TRes> validate)
{
using (var xmlClient = new XmlServiceClient(BaseUrl))
using (var jsonClient = new JsonServiceClient(BaseUrl))
using (var jsvClient = new JsvServiceClient(BaseUrl))
{
var xmlResponse = xmlClient.Send<TRes>(request);
validate(xmlResponse);
var jsonResponse = jsonClient.Send<TRes>(request);
validate(jsonResponse);
var jsvResponse = jsvClient.Send<TRes>(request);
validate(jsvResponse);
}
}
}
}