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());
        }
        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 IHttpActionResult UpdateUser(UserViewModel model)
        {
            User result = new User();

            using (var ravenSession = DataDocumentStore.Instance.OpenSession())
            {
                var userToUpdate = new User()
                {
                    Id = model.Id,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Email = model.Email,
                    StreetAddress = model.StreetAddress,
                    City = model.City,
                    State = model.State,
                    Zip = model.Zip
                };

                result = UserService.UpdateUser(ravenSession, userToUpdate);
            }

            if (result == null)
            {
                return BadRequest("User not found!");
            }

            return Ok(result);
        }