public void MethodDispatcher_Publishes_Fault_Messages()
        {
            System.Messaging.IMessageFormatter binaryFormatter = new System.Messaging.BinaryMessageFormatter();
            using (ServiceBusRuntime runtime = Create.BinaryMsmqRuntime())
            {
                CEcho echo = new CEcho();

                SubscriptionEndpoint replyEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", null, null, typeof(void), new MethodDispatcher(echo, false), new PredicateMessageFilter(m =>
                {
                    bool result = m.Action == "ThrowInvalidOperationException";
                    return(result);
                }));
                runtime.Subscribe(replyEndpoint);
                runtime.Start();
                try
                {
                    string message = null;

                    MessageDelivery[] output = runtime.PublishTwoWay(new PublishRequest(typeof(void), "ThrowInvalidOperationException", message), TimeSpan.FromSeconds(100));

                    Assert.IsNotNull(output);
                    Assert.AreEqual(1, output.Length);
                    Assert.IsInstanceOfType(typeof(InvalidOperationException), output[0].Message);
                }
                finally
                {
                    runtime.Stop();
                }
            }
        }
        public void Can_Dispatch_Raw_Messages_To_Pass_Through_Endpoint()
        {
            PassThroughService pts  = new PassThroughService();
            ServiceHost        host = new ServiceHost(pts);

            host.Open();

            WcfProxyDispatcher   contractDispatcher = new WcfProxyDispatcher();
            SubscriptionEndpoint endpoint           = new SubscriptionEndpoint(Guid.NewGuid(), "test", "PassThroughClient", "net.pipe://localhost/passthrough", typeof(IPassThroughServiceContract), contractDispatcher, new PassThroughMessageFilter());

            string action = "http://someaction";
            string body   = "this is a test";

            pts.Validator = (msg) => { Assert.AreEqual(msg.Headers.Action, action); Assert.AreEqual(msg.GetBody <string>(), body); };

            Message message = Message.CreateMessage(MessageVersion.Default, action, body);

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore()))
            {
                runtime.Subscribe(endpoint);

                runtime.Start();

                contractDispatcher.Dispatch(new MessageDelivery(endpoint.Id, typeof(IPassThroughServiceContract), action, message, 3, new MessageDeliveryContext()));

                runtime.Stop();
            }

            Assert.AreEqual(1, pts.PublishedCount);

            host.Close();
        }
        public void Can_Dispatch_Raw_Messages_To_Typed_Endpoint()
        {
            ContractImplementation ci   = new ContractImplementation();
            ServiceHost            host = new ServiceHost(ci);

            host.Open();

            WcfProxyDispatcher contractDispatcher = new WcfProxyDispatcher();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore()))
            {
                SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", "PassThroughClient", "net.pipe://localhost/remotehello", typeof(IPassThroughServiceContract), contractDispatcher, null);

                runtime.Subscribe(endpoint);

                runtime.Start();

                string action = "PublishThis";
                string body   = "blah blah test test";

                XmlDocument document = new XmlDocument();
                document.LoadXml("<PublishThis xmlns='http://tempuri.org/'><message>" + body + "</message></PublishThis>");
                Message message = Message.CreateMessage(MessageVersion.Default, action, new XmlNodeReader(document));
                contractDispatcher.Dispatch(new MessageDelivery(endpoint.Id, typeof(IPassThroughServiceContract), action, message, 3, new MessageDeliveryContext()));

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(body, ci.PublishedMessages[0]);

                runtime.Stop();
            }

            host.Close();
        }
        public void Action_Stops_On_Stop()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();

            timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(1000)));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(1100);

                long beforeStopCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.GreaterOrEqual(beforeStopCount, 0);

                Thread.Sleep(1100);

                long afterStopCount = Interlocked.Read(ref count);

                Assert.GreaterOrEqual(beforeStopCount, afterStopCount);
            }
        }
        public void Can_Dispatch_To_ServiceHost()
        {
            ContractImplementation ci   = new ContractImplementation();
            ServiceHost            host = new ServiceHost(ci);

            host.Open();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore()))
            {
                WcfProxyDispatcher contractDispatcher = new WcfProxyDispatcher();

                SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", "NamedPipeClient", "net.pipe://localhost/remotehello", typeof(IContract), contractDispatcher, null);

                runtime.Subscribe(endpoint);

                runtime.Start();


                string message = "blah blah test test";


                contractDispatcher.Dispatch(new MessageDelivery(endpoint.Id, typeof(IContract), "PublishThis", message, 3, new MessageDeliveryContext()));

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(message, ci.PublishedMessages[0]);

                runtime.Stop();
                host.Close();
            }
        }
        public void Event_Starts_At_Preset_Time()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();

            timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100), DateTime.Now.AddSeconds(5)));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(3000);

                long curCount = Interlocked.Read(ref count);
                Assert.AreEqual(0, curCount);


                Thread.Sleep(3000);

                curCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.GreaterOrEqual(curCount, 0);
            }
        }
        public void Event_Auto_Starts_When_Running()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();
            var evt = new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(500);

                long curCount = Interlocked.Read(ref count);
                Assert.AreEqual(0, curCount);

                timerService.AddEvent(evt);

                Thread.Sleep(500);

                curCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.GreaterOrEqual(curCount, 3);
            }
        }
        public void Action_Stops_On_Stop()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();
            timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(1000)));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(1100);

                long beforeStopCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.GreaterOrEqual(beforeStopCount, 0);

                Thread.Sleep(1100);

                long afterStopCount = Interlocked.Read(ref count);

                Assert.GreaterOrEqual(beforeStopCount, afterStopCount);
            }
        }
        public void MethodDispatcher_Publishes_Response_Messages()
        {
            System.Messaging.IMessageFormatter binaryFormatter = new System.Messaging.BinaryMessageFormatter();
            using (ServiceBusRuntime runtime = Create.BinaryMsmqRuntime())
            {
                CEcho echo = new CEcho();

                SubscriptionEndpoint replyEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", null, null, typeof(void), new MethodDispatcher(echo, false), new PredicateMessageFilter(m => m.Action == "Echo"));
                runtime.Subscribe(replyEndpoint);
                runtime.Start();
                try
                {
                    string message = "echo this";

                    MessageDelivery[] output = runtime.PublishTwoWay(new PublishRequest(typeof(void), "Echo", message), TimeSpan.FromSeconds(100));

                    Assert.IsNotNull(output);
                    Assert.AreEqual(1, output.Length);
                    Assert.AreEqual(message, (string)output[0].Message);
                }
                finally
                {
                    runtime.Stop();
                }
            }
        }
        public void TestPythonTransformation()
        {
            ScriptTransformationDispatcher dispatcher = new ScriptTransformationDispatcher("py",
                                                                                           @"import clr

clr.AddReference(""IServiceOriented.ServiceBus"")
clr.AddReference(""IServiceOriented.ServiceBus.Scripting.UnitTests"")

from IServiceOriented.ServiceBus import PublishRequest
from IServiceOriented.ServiceBus.Scripting.UnitTests import AfterTransformation

def Execute():
    outgoing = AfterTransformation(int(request.Message.Value));
    return PublishRequest(request.ContractType, request.Action, outgoing)
"
                                                                                           , Microsoft.Scripting.SourceCodeKind.Statements);

            dispatcher.Script.Check();

            dispatcher.Script.ExecuteWithVariables(new Dictionary <string, object>()
            {
                { "request", new PublishRequest(null, null, new BeforeTransformation()
                    {
                        Value = "1000"
                    }) }
            });

            AutoResetEvent reset = new AutoResetEvent(false);

            bool success = false;

            ServiceBusRuntime runtime = new ServiceBusRuntime(new QueuedDeliveryCore(new NonTransactionalMemoryQueue(), new NonTransactionalMemoryQueue(), new NonTransactionalMemoryQueue()));

            runtime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Tranformation", null, null, typeof(void), dispatcher, new TypedMessageFilter(typeof(BeforeTransformation))));
            runtime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "AfterTransformation", null, null, typeof(void), new ActionDispatcher((subscription, md) =>
            {
                try
                {
                    success = ((AfterTransformation)md.Message).Value == 1000;
                }
                finally
                {
                    reset.Set();
                }
            }), new TypedMessageFilter(typeof(AfterTransformation))));
            runtime.Start();

            runtime.PublishOneWay(new PublishRequest(null, null, new BeforeTransformation()
            {
                Value = "1000"
            }));

            if (!reset.WaitOne(1000 * 10, true))
            {
                Assert.Fail("Waited too long");
            }

            runtime.Stop();
        }
        public void StartAndStop(Action inner)
        {
            serviceBusRuntime.Start();

            inner();

            serviceBusRuntime.Stop();
        }
        public void Action_Ticks_On_Intervals()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();

            timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(1000)));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(9100);

                long curCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.AreEqual(9, curCount);
            }
        }
        public void Event_Auto_Starts_When_Running()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();
            var evt = new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(500);

                long curCount = Interlocked.Read(ref count);
                Assert.AreEqual(0, curCount);

                timerService.AddEvent(evt);

                Thread.Sleep(500);

                curCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.GreaterOrEqual(curCount, 3);
            }
        }
