public
Description:
Homepage: http://www.iserviceoriented.com
Clone URL: git://github.com/jezell/iserviceoriented.git
100644 62 lines (50 sloc) 2.613 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using IServiceOriented.ServiceBus.Delivery;
using IServiceOriented.ServiceBus.Listeners;
using IServiceOriented.ServiceBus.Dispatchers;
using System.ServiceModel.Channels;
 
namespace IServiceOriented.ServiceBus.UnitTests
{
[TestFixture]
    public class TestWcfListener
    {
[Test]
        public void WcfListener_Publishes_Incoming_Messages_Properly()
        {
            ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore());
            runtime.AddListener(new ListenerEndpoint("test", "NamedPipeListener", "net.pipe://localhost/remotehello", typeof(IContract), new WcfServiceHostListener()));
           
            string message = "This is a test";
 
            runtime.Subscribe(new SubscriptionEndpoint("test subscription", null, null, typeof(IContract), new ActionDispatcher((se, md) => { Assert.AreEqual(message, (string)md.Message); }), new PassThroughMessageFilter()));
 
            ServiceBusTest tester = new ServiceBusTest(runtime);
            tester.WaitForDeliveries(1, TimeSpan.FromSeconds(5), () =>
            {
                Service.Use<IContract>("NamedPipeClient", contract =>
                {
                    contract.PublishThis(message);
                });
            });
        }
 
[Test]
        public void WcfListener_Can_Listen_For_Raw_Messages()
        {
            ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore());
            runtime.AddListener(new ListenerEndpoint("test", "PassThroughListener", "net.pipe://localhost/passthrough", typeof(IPassThroughServiceContract), new WcfServiceHostListener()));
 
            string action = "http://someaction";
            string body = "some body";
 
            runtime.Subscribe(new SubscriptionEndpoint("test subscription", null, null, typeof(IContract), new ActionDispatcher((se, md) => { Assert.AreEqual(action, ((Message)md.Message).Headers.Action); Assert.AreEqual(body, ((Message)md.Message).GetBody<string>()); }), new PassThroughMessageFilter()));
 
            ServiceBusTest tester = new ServiceBusTest(runtime);
            tester.WaitForDeliveries(1, TimeSpan.FromSeconds(5), () =>
            {
                Service.Use<IPassThroughServiceContract>("PassThroughClient", contract =>
                {
                    Message message = Message.CreateMessage(MessageVersion.Default, action, body);
                    contract.Send(message);
                });
            });
        }
 
       
 
    }
}