public
Description:
Homepage: http://www.iserviceoriented.com
Clone URL: git://github.com/jezell/iserviceoriented.git
iserviceoriented / IServiceOriented.ServiceBus.UnitTests / TestFileSystemDispatchersAndListeners.cs
100644 104 lines (82 sloc) 4.981 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
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using IServiceOriented.ServiceBus.Delivery;
using IServiceOriented.ServiceBus.Listeners;
using IServiceOriented.ServiceBus.Dispatchers;
using NUnit.Framework;
using System.IO;
using IServiceOriented.ServiceBus.Delivery.Formatters;
using System.ServiceModel.Channels;
 
namespace IServiceOriented.ServiceBus.UnitTests
{
[TestFixture]
    public class TestFileSystemDispatchersAndListeners
    {
        public TestFileSystemDispatchersAndListeners()
        {
        }
 
[TestFixtureSetUp]
        public void Init()
        {
            if (Config.IncomingFilePath == null || Config.ProcessedFilePath == null)
            {
                Assert.Ignore("No incoming or processed file path configured. Ignoring tests");
            }
            else
            {
                if (Directory.Exists(Config.IncomingFilePath)) Directory.Delete(Config.IncomingFilePath, true);
                if (Directory.Exists(Config.ProcessedFilePath)) Directory.Delete(Config.ProcessedFilePath, true);
            }
        }
[Test]
        public void FileSystemDispatcher_Can_Send_To_FileSystemListener()
        {
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;
 
            ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "File System Dispatcher", null, null, typeof(IContract), new FileSystemDispatcher(new ConverterMessageDeliveryWriterFactory(encoder, typeof(IContract)), Config.IncomingFilePath), new PassThroughMessageFilter());
            dispatchRuntime.Subscribe(subscription);
 
            ServiceBusRuntime listenerRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var listener = new ListenerEndpoint(Guid.NewGuid(), "File System Listener", null, null, typeof(IContract), new FileSystemListener(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)), Config.IncomingFilePath, Config.ProcessedFilePath));
            listenerRuntime.AddListener(listener);
            listenerRuntime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Pass through", null, null, typeof(IContract), new ActionDispatcher((se, md) => { }), new PassThroughMessageFilter()));
            
            var dispatchTester = new ServiceBusTest(dispatchRuntime);
            var listenerTester = new ServiceBusTest(listenerRuntime);
 
 
            string message = "test this thing";
 
            dispatchTester.StartAndStop(() =>
            {
                listenerTester.WaitForDeliveries(1, TimeSpan.FromSeconds(10), ()=>
                {
                    dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", message);
                });
            });
 
            dispatchRuntime.RemoveSubscription(subscription);
        }
 
[Test]
        public void FileSystemDispatcher_Picks_Up_Existing_Messages()
        {
 
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;
 
            ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "File System Dispatcher", null, null, typeof(IContract), new FileSystemDispatcher(new ConverterMessageDeliveryWriterFactory(encoder,typeof(IContract)),Config.IncomingFilePath), new PassThroughMessageFilter());
            dispatchRuntime.Subscribe(subscription);
 
            ServiceBusRuntime listenerRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var listener = new ListenerEndpoint(Guid.NewGuid(), "File System Listener", null, null, typeof(IContract), new FileSystemListener(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)),Config.IncomingFilePath, Config.ProcessedFilePath));
            listenerRuntime.AddListener(listener);
            listenerRuntime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Pass through", null, null, typeof(IContract), new ActionDispatcher((se, md) => { }), new PassThroughMessageFilter()));
 
            var dispatchTester = new ServiceBusTest(dispatchRuntime);
            var listenerTester = new ServiceBusTest(listenerRuntime);
 
 
            string message = "test this thing";
 
            dispatchTester.StartAndStop(() =>
            {
                dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", message);
 
                listenerTester.WaitForDeliveries(1, TimeSpan.FromSeconds(10), () =>
                {
                });
            });
 
            dispatchRuntime.RemoveSubscription(subscription);
        }
    }
}