Пример #14
0
 public void Stop()
 {
     _serviceBus.Stop();
 }
Пример #15
0
        public void Can_Dispatch_Raw_Messages_To_Typed_Endpoint()
        {
            ContractImplementation ci = new ContractImplementation();
            ServiceHost host = new ServiceHost(ci);
            host.Open();

            WcfProxyDispatcher contractDispatcher = new WcfProxyDispatcher();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore()))
            {

                SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", "PassThroughClient", "net.pipe://localhost/remotehello", typeof(IPassThroughServiceContract), contractDispatcher, null);

                runtime.Subscribe(endpoint);

                runtime.Start();

                string action = "PublishThis";
                string body = "blah blah test test";

                XmlDocument document = new XmlDocument();
                document.LoadXml("<PublishThis xmlns='http://tempuri.org/'><message>" + body + "</message></PublishThis>");
                Message message = Message.CreateMessage(MessageVersion.Default, action, new XmlNodeReader(document));
                contractDispatcher.Dispatch(new MessageDelivery(endpoint.Id, typeof(IPassThroughServiceContract), action, message, 3, new MessageDeliveryContext()));

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(body, ci.PublishedMessages[0]);

                runtime.Stop();
            }

            host.Close();
        }
Пример #16
0
        public void Can_Dispatch_Raw_Messages_To_Pass_Through_Endpoint()
        {
            PassThroughService pts = new PassThroughService();
            ServiceHost host = new ServiceHost(pts);
            host.Open();

            WcfProxyDispatcher contractDispatcher = new WcfProxyDispatcher();
            SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", "PassThroughClient", "net.pipe://localhost/passthrough", typeof(IPassThroughServiceContract), contractDispatcher, new PassThroughMessageFilter());

            string action = "http://someaction";
            string body = "this is a test";

            pts.Validator = (msg) => { Assert.AreEqual(msg.Headers.Action, action); Assert.AreEqual(msg.GetBody<string>(), body); };

            Message message = Message.CreateMessage(MessageVersion.Default, action, body);

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore()))
            {
                runtime.Subscribe(endpoint);

                runtime.Start();

                contractDispatcher.Dispatch(new MessageDelivery(endpoint.Id, typeof(IPassThroughServiceContract), action, message, 3, new MessageDeliveryContext()));

                runtime.Stop();
            }

            Assert.AreEqual(1, pts.PublishedCount);

            host.Close();
        }
