Exemplo n.º 1
0
        public void AddToRolesAsyncFailure()
        {
            var identityResult = IdentityResult.Failed(new IdentityError {
                Description = "User already in role 'citizen'."
            });

            var repository = Substitute.For <IIdentityRepository>();

            repository.AddToRolesAsync(Arg.Any <string>(), Arg.Any <List <string> >())
            .Returns(x => identityResult);


            var result = HandleAddRolesCommand(AddRolesCommand.Create
                                               (
                                                   string.Empty,
                                                   new List <string> {
                "citizen"
            }
                                               ), repository);


            result.Should().BeEquivalentTo(new IdentityResultDto(false, new List <string> {
                "User already in role 'citizen'."
            }));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddRoles(AddRolesViewModel addRolesViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
            }

            var result = await _mediator.Send(AddRolesCommand.Create(addRolesViewModel.Cpf, addRolesViewModel.Roles));

            if (result.Succeeded)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Exemplo n.º 3
0
        public void AddToRolesAsyncSuccess()
        {
            var identityResult = IdentityResult.Success;

            var repository = Substitute.For <IIdentityRepository>();

            repository.AddToRolesAsync(Arg.Any <string>(), Arg.Any <List <string> >())
            .Returns(x => identityResult);


            var result = HandleAddRolesCommand(AddRolesCommand.Create
                                               (
                                                   string.Empty,
                                                   new List <string> {
                "citizen"
            }
                                               ), repository);


            result.Should().BeEquivalentTo(new IdentityResultDto(true, new List <string>()));
        }