コード例 #1
0
ファイル: Program.cs プロジェクト: johnsmith9264/MyChat
        public static void Main()
        {
            Logger.Debug("Main()");

            // Visual
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LogForm = new LogForm();

            AppDomain.CurrentDomain.UnhandledException += (sender, e) => LogException(e.ExceptionObject as Exception);
            Application.ThreadException += (sender, e) => LogException(e.Exception);

            Server = new ChatServer(DataContext.Instance, Properties.Settings.Default.Port);

            // Init ServerConfig Form
            new ServerConfig();
            Application.Run();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: andriy-f/MyChat
        public static void Main()
        {
            Logger.Debug("Main()");

            // Visual
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LogForm = new LogForm();

            AppDomain.CurrentDomain.UnhandledException += (sender, e) => LogException(e.ExceptionObject as Exception);
            Application.ThreadException += (sender, e) => LogException(e.Exception);

            Server = new ChatServer(DataContext.Instance, Properties.Settings.Default.Port);

            // Init ServerConfig Form
            new ServerConfig();
            Application.Run();
        }
コード例 #3
0
        public void OneServerSeveralClientsTest()
        {
            const string LoginPrefix = "testUser";
            const string PassPrefix = "testPass";
            var serverDataContext =
                Mock.Of<IDataContext>(
                    ctx =>
                    ctx.LoginExists(It.Is<string>(l => l.StartsWith(LoginPrefix)))
                    && ctx.ValidateLoginPass(It.IsAny<string>(), It.IsAny<string>()));

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

            var clientList = new List<ChatClient>(10);
            for (int i = 0; i < 10; i++)
            {
                clientList.Add(this.SetUpChatClient(LoginPrefix + i, PassPrefix + i));
            }

            int j = 0;
            foreach (var chatClient in clientList)
            {
                var messageReceivedBack = false;
                var syncRef = new object();
                chatClient.MessageProcessor.addProcessor(
                    "r1",
                    (source, dest, msg) =>
                        {
                            if (source == LoginPrefix + j && msg == "testMsg" + j)
                            {
                                lock (syncRef)
                                {
                                    messageReceivedBack = true;
                                }
                            }
                        });

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

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

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

            foreach (var chatClient in clientList)
            {
                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
        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();
        }