public async Task <Guid> AddRole(AddRoleCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            command.EnsureIsValid();

            var persistedRole = await authorizationRepository.GetRoleByName(command.Name, cancellationToken).ConfigureAwait(false);

            if (persistedRole is not null)
            {
                throw new BusinessException(Messages.RoleAlreadyExist);
            }

            var role = new Role()
            {
                Name        = command.Name,
                Description = command.Description
            };

            await authorizationRepository.AddRole(role, cancellationToken).ConfigureAwait(false);

            return(role.Id);
        }
        public async Task AddRole_Throw_Exception_If_Role_Already_Exist()
        {
            var expectedRole = new Role()
            {
                Name = "Admin", Description = "Allow Admin users"
            };

            var command = new AddRoleCommand("Admin", "Allow Admin users", null);

            authorizationRepositoryMock.GetRoleByName(command.Name, Arg.Any <CancellationToken>())
            .Returns(expectedRole);

            Assert.ThrowsAsync <BusinessException>(async() =>
                                                   await authorizationAppService.AddRole(command, CancellationToken.None), "Role already exist.");

            await authorizationRepositoryMock.Received(1).GetRoleByName(command.Name, Arg.Any <CancellationToken>());
        }