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)); }
public void SendNewMessagesWhenMessageNoExistShouldThrowException() { MockSocketCommunication socket = new MockSocketCommunication(); ChatServerSide server = new ChatServerSide(socket); Assert.Throws <ArgumentException>(() => server.SendNewMessages(socket, -1)); }
public void SendNewMessagesWhenNullSocketShouldThrowException() { ChatServerSide server = new ChatServerSide(); Assert.Throws <ArgumentNullException>(() => server.SendNewMessages(null, 0)); }