Пример #17
0
        public void Can_Dispatch_To_ServiceHost()
        {
            ContractImplementation ci = new ContractImplementation();
            ServiceHost host = new ServiceHost(ci);
            host.Open();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore()))
            {
                WcfProxyDispatcher contractDispatcher = new WcfProxyDispatcher();

                SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", "NamedPipeClient", "net.pipe://localhost/remotehello", typeof(IContract), contractDispatcher, null);

                runtime.Subscribe(endpoint);

                runtime.Start();

                string message = "blah blah test test";

                contractDispatcher.Dispatch(new MessageDelivery(endpoint.Id, typeof(IContract), "PublishThis", message, 3, new MessageDeliveryContext()));

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(message, ci.PublishedMessages[0]);

                runtime.Stop();
                host.Close();
            }
        }
        public void Action_Ticks_On_Intervals()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();
            timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(1000)));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(9100);

                long curCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.AreEqual(9, curCount);
            }
        }
        public void Event_Starts_At_Preset_Time()
        {
            long count = 0;

            TimerRuntimeService timerService = new TimerRuntimeService();
            timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100), DateTime.Now.AddSeconds(5)));

            DeliveryCore deliveryCore = new DirectDeliveryCore();

            using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService))
            {
                runtime.Start();

                Thread.Sleep(3000);

                long curCount = Interlocked.Read(ref count);
                Assert.AreEqual(0, curCount);

                Thread.Sleep(3000);

                curCount = Interlocked.Read(ref count);

                runtime.Stop();

                Assert.GreaterOrEqual(curCount, 0);
            }
        }