public void Disconnected_duringOriginAsk_throws()
        {
            var channelPair = TntTestHelper.CreateChannelPair();

            var originConnection = TntBuilder
                                   .UseContract <ITestContract, TestContractMock>()
                                   .UseReceiveDispatcher <NotThreadDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <NotThreadDispatcher>()
                                  .UseContractInitalization((c, _) =>
            {
                c.OnAsk += () =>
                {
                    channelPair.Disconnect();
                    try {
                        //call say method to notify channel about disconnection (tcp channel immitation)
                        originConnection.Contract.Say();
                    } catch (ConnectionIsLostException) { /*suppressTheException*/ }
                    return(0);
                };
            })
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            channelPair.ConnectAndStartReceiving();
            TestTools.AssertThrowsAndNotBlocks <ConnectionIsLostException>(() => originConnection.Contract.OnAsk());
        }
Exemple #2
0
        public void ProxyAskCall_ReturnsSettedValue(string returnedValue)
        {
            var channelPair = TntTestHelper.CreateChannelPair();

            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <ConveyorDispatcher>()
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <ITestContract, TestContractMock>()
                                   .UseContractInitalization((c, _) => c.OnAskS += (arg) => arg)
                                   .UseReceiveDispatcher <ConveyorDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();
            //set 'echo' handler
            proxyConnection.Contract.OnAskS += (arg) => arg;
            //call
            var proxyResult = originConnection.Contract.OnAskS(returnedValue);

            Assert.AreEqual(returnedValue, proxyResult);
        }
Exemple #3
0
        public void ProxyAskCall_ReturnsCorrectValue(string s, int i, long l)
        {
            var func = new Func <string, int, long, string>((s1, i2, l3) =>
            {
                return(s1 + i2.ToString() + l3.ToString());
            });


            var channelPair = TntTestHelper.CreateChannelPair();

            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <ConveyorDispatcher>()
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <ITestContract, TestContractMock>()
                                   .UseContractInitalization((c, _) => ((TestContractMock)c).WhenAskSILCalledCall(func))
                                   .UseReceiveDispatcher <ConveyorDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();

            var proxyResult  = proxyConnection.Contract.Ask(s, i, l);
            var originResult = func(s, i, l);

            Assert.AreEqual(originResult, proxyResult);
        }
        public void Proxy_SayMissingCord_NotThrows()
        {
            var channelPair     = TntTestHelper.CreateChannelPair();
            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <NotThreadDispatcher>()
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <IEmptyContract, EmptyContract>()
                                   .UseReceiveDispatcher <NotThreadDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();
            TestTools.AssertNotBlocks(proxyConnection.Contract.Say);
        }
        public void Proxy_AskWithException_Throws()
        {
            var channelPair     = TntTestHelper.CreateChannelPair();
            var proxyConnection = TntBuilder
                                  .UseContract <IExceptionalContract>()
                                  .UseReceiveDispatcher <NotThreadDispatcher>()
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <IExceptionalContract, ExceptionalContract>()
                                   .UseReceiveDispatcher <NotThreadDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();
            TestTools.AssertThrows_AndNotBlocks_AndContainsInfo <RemoteUnhandledException>(() => proxyConnection.Contract.Ask());
        }
        public void Proxy_AskMissingCord_Throws()
        {
            var channelPair     = TntTestHelper.CreateChannelPair();
            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <NotThreadDispatcher>()
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <IEmptyContract, EmptyContract>()
                                   .UseReceiveDispatcher <NotThreadDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();

            TestTools.AssertThrowsAndNotBlocks <RemoteContractImplementationException>(() => proxyConnection.Contract.Ask());
        }
        public void Origin_AsksNotImplemented_returnsDefault()
        {
            var channelPair = TntTestHelper.CreateChannelPair();

            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <NotThreadDispatcher>()
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <ITestContract, TestContractMock>()
                                   .UseReceiveDispatcher <NotThreadDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();

            var answer = TestTools.AssertNotBlocks(originConnection.Contract.OnAsk).Result;

            Assert.AreEqual(default(int), answer);
        }
Exemple #8
0
        public void ConveyourDispatcher_NetworkDeadlockNotHappens()
        {
            var channelPair     = TntTestHelper.CreateChannelPair();
            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  //On income ask request, calling rpc ask.
                                  //It can provoke an networkDeadlock
                                  .UseContractInitalization((c, _) => c.OnAsk += c.Ask)
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <ITestContract, TestContractMock>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();

            var task = TestTools.AssertNotBlocks(originConnection.Contract.OnAsk);

            Assert.AreEqual(TestContractMock.AskReturns, task.Result);
        }
        public void Origin_AskExceptioanlCallback_Throws()
        {
            var channelPair = TntTestHelper.CreateChannelPair();

            var proxyConnection = TntBuilder
                                  .UseContract <ITestContract>()
                                  .UseReceiveDispatcher <NotThreadDispatcher>()
                                  .UseContractInitalization((c, _) =>
            {
                c.OnAsk += () => { throw new InvalidOperationException(); };
            })
                                  .UseChannel(channelPair.CahnnelA)
                                  .Build();

            var originConnection = TntBuilder
                                   .UseContract <ITestContract, TestContractMock>()
                                   .UseReceiveDispatcher <NotThreadDispatcher>()
                                   .UseChannel(channelPair.ChannelB)
                                   .Build();

            channelPair.ConnectAndStartReceiving();
            TestTools.AssertThrows_AndNotBlocks_AndContainsInfo <RemoteUnhandledException>(() => originConnection.Contract.OnAsk());
        }