Esempio n. 1
0
        public async Task <ActionResult> UpdateUsernameAsync(UsernameUpdateVm data)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            await _userService.UpdateUsernameAsync(data, userId);

            Log.Information("User {userId} updated username {@data}", userId, data);
            return(Ok());
        }
        public async Task ShouldUpdateUserName()
        {
            UserService    userService    = new UserService(_dbContext, _userManager, _mainEventProvider, _securityService);
            UserController userController = new UserController(userService, _securityService);

            SetUser(userController, _createdUser2.Entity.Id);

            UsernameUpdateVm userForUpdate = new UsernameUpdateVm
            {
                Username = "******"
            };

            await userController.UpdateUsernameAsync(userForUpdate);

            ApplicationUser updatedUser = _dbContext.Users.Find(_createdUser2.Entity.Id);

            Assert.AreEqual(userForUpdate.Username, updatedUser.UserName);
        }
        public void ShouldNotUpdateUserNameIfNotFound()
        {
            UserService    userService    = new UserService(_dbContext, _userManager, _mainEventProvider, _securityService);
            UserController userController = new UserController(userService, _securityService);

            SetUser(userController, "123456");

            UsernameUpdateVm userForUpdate = new UsernameUpdateVm
            {
                Username = "******"
            };

            var ex = Assert.ThrowsAsync <HttpException>(async() =>
            {
                await userController.UpdateUsernameAsync(userForUpdate);
            });

            Assert.AreEqual("Fant ingen bruker med denne ID'en", ex.Message);
        }