public void UpdateUserFail() { // 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 var userViewModel = new UserViewModel() { Id = "users/1", FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "ChangeTestSA", City = "TestCity", State = "TestState", Zip = "99999" }; IHttpActionResult result = controller.UpdateUser(userViewModel); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(BadRequestErrorMessageResult), result.GetType()); Assert.AreEqual((result as BadRequestErrorMessageResult).Message, "User not found!"); }
public void UpdateUser() { // Arrange DBSetup(); var userModel = new User() { Id = "users/1", FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "ChangeTestSA", City = "TestCity", State = "TestState", Zip = "99999" }; Mock<IUserService> userService = new Mock<IUserService>(); userService.Setup(x => x.UpdateUser(It.IsAny<IDocumentSession>(), It.IsAny<User>())).Returns(userModel); UserApiController controller = new UserApiController(userService.Object); // Act var userViewModel = new UserViewModel() { Id = "users/1", FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "ChangeTestSA", City = "TestCity", State = "TestState", Zip = "99999" }; IHttpActionResult result = controller.UpdateUser(userViewModel); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(OkNegotiatedContentResult<User>), result.GetType()); }