public async Task <bool> Handle(RemoveApiResourceCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var savedClient = await _apiResourceRepository.GetResource(request.Resource.Name);

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

                return(false);
            }

            _apiResourceRepository.Remove(savedClient.Id);

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

                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public async Task ShouldNotRemoveResourceWhenNameIsntProvided()
        {
            var command = new RemoveApiResourceCommand(null);

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

            result.Should().BeFalse();
            _uow.Verify(v => v.Commit(), Times.Never);
        }
 public async Task RemoveAsync(string name)
 {
     var command = new RemoveApiResourceCommand(name);
     await _bus.SendCommand(command);
 }