Exemplo n.º 1
0
        public async Task <IActionResult> CreateAsync(UserDto model)
        {
            var updCommand = new CreateUser.Command(model);
            var res        = await _mediator.Send(updCommand);

            return(Ok(res));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create()
        {
            var command = new CreateUser.Command();

            await PrepareViewModelAsync(command);

            return(View(command));
        }
Exemplo n.º 3
0
        public void WhenMapping()
        {
            _mapper = new MapperConfiguration(x => x.AddProfile <CreateUserCommandToUserProfile>()).CreateMapper();

            _request = new Fixture().Create <CreateUser.Command>();

            _result = _mapper.Map <User>(_request);
        }
        public async Task Should_commit_UserCreated_to_Outbox_when_Handler_is_called(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock)
        {
            var handler = new CreateUser.Handler(outboxMock.Object, _db);

            await handler.Handle(command, CancellationToken.None);

            outboxMock.Verify(x => x.Commit(It.IsAny <UserCreated>()), Times.Once);
        }
        public async Task Should_not_return_empty_guid_when_User_is_created(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock)
        {
            var handler = new CreateUser.Handler(outboxMock.Object, _db);

            var result = await handler.Handle(command, CancellationToken.None);

            var actualId = result.Id;

            actualId.Should().NotBe(Guid.Empty);
        }
        public async Task Should_commit_same_Id_to_Outbox_when_Handler_is_called(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock)
        {
            var handler = new CreateUser.Handler(outboxMock.Object, _db);

            var result = await handler.Handle(command, CancellationToken.None);

            var expectedId = result.Id;

            outboxMock.Verify(x => x.Commit(It.Is <UserCreated>(user => user.UserId == expectedId)));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> RegisterGuest(CreateUserRequest model)
        {
            model.RoleId = RoleConstants.Guest;
            var command = new CreateUser.Command {
                CreateUserRequest = model
            };

            return(await ExecuteCommand(command)
                   .ConfigureAwait(false));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> CreateSuperAdminUser(CreateUserRequest model)
        {
            model.RoleId = RoleConstants.Superadmin;
            var command = new CreateUser.Command {
                CreateUserRequest = model
            };

            return(await ExecuteCommand(command)
                   .ConfigureAwait(false));
        }
Exemplo n.º 9
0
        public async Task <ActionResult <CreateUser.Result> > CreateUser([FromBody] CreateUser.Command user)
        {
            var result = await _commandBus.Send(new CreateUser.Command
            {
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName
            });

            return(CreatedAtAction(nameof(GetUser), new { id = result.Id }));
        }
        public async Task Should_insert_User_in_db_when_Handler_is_called(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock)
        {
            var expectedUserCount = _db.Users.Count() + 1;
            var handler           = new CreateUser.Handler(outboxMock.Object, _db);

            await handler.Handle(command, CancellationToken.None);

            var actualUserCount = _db.Users.Count();

            actualUserCount.Should().Be(expectedUserCount);
        }
Exemplo n.º 11
0
        public async Task <ActionResult> Create(CreateUser.Command command)
        {
            if (ModelState.IsValid)
            {
                await _mediator.Send(command);

                return(RedirectToAction(nameof(Index)));
            }
            await PrepareViewModelAsync(command);

            return(View(command));
        }
Exemplo n.º 12
0
        public async Task WhenCreateUserCommandDispatched()
        {
            _request = new Fixture().Create <CreateUser.Command>();

            var database = Substitute.For <IMongoDatabase>();

            _collection = Substitute.For <IMongoCollection <CreateUser.Command> >();
            database.GetCollection <CreateUser.Command>("users").Returns(_collection);

            var mediator = Substitute.For <IMediator>();

            mediator.Send(Arg.Is <FindBankDetailsByAccountNumber.Query>(x => x.AccountNumber == _request.BankDetails.AccountNumber), CancellationToken.None).Returns(Maybe <BankDetails> .Some(new BankDetails()));

            var handler = new CreateUser(database, mediator, null);

            _result = await handler.Handle(_request, CancellationToken.None);
        }
Exemplo n.º 13
0
        public async void Should_create_new_user()
        {
            var databaseOptions = SetupInMemoryDatabase(out var connection);

            try
            {
                connection.Open();

                // Cria o esquema no banco de dados
                SeedInMemoryDatabase(databaseOptions);

                var command = new CreateUser.Command
                {
                    Username = "******",
                    Password = "******",
                    Name     = "Client Name"
                };

                CommandResponse response;

                // Comando em teste
                using (var context = new DatabaseContext(databaseOptions))
                {
                    response = await new CreateUser.Handler(context, null).Handle(command, default);
                }

                // Verifica
                response.IsValid.ShouldBeTrue();

                using (var context = new DatabaseContext(databaseOptions))
                {
                    var createdEntity = await context.Users
                                        .FirstOrDefaultAsync(x => EF.Functions.Like(x.Username, command.Username));

                    createdEntity.ShouldNotBeNull();
                    createdEntity.Username.ShouldBe(command.Username);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task WhenCreatingUser()
        {
            var cancellationToken = new CancellationToken();
            var request           = new CreateUserRequest();
            var command           = new CreateUser.Command();

            _errorMessage = "error!";

            var mapper = Substitute.For <IMapper>();

            mapper.Map <CreateUser.Command>(request).Returns(command);

            var mediator = Substitute.For <IMediator>();

            mediator.Send(command, cancellationToken).Returns(CommandResult.Fail(_errorMessage));

            var controller = new UsersController(mediator, mapper);

            _result = await controller.Create(request, cancellationToken) as BadRequestObjectResult;
        }
Exemplo n.º 15
0
        public async Task WhenCreatingUser()
        {
            var cancellationToken = new CancellationToken();
            var request           = new CreateUserRequest();

            _expectedId = Guid.NewGuid();
            var command = new CreateUser.Command
            {
                Id = _expectedId
            };

            var mapper = Substitute.For <IMapper>();

            mapper.Map <CreateUser.Command>(request).Returns(command);

            var mediator = Substitute.For <IMediator>();

            mediator.Send(command, cancellationToken).Returns(CommandResult.Success);

            var controller = new UsersController(mediator, mapper);

            _result = await controller.Create(request, cancellationToken) as CreatedResult;
        }
Exemplo n.º 16
0
 public async Task <ActionResult> Create(CreateUser.Command data)
 {
     return(HttpResponse(await Mediator.Send(data)));
 }
Exemplo n.º 17
0
 public async Task <ActionResult <Unit> > Create(CreateUser.Command command)
 {
     return(await _mediator.Send(command));
 }
Exemplo n.º 18
0
        public void Should_throw_ValidationException_When_Email_is_invalid(string email, CreateUser.Command command)
        {
            command.Email = email;

            Func <Task> act = async() => await _mediator.Send(command);

            act.Should().Throw <ValidationException>();
        }
Exemplo n.º 19
0
        public void Should_throw_ValidationException_When_LastName_is_empty(string lastName, CreateUser.Command command, MailAddress mailAddress)
        {
            command.LastName = lastName;
            command.Email    = mailAddress.Address;

            Func <Task> act = async() => await _mediator.Send(command);

            act.Should().Throw <ValidationException>();
        }
        public async Task Should_save_User_with_requested_properties_to_db_when_saving_User(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock)
        {
            var handler = new CreateUser.Handler(outboxMock.Object, _db);

            var result = await handler.Handle(command, CancellationToken.None);

            var actualUser = _db.Users.Select(u => new CreateUser.Command
            {
                FirstName = u.FirstName,
                LastName  = u.LastName,
                Email     = u.Email
            }).First();

            actualUser.Should().BeEquivalentTo(command);
        }
Exemplo n.º 21
0
        public async Task <string> CreateAsync([FromBody] CreateUser.Command command)
        {
            var response = await _mediator.Send(command);

            return(response);
        }
Exemplo n.º 22
0
 public async Task <string> Post([FromBody] CreateUser.Command command) => await Task.FromResult(_mediator.Send(command).ToString());
 public async Task <IActionResult> CreateUser([FromBody] CreateUser.Command command)
 {
     command.UrlHelper = new UrlHelper(Url.ActionContext);
     return(Ok(await _mediator.Send(command)));
 }
        public async Task <IActionResult> CreateRole([FromBody] CreateUser.Command command)
        {
            IdentityResult result = await _roleManager.CreateAsync(new IdentityRole("user"));

            return(Ok());
        }
Exemplo n.º 25
0
        private async Task PrepareViewModelAsync(CreateUser.Command command)
        {
            var roles = await _mediator.Send(new GetAllRoles.Query());

            command.AllRoles = roles;
        }
        public async Task <IActionResult> CreateUser([FromBody] CreateUser.Command user)
        {
            var result = await _mediator.Send(user);

            return(Ok(result));
        }