public async Task Execute_CorrectCommand_EnablesUserAccount() { //Arrange var usersStub = new List <AppUser> { new AppUser { Id = "6bd969d6-cec7-4383-8aa0-d59b89f77602", Email = "*****@*****.**", FullName = "Mr Test", IsDisabled = false } }; var idStub = "6bd969d6-cec7-4383-8aa0-d59b89f77602"; var userManager = MockUserManager.Build(usersStub, idStub).Object; var command = new DisableUserCommand { Id = idStub }; var handler = new DisableUserCommandHandler(_config.Object, _logger.Object, _context, userManager); //Act await handler.Handle(command); //Assert var user = await userManager.FindByIdAsync(idStub); Assert.AreEqual(user.IsDisabled.Value, true); }
public Task DisableUserByIdAsync(UserEditViewModel userEditViewModel) { var disableUserCommand = new DisableUserCommand { Id = userEditViewModel.Id }; return(_mediator.Send(disableUserCommand, default(CancellationToken))); }
public async Task Handle(UserDisabledEvent message, IMessageHandlerContext context) { using (LogContext.PushProperty("IntegrationEventContext", $"{message.Id}-{Program.AppName}")) { _logger.LogInformation("----- Handling UserDisabledEvent: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", message.Id, Program.AppName, message); var command = new DisableUserCommand { UserId = message.UserId, DisabledTime = message.DisabledTime }; await _mediator.Send(command); } }
public GenericCommandResult DisableUser( [FromBody] DisableUserCommand command, [FromServices] UserHandler handler, [FromServices] IUserRepository repository ) { var userAccout = new UserAccount(); userAccout = repository.GetUser(command.User); command.Id = userAccout.Id; return((GenericCommandResult)handler.Handle(command)); }
public ICommandResult Handle(DisableUserCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Algo deu errado!", command.Notifications)); } var user = _repository.GetUser(command.User); user.DisableUser(command.User); _repository.Update(user); return(new GenericCommandResult(true, "O usuário foi desativado!", user)); }
//[Authorize(Policy = "Desired.Add")] //TODO: Add a new profile less admin to do that public async Task <IActionResult> DisableUserAsync(int idUser) { var userLoggedInDB = await GetUserDbByIdentityAsync(HttpContext); if (userLoggedInDB == null) { return(Response()); } var cmd = new DisableUserCommand( Mapper.Map <UserViewModel, User>(userLoggedInDB), idUser); await _mediator.SendCommand(cmd); return(Response(cmd)); }
public async Task Handle(DomainEventNotification <MaxLoginAttemptsReached> notification, CancellationToken cancellationToken) { var user = notification.DomainEvent.User; _logger.LogInformation($"User {user.Name} reached max login attempts"); var currentUserId = (await _currentUserService.CurrentUser())?.Id ?? user.Id; var command = new DisableUserCommand() { DisablementTypeId = GeneralConstants.DisablementBlockedByLoginTriesId, Observation = "", ToDisableId = user.Id, DisabledById = currentUserId }; await _mediator.Send(command, cancellationToken); }
public async Task Handle(DisableUserCommand command) { try { var user = await Repository.GetByKeyAsync<Domain.Models.User>(command.UserId); user.Disable(); await Repository.SaveChangesAsync(); var @event = new UserDisabledEvent(command.UserId); EventBus.RaiseEvent(@event); } catch { throw; } }
public async Task DisableUserCommandHandler_DisableStatusExistingUser() { //Arrange var newUser = GetNewUser(); await AllMarktContextIM.Users.AddAsync(newUser); await AllMarktContextIM.SaveChangesAsync(); var existingUser = AllMarktContextIM.Users.First(); var disableUserCommand = new DisableUserCommand { Id = existingUser.Id }; //Act await _disableUserCommandHandler.Handle(disableUserCommand, CancellationToken.None); //Assert var result = AllMarktContextIM.Users.FirstOrDefault(); (result != null && result.IsEnabled).Should().BeFalse(); }
public Task <DisableUserResponse> Disable([FromRoute] DisableUserCommand query) { return(_disableUserCommandHandler.Handle(query)); }
public async Task <ActionResult <ResponseWrapper> > DisableUserAsync([FromBody] DisableUserCommand command) { var result = await _mediator.Send(command); return(Ok(ResponseWrapper.CreateOkResponseWrapper(result))); }