public void TestProxiedToStringMethod()
        {
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();

            proxyFactory.DefaultRequestChannel = new DirectChannel();
            proxyFactory.ServiceInterface      = typeof(ITestService);
            proxyFactory.AfterPropertiesSet();
            Object       proxy    = proxyFactory.GetObject();
            const string expected = "gateway proxy for";
            string       current  = proxy.ToString();

            Assert.That(current.Substring(0, expected.Length), Is.EqualTo(expected));
        }
        public void TestRequestReplyWithAnonymousChannel()
        {
            QueueChannel requestChannel = new QueueChannel();

            StartResponder(requestChannel);
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();

            proxyFactory.DefaultRequestChannel = requestChannel;
            proxyFactory.ServiceInterface      = typeof(ITestService);
            proxyFactory.AfterPropertiesSet();
            ITestService service = (ITestService)proxyFactory.GetObject();
            String       result  = service.RequestReply("foo");

            Assert.That(result, Is.EqualTo("foobar"));
        }
        public void TestOneWay()
        {
            QueueChannel requestChannel            = new QueueChannel();
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();

            proxyFactory.DefaultRequestChannel = requestChannel;
            proxyFactory.ServiceInterface      = typeof(ITestService);
            proxyFactory.AfterPropertiesSet();
            ITestService service = (ITestService)proxyFactory.GetObject();

            service.OneWay("test");
            IMessage message = requestChannel.Receive(TimeSpan.FromMilliseconds(1000));

            Assert.IsNotNull(message);
            Assert.That(message.Payload, Is.EqualTo("test"));
        }
        public void TestSolicitResponse()
        {
            QueueChannel replyChannel = new QueueChannel();

            replyChannel.Send(new StringMessage("foo"));
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();

            proxyFactory.ServiceInterface      = typeof(ITestService);
            proxyFactory.DefaultRequestChannel = new DirectChannel();
            proxyFactory.DefaultReplyChannel   = replyChannel;
            proxyFactory.AfterPropertiesSet();
            ITestService service = (ITestService)proxyFactory.GetObject();

            string result = service.SolicitResponse();

            Assert.IsNotNull(result);
            Assert.That(result, Is.EqualTo("foo"));
        }
        public void TestServiceMustBeInterface()
        {
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();
            int count = 0;

            try
            {
                proxyFactory.ServiceInterface = typeof(ITestService);
                count++;
                proxyFactory.ServiceInterface = typeof(string);
                count++;
            }
            catch (ArgumentException)
            {
                // expected
            }
            Assert.That(count, Is.EqualTo(1));
        }
        public void TestRequestReplyWithTypeConversion()
        {
            QueueChannel requestChannel = new QueueChannel();

            new Thread(new ThreadStart(delegate
            {
                IMessage input      = requestChannel.Receive();
                StringMessage reply = new StringMessage(input.Payload + "456");
                ((IMessageChannel)input.Headers.ReplyChannel).Send(reply);
            })).Start();
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();

            proxyFactory.ServiceInterface      = typeof(ITestService);
            proxyFactory.DefaultRequestChannel = requestChannel;
            proxyFactory.AfterPropertiesSet();
            ITestService service = (ITestService)proxyFactory.GetObject();
            int          result  = service.RequestReplyWithIntegers(123);

            Assert.That(result, Is.EqualTo(123456));
        }
        public void TestMessageAsReturnValue()
        {
            QueueChannel requestChannel = new QueueChannel();

            new Thread(new ThreadStart(delegate
            {
                IMessage input      = requestChannel.Receive();
                StringMessage reply = new StringMessage(input.Payload + "bar");
                ((IMessageChannel)input.Headers.ReplyChannel).Send(reply);
            })).Start();
            GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();

            proxyFactory.ServiceInterface      = typeof(ITestService);
            proxyFactory.DefaultRequestChannel = requestChannel;
            proxyFactory.AfterPropertiesSet();
            ITestService service = (ITestService)proxyFactory.GetObject();
            IMessage     result  = service.RequestReplyWithMessageReturnValue("foo");

            Assert.That(result.Payload, Is.EqualTo("foobar"));
        }