public void ProperlyCountsOneMessage() { var message = "Hi Counter!"; var aliceDisplay = new Mock <IReceivedMessagesHandler>(); var mediator = new ChatRoomMediator(); var alice = new ChatClient("Alice", mediator, aliceDisplay.Object); var counter = new ChatMessageCounter(mediator); alice.SendMessageThroughMediator(message); Assert.AreEqual(1, counter.Counter); }
public void ProperlyCountsMultipleMessagesFromOneSender() { var messages = Fixture.CreateMany <string>().ToList(); var aliceDisplay = new Mock <IReceivedMessagesHandler>(); var mediator = new ChatRoomMediator(); var alice = new ChatClient("Alice", mediator, aliceDisplay.Object); var counter = new ChatMessageCounter(mediator); foreach (var message in messages) { alice.SendMessageThroughMediator(message); } Assert.AreEqual(messages.Count, counter.Counter); }
public void ProperlyForwardsAndCountsMultipleMessagesFromMultipleSenders() { // Arrange var bobsMessages = Fixture.CreateMany <string>().ToList(); var aliceMessages = Fixture.CreateMany <string>().ToList(); var bobDisplay = new Mock <IReceivedMessagesHandler>(); var aliceDisplay = new Mock <IReceivedMessagesHandler>(); var mediator = new ChatRoomMediator(); var bob = new ChatClient("Bob", mediator, bobDisplay.Object); var alice = new ChatClient("Alice", mediator, aliceDisplay.Object); var counter = new ChatMessageCounter(mediator); // Act foreach (var aliceMessage in aliceMessages) { alice.SendMessageThroughMediator(aliceMessage); } foreach (var bobsMessage in bobsMessages) { bob.SendMessageThroughMediator(bobsMessage); } // Assert foreach (var aliceMessage in aliceMessages) { bobDisplay.Verify(m => m.HandleReceivedMessage("Alice", aliceMessage), Times.Once); } foreach (var bobsMessage in bobsMessages) { aliceDisplay.Verify(m => m.HandleReceivedMessage("Bob", bobsMessage), Times.Once); } Assert.AreEqual(bobsMessages.Count + aliceMessages.Count, counter.Counter); }