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'." })); }
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)); }
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>())); }