예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }