forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncOneWayTests.cs
More file actions
94 lines (78 loc) · 2.37 KB
/
AsyncOneWayTests.cs
File metadata and controls
94 lines (78 loc) · 2.37 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.Messaging;
using ServiceStack.ServiceClient.Web;
namespace ServiceStack.WebHost.Endpoints.Tests
{
[Route("/queue", "GET", IsOneWay = true)]
public class Queue
{
}
public class QueueResponse
{
}
public class QueueService : ServiceBase<Queue>
{
public static int timesCalled = 0;
protected override object Run(Queue request)
{
timesCalled += 1;
return null;
}
}
[TestFixture]
public class AsyncOneWayTests
{
private const string ListeningOn = "http://localhost:82/";
static int called = 0;
public class QueueAppHost : AppHostHttpListenerBase
{
public QueueAppHost()
: base("Queue service test", typeof(QueueService).Assembly)
{
}
public override void Configure(Funq.Container container)
{
var queue = new InMemoryTransientMessageFactory();
using (var serviceHost = queue.CreateMessageService())
{
serviceHost.RegisterHandler<Queue>(dto =>
{
var service = Container.Resolve<QueueService>();
service.Execute(dto);
return null;
});
serviceHost.Start();
}
container.Register<IMessageFactory>(queue);
}
}
QueueAppHost appHost;
[TestFixtureSetUp]
public void OnTestFixtureSetUp()
{
appHost = new QueueAppHost();
appHost.Init();
appHost.Start(ListeningOn);
}
[TestFixtureTearDown]
public void OnTestFixtureTearDown()
{
appHost.Dispose();
}
[TestCase("/queue")]
[TestCase("/json/oneway/queue")]
public void Does_add_message_to_queue_on_async_one_way_request(string url)
{
QueueService.timesCalled = 0;
var client = new JsonServiceClient(ListeningOn);
client.Get<QueueResponse>(url);
Assert.That(QueueService.timesCalled, Is.EqualTo(1));
}
}
}