예제 #1
0
        public void SendNewMessagesWhenThereAreNoNewMessagesShouldDoNothing()
        {
            MockSocketCommunication mockSocket = new MockSocketCommunication();

            ChatServerSide server = new ChatServerSide(mockSocket);

            mockSocket.SentMessages.Add("Initial message");

            string trimmedReceivedData = "userName<sep>sentMessage<sep>server: userName joined the chat.<eof>";

            mockSocket.TextToReceive = trimmedReceivedData;

            server.CheckMessage(mockSocket);

            Assert.False(server.IsNewUser("userName"));
            Assert.Equal(3, trimmedReceivedData.Split("<sep>").Length);
            Assert.True(trimmedReceivedData.IndexOf("<eof>") > -1);
            Assert.Equal("sentMessage", server.CheckMessage(mockSocket));
            Assert.False(server.IsNewUser("userName"));

            Assert.Collection(mockSocket.SentMessages,
                              item => Assert.Equal("Initial message", item),
                              item => Assert.Equal("server: userName joined the chat.<eof>", item),
                              item => Assert.Equal("userName: sentMessage<eof>", item));

            server.SendNewMessages(mockSocket, 2);

            Assert.Collection(mockSocket.SentMessages,
                              item => Assert.Equal("Initial message", item),
                              item => Assert.Equal("server: userName joined the chat.<eof>", item),
                              item => Assert.Equal("userName: sentMessage<eof>", item));
        }
예제 #2
0
        public void SendNewMessagesWhenMessageNoExistShouldThrowException()
        {
            MockSocketCommunication socket = new MockSocketCommunication();

            ChatServerSide server = new ChatServerSide(socket);

            Assert.Throws <ArgumentException>(() => server.SendNewMessages(socket, -1));
        }
예제 #3
0
        public void SendNewMessagesWhenNullSocketShouldThrowException()
        {
            ChatServerSide server = new ChatServerSide();

            Assert.Throws <ArgumentNullException>(() => server.SendNewMessages(null, 0));
        }