Exemple #1
0
        public async Task DeleteUserAsync_RequestIsNull_ThrowArgumentNullException()
        {
            // Arrange
            DeleteUserRequest request = null;

            // Act + Assert
            ArgumentNullException exception =
                await Assert.ThrowsAsync <ArgumentNullException>(() => _identityService.DeleteUserAsync(request))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.Equal(string.Format(ErrorMessages.NullExceptionMessage, "request"), exception.Message);
        }
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                await _identityService.DeleteUserAsync(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(RedirectToAction(nameof(Index)));
            }
        }
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                var entity = _service.Members.Id(id).FirstOrDefault();
                if (entity == null)
                {
                    return(NotFound(AppResult.NotFound()));
                }
                var validationData = _service.ValidateDeleteMember(User, entity);
                if (!validationData.IsValid)
                {
                    return(BadRequest(AppResult.FailValidation(data: validationData)));
                }
                using (var trans = context.Database.BeginTransaction())
                {
                    var user = entity.User;
                    _service.DeleteMemberTransaction(entity);
                    var result = await _identityService.DeleteUserAsync(user);

                    if (!result.Succeeded)
                    {
                        foreach (var err in result.Errors)
                        {
                            ModelState.AddModelError(err.Code, err.Description);
                        }
                        var builder = ResultHelper.MakeInvalidAccountRegistrationResults(ModelState);
                        return(BadRequest(builder));
                    }
                    //log event
                    var ev = _sysService.GetEventForDeleteMember(
                        $"Admin has remove a user with email {entity.Email}",
                        UserId);
                    _sysService.CreateAppEvent(ev);
                    //end log event
                    context.SaveChanges();
                    trans.Commit();
                }
                return(NoContent());
            }
            catch (DbUpdateException e)
            {
                _logger.Error(e);
                return(BadRequest(AppResult.FailValidation(data: new ValidationData()
                                                           .Fail(code: AppResultCode.DependencyDeleteFail))));
            }
        }
Exemple #4
0
        public async Task DeleteUserAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var testUserManager = GetTestUserManager(context);
                var testRoleManager = GetTestRoleManager(context);

                IIdentityRepository identityRepository = new IdentityRepository(context, testUserManager, testRoleManager);
                var localizerIdentityResource          = new IdentityServiceResources();

                IIdentityService identityService = new IdentityService(identityRepository, localizerIdentityResource);

                //Generate random new user
                var userDto = IdentityDtoMock.GenerateRandomUser(Guid.NewGuid());

                await identityService.CreateUserAsync(userDto);

                //Get new user
                var user = await context.Users.Where(x => x.UserName == userDto.UserName).SingleOrDefaultAsync();

                userDto.Id = user.Id;

                var newUserDto = await identityService.GetUserAsync(userDto);

                //Assert new user
                userDto.Should().BeEquivalentTo(newUserDto);

                //Remove user
                await identityService.DeleteUserAsync(newUserDto);

                //Try Get Removed user
                var removeUser = await context.Users.Where(x => x.Id == user.Id)
                                 .SingleOrDefaultAsync();

                //Assert removed user
                removeUser.Should().BeNull();
            }
        }
 public async Task Delete(string userId)
 {
     await _identityService.DeleteUserAsync(userId);
 }