public void UpdateUserInfo_NullUserManager()
        {
            Guid         apiToken = new Guid("d2ab6d8a-d8b3-42a6-9dd4-a36a8a9b1f79");
            const string password = "******";

            //arrange
            var userUpdateModel = new UserUpdateModel();

            _userManager.Setup(x => x.GetUserByApiToken(apiToken)).Returns(default(User));

            //act / assert
            var ex = Assert.Throws <UserNotFoundException>(() => _webPageHelper.UpdateUserInfo(apiToken, password, userUpdateModel));

            AssertWithMessage.AreEqual(ex.Message, $"User could not be found where API token is {apiToken}", "exception message");
        }
示例#2
0
        public IActionResult Put(string apiToken, string password, [FromBody] UserUpdateModel userUpdateModel)
        {
            try
            {
                ValidateModel(userUpdateModel);

                if (!Guid.TryParse(apiToken, out Guid apiTokenGuid))
                {
                    string msg = $"Could not parse API token passed in into a GUID.  API token: {apiToken}";
                    _logger.Error(msg);
                    return(StatusCode((int)HttpStatusCode.BadRequest, msg));
                }

                var result = _webPageHelper.UpdateUserInfo(apiTokenGuid, password, userUpdateModel);

                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.Error($"Unhandled exception occurred when attempting to update user data", ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }