Пример #1
0
        public void OneServerOneClientTooBigMessage2Test()
        {
            const string Login             = "******";
            const string Pass              = "******";
            var          serverDataContext = Mock.Of <IDataContext>(ctx => ctx.LoginExists(Login) &&
                                                                    ctx.ValidateLoginPass(Login, Pass));

            var server = new ChatServer(serverDataContext, this.ServerPort);

            var chatClient = new ChatClient();

            chatClient.Init("localhost", this.ServerPort, Login, Pass);
            chatClient.ValidateItselfAndServer();

            chatClient.SetUpSecureChannel();

            var logonResult = chatClient.LogOnInvalidMessage1();

            Assert.AreEqual(0, logonResult);

            chatClient.StartListener();

            chatClient.StopListener();
            server.Stop();
        }
Пример #2
0
        private ChatClient SetUpChatClient(string login, string pass)
        {
            var chatClient = new ChatClient();

            chatClient.Init("localhost", this.ServerPort, login, pass);
            chatClient.ValidateItselfAndServer();
            chatClient.SetUpSecureChannel();

            var logonResult = chatClient.LogOn();

            Assert.AreEqual(0, logonResult);

            chatClient.StartListener();

            var joinRoomResult = chatClient.performJoinRoom("r1", "testRoomPass");

            Assert.True(joinRoomResult);

            return(chatClient);
        }
Пример #3
0
        public void OneServerOneClientTest()
        {
            const string Login             = "******";
            const string Pass              = "******";
            var          serverDataContext = Mock.Of <IDataContext>(ctx => ctx.LoginExists(Login) &&
                                                                    ctx.ValidateLoginPass(Login, Pass));

            var server = new ChatServer(serverDataContext, this.ServerPort);

            var chatClient = new ChatClient();

            chatClient.Init("localhost", this.ServerPort, Login, Pass);
            chatClient.ValidateItselfAndServer();

            chatClient.SetUpSecureChannel();

            var logonResult = chatClient.LogOn();

            Assert.AreEqual(0, logonResult);

            chatClient.StartListener();

            var joinRoomResult = chatClient.performJoinRoom("r1", "testRoomPass");

            Assert.True(joinRoomResult);

            var messageReceivedBack = false;
            var syncRef             = new object();

            chatClient.MessageProcessor.addProcessor(
                "r1",
                (source, dest, msg) =>
            {
                if (msg == "testMsg")
                {
                    lock (syncRef)
                    {
                        messageReceivedBack = true;
                    }
                }
            });

            chatClient.queueChatMsg(3, "r1", "testMsg");

            Func <bool> messageReceivedBackRead = () =>
            {
                lock (syncRef)
                {
                    return(messageReceivedBack);
                }
            };

            var waiter = Task.Run(
                () =>
            {
                while (!messageReceivedBackRead())
                {
                    Thread.Sleep(100);
                }
            });

            Task.WaitAll(new[] { waiter }, 5000);
            Assert.True(messageReceivedBackRead());

            chatClient.StopListener();
            server.Stop();
        }
Пример #4
0
        public void OneServerOneClientTest()
        {
            const string Login = "******";
            const string Pass = "******";
            var serverDataContext = Mock.Of<IDataContext>(ctx => ctx.LoginExists(Login) &&
                ctx.ValidateLoginPass(Login, Pass));

            var server = new ChatServer(serverDataContext, this.ServerPort);

            var chatClient = new ChatClient();

            chatClient.Init("localhost", this.ServerPort, Login, Pass);
            chatClient.ValidateItselfAndServer();

            chatClient.SetUpSecureChannel();

            var logonResult = chatClient.LogOn();
            Assert.AreEqual(0, logonResult);

            chatClient.StartListener();

            var joinRoomResult = chatClient.performJoinRoom("r1", "testRoomPass");
            Assert.True(joinRoomResult);

            var messageReceivedBack = false;
            var syncRef = new object();
            chatClient.MessageProcessor.addProcessor(
                "r1",
                (source, dest, msg) =>
                    {
                        if (msg == "testMsg")
                        {
                            lock (syncRef)
                            {
                                messageReceivedBack = true;
                            }
                        }
                    });

            chatClient.queueChatMsg(3, "r1", "testMsg");

            Func<bool> messageReceivedBackRead = () =>
                {
                    lock (syncRef)
                    {
                        return messageReceivedBack;
                    }
                };

            var waiter = Task.Run(
                () =>
                    {
                        while (!messageReceivedBackRead())
                        {
                            Thread.Sleep(100);
                        }
                    });
            Task.WaitAll(new[] { waiter }, 5000);
            Assert.True(messageReceivedBackRead());

            chatClient.StopListener();
            server.Stop();
        }
Пример #5
0
        private ChatClient SetUpChatClient(string login, string pass)
        {
            var chatClient = new ChatClient();

            chatClient.Init("localhost", this.ServerPort, login, pass);
            chatClient.ValidateItselfAndServer();
            chatClient.SetUpSecureChannel();

            var logonResult = chatClient.LogOn();
            Assert.AreEqual(0, logonResult);

            chatClient.StartListener();

            var joinRoomResult = chatClient.performJoinRoom("r1", "testRoomPass");
            Assert.True(joinRoomResult);

            return chatClient;
        }
Пример #6
0
        public void OneServerOneClientTooBigMessage2Test()
        {
            const string Login = "******";
            const string Pass = "******";
            var serverDataContext = Mock.Of<IDataContext>(ctx => ctx.LoginExists(Login) &&
                ctx.ValidateLoginPass(Login, Pass));

            var server = new ChatServer(serverDataContext, this.ServerPort);

            var chatClient = new ChatClient();

            chatClient.Init("localhost", this.ServerPort, Login, Pass);
            chatClient.ValidateItselfAndServer();

            chatClient.SetUpSecureChannel();

            var logonResult = chatClient.LogOnInvalidMessage1();
            Assert.AreEqual(0, logonResult);

            chatClient.StartListener();

            chatClient.StopListener();
            server.Stop();
        }