public void SendOneSimpleMessage() { var mock = new MockChannel("doi"); var participant = new Participant(mock); participant.Send(new Message("unu")); Assert.True(mock.CheckWriteMessage("unu\0")); }
public void LeaveParticipant() { var firstMock = new MockChannel("dan"); var secondMock = new MockChannel("mirel"); var firstParticipant = new Participant(firstMock); var secondParticipant = new Participant(secondMock); var room = new Room(); room.Join(firstParticipant); room.Join(secondParticipant); room.Leave(secondParticipant); room.Broadcast(new Message("ion")); Assert.True(firstMock.CheckWriteMessage("ion\0")); Assert.Throws <InvalidOperationException> (() => secondMock.CheckWriteMessage("ion\0")); }
public void ParticipantIsRemovedFromRoomWhenHeClosedTheConnection() { var firstMock = new MockChannel("mare\0", "nisip\0"); var secondMock = new MockChannel("doi\0"); var firstParticipant = new Participant(firstMock); var secondParticipant = new Participant(secondMock); var room = new Room(); room.Join(firstParticipant); room.Join(secondParticipant); secondParticipant.Receive(); Assert.Throws <CantReadException>(() => secondParticipant.Receive()); room.Broadcast(new Message("dan")); Assert.Throws <InvalidOperationException> (() => secondMock.CheckWriteMessage("dan\0")); Assert.True(firstMock.CheckWriteMessage("dan\0")); }
public void BroadcastMessage() { var firstMock = new MockChannel("ana"); var secondMock = new MockChannel("are"); var firstParticipant = new Participant(firstMock); var secondParticipant = new Participant(secondMock); firstParticipant.Nickname = "a"; secondParticipant.Nickname = "b"; var room = new Room(); room.Join(firstParticipant); room.Join(secondParticipant); room.Broadcast(new Message("mere")); Assert.True(firstMock.CheckWriteMessage("b has joined\0")); Assert.True(secondMock.CheckWriteMessage("mere\0")); }