Example #1
0
        public async Task <bool> Handle(RemoveIdentityResourceCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var savedClient = await _identityResourceRepository.GetByName(request.Resource.Name);

            if (savedClient == null)
            {
                await Bus.RaiseEvent(new DomainNotification("1", "Resource not found"));

                return(false);
            }

            _identityResourceRepository.Remove(savedClient.Id);

            if (Commit())
            {
                await Bus.RaiseEvent(new IdentityResourceRemovedEvent(request.Resource.Name));

                return(true);
            }
            return(false);
        }
Example #2
0
        public async Task ShouldNotRemoveResourceWhenNameIsntProvided()
        {
            var command = new RemoveIdentityResourceCommand(null);

            var result = await _commandHandler.Handle(command, _tokenSource.Token);

            result.Should().BeFalse();
            _uow.Verify(v => v.Commit(), Times.Never);
        }
Example #3
0
        public async Task <bool> Handle(RemoveIdentityResourceCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var resource = await _identityResourceRepository.FirstOrDefaultAsync(r => r.Name == request.IdentityResource.Name);

            if (resource != null)
            {
                await _identityResourceRepository.RemoveAsync(resource);

                if (Commit())
                {
                    await _bus.RaiseEvent(new IdentityResourceRemovedEvent(resource.Id));

                    return(true);
                }
            }
            return(false);
        }
 public async Task RemoveAsync(string name)
 {
     var command = new RemoveIdentityResourceCommand(name);
     await _bus.SendCommand(command);
 }