public void ShouldReturnSuccessWhenChannelIdAndAdministratorIdIsValid()
        {
            var command = new DeleteChannelCommand
            {
                ChannelId       = Guid.NewGuid(),
                AdministratorId = Guid.NewGuid()
            };

            command.Validate();

            command.Valid.Should().BeTrue();
        }
        public void ShouldReturnErrorWhenChannelIdAndAdministratorIdIsEmpty()
        {
            var command = new DeleteChannelCommand
            {
                ChannelId       = Guid.Empty,
                AdministratorId = Guid.Empty
            };

            command.Validate();

            command.Invalid.Should().BeTrue();
        }
        public async Task <ICommandResult> HandleAsync(DeleteChannelCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Could not delete this channel", Errors));
            }
            GetChannelByIdQueryResult channel = await _channelRepository.GetById(command.ChannelId);

            if (channel is null)
            {
                AddNotification(nameof(command.ChannelId), "Channel not found");
                return(new CommandResult(false, "Could not delete this channel", Errors));
            }
            if (channel.AdministratorId != command.AdministratorId)
            {
                AddNotification(nameof(command.AdministratorId), "AdministratorId does't match channel administrator id");
                return(new CommandResult(false, "User does't have permission to delete this channel", Errors));
            }
            await _channelRepository.DeleteChannel(channel.Id);

            return(new CommandResult(true, "Channel successfully deleted", null, null));
        }