예제 #1
0
        public void GetChatRoomByIdWithInvalidIdReturnsNotFoundResult()
        {
            // Arrange
            var chatRoomManagerMock = new Mock <IChatRoomManager>(MockBehavior.Strict);

            chatRoomManagerMock.Setup(manager => manager.FindChatRoomById(It.IsAny <long>())).Throws(new KeyNotFoundException());
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);
            long chatRoomId = 1;
            // Act
            var result = chatRoomController.GetChatRoomById(chatRoomId);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
예제 #2
0
        public void GetChatRoomByIdWithValidIdReturnsObjectResult()
        {
            // Arrange
            var chatRoomManagerMock = new Mock <IChatRoomManager>(MockBehavior.Strict);

            chatRoomManagerMock.Setup(manager => manager.FindChatRoomById(It.IsAny <long>())).Returns(new ChatRoom());
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);
            long chatRoomId = 1;
            // Act
            var result = chatRoomController.GetChatRoomById(chatRoomId);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ObjectResult));
            ObjectResult objectResult = (ObjectResult)result;

            Assert.IsInstanceOfType(objectResult.Value, typeof(ChatRoom));
        }