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

            chatRoomManagerMock.Setup(manager => manager.AddMessageToChatRoom(It.IsAny <long>(), It.IsAny <Message>())).Throws(new KeyNotFoundException());
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);
            long    chatRoomId         = 1;
            Message message            = new Message("Carla Red", "Hello World");
            int     expectedStatusCode = 404;
            int     expectedErrorCount = 0;

            // Act
            SimulateValidation(message, chatRoomController);
            var result = chatRoomController.AddMessageToChatRoom(chatRoomId, message);

            // Assert
            Assert.IsNotNull(result);
            StatusCodeResult statusCodeResult = (StatusCodeResult)result;

            Assert.AreEqual(expectedStatusCode, statusCodeResult.StatusCode);

            var modelState = chatRoomController.ModelState;

            Assert.AreEqual(expectedErrorCount, modelState.ErrorCount);
        }
Beispiel #2
0
        public void AddMessageToChatRoomReturnsStatusCodeResult()
        {
            // Arrange
            var chatRoomManagerMock = new Mock <IChatRoomManager>(MockBehavior.Strict);

            chatRoomManagerMock.Setup(manager => manager.AddMessageToChatRoom(It.IsAny <long>(), It.IsAny <Message>()));
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);
            long    chatRoomId = 1;
            Message message    = new Message("Carla Red", "Hello World");
            // Act
            var result = chatRoomController.AddMessageToChatRoom(chatRoomId, message);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
        }