Ejemplo n.º 1
0
        public void AddChatRoomWithNameEmptyReturnsStatusCode400()
        {
            // Arrange
            var chatRoomManagerMock = new Mock <IChatRoomManager>(MockBehavior.Strict);

            chatRoomManagerMock.Setup(manager => manager.AddChatRoom(It.IsAny <ChatRoom>())).Returns(1);
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);

            ChatRoom chatRoom           = new ChatRoom("");
            int      expectedStatusCode = 400;
            int      expectedErrorCount = 1;

            // Act
            SimulateValidation(chatRoom, chatRoomController);
            var result = chatRoomController.AddChatRoom(chatRoom);

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

            Assert.AreEqual(expectedStatusCode, statusCodeResult.StatusCode);

            var modelState = chatRoomController.ModelState;

            Assert.AreEqual(expectedErrorCount, modelState.ErrorCount);
            Assert.AreEqual(modelState.First().Key, "Name");
        }
Ejemplo n.º 2
0
        public void PostWithValidChatRoomCallsChatRoomManager()
        {
            // Arrange
            var chatRoomManagerMock = new Mock <IChatRoomManager>(MockBehavior.Strict);

            chatRoomManagerMock.Setup(manager => manager.AddChatRoom(It.IsAny <ChatRoom>())).Returns(1);
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);

            ChatRoom chatRoom = new ChatRoom("Room");

            // Act
            SimulateValidation(chatRoom, chatRoomController);
            chatRoomController.AddChatRoom(chatRoom);

            // Assert
            chatRoomManagerMock.Verify(manager => manager.AddChatRoom(It.IsAny <ChatRoom>()), Times.Once);
        }
Ejemplo n.º 3
0
        public void AddChatRoomReturnsStatusCodeResult()
        {
            // Arrange
            var chatRoomManagerMock = new Mock <IChatRoomManager>(MockBehavior.Strict);

            chatRoomManagerMock.Setup(manager => manager.AddChatRoom(It.IsAny <ChatRoom>())).Returns(1);
            ChatRoomController chatRoomController = new ChatRoomController(chatRoomManagerMock.Object);

            ChatRoom chatRoom = new ChatRoom("Room");

            // Act
            SimulateValidation(chatRoom, chatRoomController);
            var result = chatRoomController.AddChatRoom(chatRoom);

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