예제 #1
0
        public void AddMessageToChatRoomAddsMessage()
        {
            // Arrange
            ChatRoom parameter = null;
            var      chatRoomRepositoryMock = new Mock <IRepository <ChatRoom, long> >(MockBehavior.Strict);

            chatRoomRepositoryMock.Setup(repository => repository.FindByIdWithMessages(It.IsAny <long>())).Returns(new List <ChatRoom>()
            {
                new ChatRoom("room")
            });
            chatRoomRepositoryMock.Setup(repository => repository.Exists(It.IsAny <long>())).Returns(true);
            chatRoomRepositoryMock.Setup(repository => repository.Update(It.IsAny <ChatRoom>()))
            .Callback <ChatRoom>((chatRoom) => parameter = chatRoom);
            ChatRoomManager chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object);
            long            chatRoomId      = 1;
            Message         message         = new Message("Carla Red", "Hello World");

            // Act Assert
            chatRoomManager.AddMessageToChatRoom(chatRoomId, message);

            // Assert
            Assert.AreEqual(1, parameter.Messages.Count);
            Assert.AreEqual("Carla Red", parameter.Messages[0].Sender);
            Assert.AreEqual("Hello World", parameter.Messages[0].Content);
            Assert.AreEqual("room", parameter.Name);
        }
예제 #2
0
        public void AddMessageToChatRoomWithInvalidIdThrowsKeyNotFoundException()
        {
            // Arrange
            var chatRoomRepositoryMock = new Mock <IRepository <ChatRoom, long> >(MockBehavior.Strict);

            chatRoomRepositoryMock.Setup(repository => repository.FindByIdWithMessages(It.IsAny <long>())).Returns(new List <ChatRoom>()
            {
                new ChatRoom("room")
            });
            chatRoomRepositoryMock.Setup(repository => repository.Exists(It.IsAny <long>())).Returns(false);
            chatRoomRepositoryMock.Setup(repository => repository.Update(It.IsAny <ChatRoom>()));
            ChatRoomManager chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object);
            long            chatRoomId      = 1;
            Message         message         = new Message("Carla Red", "Hello World");

            // Act Assert
            Assert.ThrowsException <KeyNotFoundException>(() => chatRoomManager.AddMessageToChatRoom(chatRoomId, message));
        }
예제 #3
0
        public void AddMessageToChatRoomCallsRepository()
        {
            // Arrange
            var chatRoomRepositoryMock = new Mock <IRepository <ChatRoom, long> >(MockBehavior.Strict);

            chatRoomRepositoryMock.Setup(repository => repository.FindByIdWithMessages(It.IsAny <long>())).Returns(new List <ChatRoom>()
            {
                new ChatRoom("room")
            });
            chatRoomRepositoryMock.Setup(repository => repository.Exists(It.IsAny <long>())).Returns(true);
            chatRoomRepositoryMock.Setup(repository => repository.Update(It.IsAny <ChatRoom>()));
            ChatRoomManager chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object);
            long            chatRoomId      = 1;
            Message         message         = new Message("Carla Red", "Hello World");

            // Act
            chatRoomManager.AddMessageToChatRoom(chatRoomId, message);

            // Assert
            chatRoomRepositoryMock.Verify(repository => repository.Update(It.IsAny <ChatRoom>()), Times.Once);
        }