public async Task <IActionResult> UpdateAccountManager(AccountManagerOutputViewModel accountManager)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(accountManager));
            }

            await this.administratorService.UpdateAccountManagerAsync(accountManager);

            return(this.RedirectToAction(nameof(this.Index)));
        }
        public async Task UpdateAccountManagerAsyncShouldCallUserManagerUpdate()
        {
            var managerToUpdate = new AccountManagerOutputViewModel
            {
                UserId   = "1",
                Username = "******",
                Email    = "[email protected]",
            };

            var result = await this.administratorService.UpdateAccountManagerAsync(managerToUpdate);

            this.userManager.Verify(u => u.UpdateAsync(It.IsAny <ApplicationUser>()), Times.Once);
        }
        public async Task UpdateAccountManagerAsyncReturnsFalseWithInCorrectData()
        {
            var managerToUpdate = new AccountManagerOutputViewModel
            {
                UserId   = "-1",
                Username = "******",
                Email    = "[email protected]",
            };

            var result = await this.administratorService.UpdateAccountManagerAsync(managerToUpdate);

            Assert.IsFalse(result);
        }
        public async Task <bool> UpdateAccountManagerAsync(AccountManagerOutputViewModel accountManager)
        {
            var user = await this.userRepository.GetByIdWithDeletedAsync(accountManager.UserId);

            if (user == null)
            {
                return(false);
            }

            user.Email    = accountManager.Email;
            user.UserName = accountManager.Username;

            var result = await this.userManager.UpdateAsync(user);

            return(result.Succeeded);
        }
        public async Task UpdateAccountManagerAsyncUpdatesCorrectlyWithCorrectData()
        {
            var managerToUpdate = new AccountManagerOutputViewModel
            {
                UserId   = "1",
                Username = "******",
                Email    = "[email protected]",
            };

            var result = await this.administratorService.UpdateAccountManagerAsync(managerToUpdate);

            var updatedManager = this.userRepository
                                 .All()
                                 .FirstOrDefault(u => u.Id == "1");

            Assert.AreEqual(managerToUpdate.Username, updatedManager?.UserName);
            Assert.AreEqual(managerToUpdate.Email, updatedManager?.Email);
        }