Beispiel #1
0
        public void Attach_DoesNotThrow()
        {
            var messageBoard = new MessageBoard();
            var observerMock = new Mock <IMessageBoardObserver>();

            Assert.DoesNotThrow(() => messageBoard.Attach(observerMock.Object));
        }
Beispiel #2
0
        public void Attach_NullObserver_ArgumentNullException()
        {
            var messageBoard = new MessageBoard();
            var ex           = Assert.Throws <ArgumentNullException>(() => messageBoard.Attach(null));

            Assert.That(ex.ParamName, Is.EqualTo(AttachObserverParam));
        }
Beispiel #3
0
        public void AddMessage_ObserversNotified()
        {
            const string message      = "Room for rent.";
            var          messageBoard = new MessageBoard();
            var          observerMock = new Mock <IMessageBoardObserver>();

            messageBoard.Attach(observerMock.Object);

            messageBoard.AddMessage(message);

            observerMock.Verify(
                o => o.Update(It.Is <IEnumerable <string> >(e => e.Single() == message)), Times.Once);
        }
Beispiel #4
0
        public void RemoveMessage_Nonexistent_ObserversNotNotified()
        {
            const string message      = "Have you seen this man?";
            var          messageBoard = new MessageBoard();
            var          observerMock = new Mock <IMessageBoardObserver>();

            messageBoard.Attach(observerMock.Object);

            messageBoard.RemoveMessage(message);

            observerMock.Verify(
                o => o.Update(It.IsAny <IEnumerable <string> >()), Times.Never);
        }
Beispiel #5
0
        public void AddMessage_Duplicate_ObserversNotNotified()
        {
            const string message      = "Looking for car share.";
            var          messageBoard = new MessageBoard();
            var          observerMock = new Mock <IMessageBoardObserver>();

            messageBoard.AddMessage(message);
            messageBoard.Attach(observerMock.Object);

            messageBoard.AddMessage(message);

            observerMock.Verify(
                o => o.Update(It.IsAny <IEnumerable <string> >()), Times.Never);
        }
Beispiel #6
0
        public void RemoveMessage_ObserversNotified()
        {
            const string message1     = "Cat for sale.";
            const string message2     = "Dog for sale.";
            var          messageBoard = new MessageBoard();
            var          observerMock = new Mock <IMessageBoardObserver>();

            messageBoard.AddMessage(message1);
            messageBoard.AddMessage(message2);
            messageBoard.Attach(observerMock.Object);

            messageBoard.RemoveMessage(message1);

            observerMock.Verify(
                o => o.Update(It.Is <IEnumerable <string> >(e => e.Single() == message2)), Times.Once);
        }