コード例 #1
0
        public void DeleteUser()
        {
            // Arrange
            DBSetup();

            Mock<IUserService> userService = new Mock<IUserService>();
            userService.Setup(x => x.DeleteUser(It.IsAny<IDocumentSession>(), It.IsAny<string>())).Returns("users/1");

            UserApiController controller = new UserApiController(userService.Object);

            // Act
            IHttpActionResult result = controller.DeleteUser("1");

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(OkResult), result.GetType());
        }
コード例 #2
0
        public void DeleteUserFail()
        {
            // Arrange
            DBSetup();

            Mock<IUserService> userService = new Mock<IUserService>();
            userService.Setup(x => x.UpdateUser(It.IsAny<IDocumentSession>(), It.IsAny<User>())).Returns<User>(null);

            UserApiController controller = new UserApiController(userService.Object);

            // Act
            IHttpActionResult result = controller.DeleteUser("1");

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(BadRequestErrorMessageResult), result.GetType());
            Assert.AreEqual((result as BadRequestErrorMessageResult).Message, "User not found!");
        }