Exemple #1
0
        public void ServerAcceptConnection_AllowReceiveEqualTrue()
        {
            var server = new TestChannelServer <ITestContract>(TntBuilder.UseContract <ITestContract, TestContractMock>());

            server.StartListening();
            var clientChannel = new TestChannel();

            TntBuilder.UseContract <ITestContract>().UseChannel(clientChannel).Build();
            server.TestListener.ImmitateAccept(clientChannel);
            Assert.IsTrue(server.GetAllConnections().First().Channel.AllowReceive);
        }
Exemple #2
0
        public void Run()
        {
            Console.WriteLine("TNT unit/integration test example.");
            Console.WriteLine("In this example, we will create connection with custom mock channell instead of using tcp.");
            Console.WriteLine("The example shows you how to write integration/unit tests at your code");
            Console.WriteLine();

            #region arrange

            var serverBuilder = TntBuilder
                                .UseContract <IStage3EchoContract, Stage3EchoContract>()
                                .UseReceiveDispatcher <NotThreadDispatcher>(); //Use "no thread dispatcher" to perform the calls in the calling thread

            var server = new TestChannelServer <IStage3EchoContract>(serverBuilder);
            server.StartListening();

            var clientConnection = TntBuilder
                                   .UseContract <IStage3EchoContract>()
                                   .UseChannel(new TestChannel())
                                   .Build();
            //Immitate connection:
            server.TestListener.ImmitateAccept(clientConnection.Channel);

            #endregion

            #region act
            string testMessage = "Watup buddy?";

            var echo = clientConnection.Contract.Send("superman", testMessage);
            #endregion

            #region assert

            // use
            // Assert.AreEqual(echo, testMessage)
            // with your test framework instead

            if (echo != testMessage)
            {
                throw new Exception("Unit test failed");
            }
            else
            {
                Console.WriteLine("Integration test passed");
            }

            #endregion

            Console.WriteLine("Press any key for exit...");
            Console.ReadKey();
        }
Exemple #3
0
        public void ServerAcceptConnection_AfterConnectRaised()
        {
            var server = new TestChannelServer <ITestContract>(TntBuilder.UseContract <ITestContract, TestContractMock>());

            server.StartListening();
            IConnection <ITestContract, TestChannel> incomeContractConnection = null;

            server.AfterConnect += (sender, income) => incomeContractConnection = income;
            var clientChannel   = new TestChannel();
            var proxyConnection = TntBuilder.UseContract <ITestContract>().UseChannel(clientChannel).Build();

            server.TestListener.ImmitateAccept(clientChannel);
            Assert.IsNotNull(incomeContractConnection, "AfterConnect not raised");
        }
Exemple #4
0
        public void ClientDisconnected_DisconnectedRaised()
        {
            var server = new TestChannelServer <ITestContract>(TntBuilder.UseContract <ITestContract, TestContractMock>());

            server.StartListening();
            ClientDisconnectEventArgs <ITestContract, TestChannel> disconnectedConnection = null;

            server.Disconnected += (sender, args) => disconnectedConnection = args;
            var clientChannel   = new TestChannel();
            var proxyConnection = TntBuilder.UseContract <ITestContract>().UseChannel(clientChannel).Build();
            var pair            = server.TestListener.ImmitateAccept(clientChannel);

            pair.Disconnect();

            Assert.IsNotNull(disconnectedConnection, "Disconnect not raised");
        }
Exemple #5
0
        public void ServerAcceptConnection_BeforeConnectRaised()
        {
            var server = new TestChannelServer <ITestContract>(TntBuilder.UseContract <ITestContract, TestContractMock>());

            server.StartListening();
            BeforeConnectEventArgs <ITestContract, TestChannel> connectionArgs = null;

            server.BeforeConnect += (sender, args) => connectionArgs = args;

            var clientChannel   = new TestChannel();
            var proxyConnection = TntBuilder.UseContract <ITestContract>().UseChannel(clientChannel).Build();

            server.TestListener.ImmitateAccept(clientChannel);

            Assert.IsNotNull(connectionArgs, "AfterConnect not raised");
        }