Beispiel #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'."
            }));
        }
Beispiel #2
0
 private void NewUser_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     StartCreateNewCommand.RaiseCanExecuteChanged();
     AddRoleCommand.RaiseCanExecuteChanged();
     RemoveRoleCommand.RaiseCanExecuteChanged();
     AddRolesCommand.RaiseCanExecuteChanged();
     RemoveRolesCommand.RaiseCanExecuteChanged();
     AddMultipleRolesCommand.RaiseCanExecuteChanged();
 }
Beispiel #3
0
        private IdentityResultDto HandleAddRolesCommand(AddRolesCommand command, IIdentityRepository repository)
        {
            var provider = DependencyInjectorMock.Get((s, c) =>
            {
                BootStrapper.RegisterServices(s, c);
                s.AddScoped((x) => repository);
                s.AddLogging();
            });

            var handler = provider.GetRequiredService <IRequestHandler <AddRolesCommand, IdentityResultDto> >();

            return(handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult());
        }
Beispiel #4
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));
        }
Beispiel #5
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>()));
        }