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)); }
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)); }