public void Deve_salvar_usuario_valido()
        {
            SetupSchoolingRepository(1);
            var command = new CreateUserCommand("Antonio", "Cesar", "*****@*****.**", new DateTime(1996, 10, 19), 1);

            var result = (GenericCommandResult)_createUserHandler.Handle(command);

            Assert.True(result.Success);
        }
예제 #2
0
        public void UserCreationShouldFailIfEmailAddressIsAlreadyTaken()
        {
            CreateUserRequest createUserRequest = new CreateUserRequest
            {
                Email = "*****@*****.**"
            };

            CreateUserResult createUserResult = _createUserHandler.Handle(createUserRequest);

            Assert.IsFalse(createUserResult.Succeeded);
        }
예제 #3
0
        public HttpResponseMessage Create(User user, string inviteCode) //done
        {
            var handler = new CreateUserHandler(_connectionString);

            var response = handler.Handle(new CreateUserRequest
            {
                Email          = user.Email,
                Password       = user.Password,
                Username       = user.Name,
                InvitationCode = inviteCode
            });

            var createDashRequest = new CreateDashboardRequest
            {
                DashName = "Hello_DashBoardify",
                UserId   = response.UserId
            };

            var createDashHandler = new CreateDashboardHandler(_connectionString);

            var createResponse = createDashHandler.Handle(createDashRequest);

            if (createResponse.HasErrors || response.HasErrors)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #4
0
        public async Task Should_Returns_User_When_SuccessOnCreate()
        {
            var command = new CreateUserCommand(NAME, EMAIL, PASSWORD, PHONES_COMMAND);

            _authRepository.GetUserByEmail(Arg.Any <string>()).Returns(Task.FromResult <User>(null));

            _authRepository.CreateUser(Arg.Any <User>()).Returns(new User(OBJECT_ID, NAME, EMAIL, PASSWORD, PHONES, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, TOKEN));

            var actual = await _handler.Handle(command, CancellationToken.None);

            Assert.NotNull(actual);
            Assert.True(actual.IsSuccess);
            Assert.NotNull(actual.Value.User);
            Assert.Equal(actual.Value.User.Email, EMAIL);
            Assert.Equal(actual.Value.User.Name, NAME);
            Assert.Equal(actual.Value.User.Phones.Count, PHONES.Count);
        }
예제 #5
0
        public void CreateQuizHandler_ResultNotNull()
        {
            var command = new CreateUserCommand(new User());
            var handler = new CreateUserHandler(_mock.Object);

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

            Assert.NotNull(result);
        }
예제 #6
0
        static void Main_Example(string[] args)
        {
            var logger = new ConsoleLogger();
            var sqlConnectionFactory = new SqlConnectionFactory("SQL Connection", logger);
            var createUserHandler    = new CreateUserHandler(new UserService(new QueryExecutor(sqlConnectionFactory),
                                                                             new CommandExecutor(sqlConnectionFactory), new CacheService(logger, new RestClient("API KEY"))), logger);

            createUserHandler.Handle();
        }
예제 #7
0
        public void DadoUmUsuarioJaCadastrado_IsInvalid()
        {
            var command = new CreateUserCommand("user", "1234", "1234");

            var handler = new CreateUserHandler(new FakeRepositoryUsuario());
            var result  = handler.Handle(command).Result;

            Assert.AreNotEqual(0, result.Notifications.Count);
            Assert.AreEqual(true, result.Invalid);
        }
예제 #8
0
        public async Task CreateQuizHandler_ResultTrue(string value)
        {
            var command = new CreateUserCommand(new User {
                _id = value
            });
            var handler = new CreateUserHandler(_mock.Object);

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

            Assert.AreEqual(result, true);
        }
예제 #9
0
        public async Task CreateQuizHandler_ResultFalse()
        {
            var command = new CreateUserCommand(new User {
                _id = "1"
            });
            var handler = new CreateUserHandler(_mock.Object);

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

            Assert.AreEqual(result, false);
        }
예제 #10
0
        public async Task commandhandler_create_user()
        {
            var uniqueChecker        = new Mock <IUserUniqueLoginChecker>();
            var companyUniqueChecker = new Mock <ICompanyUniqueNameChecker>();
            var repository           = new Mock <IUserRepository>();
            var handler = new CreateUserHandler(uniqueChecker.Object, repository.Object, new FakeHashService(), companyUniqueChecker.Object);
            var request = new CreateUserCommand("*****@*****.**", "veryhard4break!", "INC");

            uniqueChecker.Setup(mock => mock.IsUnique(It.IsAny <string>())).ReturnsAsync(true);
            companyUniqueChecker.Setup(mock => mock.IsUnique(It.IsAny <string>())).ReturnsAsync(true);
            await handler.Handle(request, CancellationToken.None);

            repository.Verify(mock => mock.Save(It.Is <User>(user => user.Login == request.Login && user.Password == request.Password)));
            repository.Verify(mock => mock.Save(It.Is <Company>(company => company.Name == request.CompanyName)));
        }
예제 #11
0
        public async Task WhenCommandIsHandlerThenUserShouldBeCreated()
        {
            var createUserCommand = new CreateUserCommand
            {
                Password    = "******",
                Permissions = new[]
                {
                    new UserPermission
                    {
                        Resource    = "R1",
                        AccessRight = ResourceAccessRight.Create
                    }
                },
                UserName = "******"
            };

            var createdUser = new User {
                Id = "332"
            };

            _userRepository
            .Setup(it => it.TryAddUser(It.Is <User>(user => user.UserName == createUserCommand.UserName)))
            .ReturnsAsync(createdUser);

            var result = await _sut.Handle(createUserCommand, CancellationToken.None).ConfigureAwait(false);

            result.ResultType.ShouldBe(ExecutionResultType.Ok);
            result.Value.Id.ShouldBe(createdUser.Id);

            _userRepository.Verify(it => it.TryAddUser(It.Is <User>(user =>
                                                                    user.UserName == createUserCommand.UserName &&
                                                                    user.Permissions.Length == 1 &&
                                                                    user.Permissions[0].Resource == createUserCommand.Permissions[0].Resource &&
                                                                    user.Permissions[0].AccessRight == createUserCommand.Permissions[0].AccessRight &&
                                                                    !string.IsNullOrEmpty(user.PasswordHash))));
        }
예제 #12
0
        public async Task Handle_CreateUserCommand_ReturnSuccessResult()
        {
            // Arrange
            var command = new CreateUserCommand()
            {
                DateOfBirth = DateTime.UtcNow,
                Email       = "*****@*****.**",
                FirstName   = "Vasya",
                LastName    = "Antonovich"
            };

            // Act
            var result = await _sut.Handle(command, new CancellationToken());

            // Assert
            result.Result.Should().BeTrue();
        }
예제 #13
0
        public async Task register_user_handler_should_not_be_null()
        {
            var userRepositoryMock = new Mock <IUserRepository>();
            var passwordService    = new Mock <IPasswordService>();

            passwordService.Setup(x => x.HashPassword(It.IsAny <string>())).Returns("asdasd");
            var createUserHandler = new CreateUserHandler(userRepositoryMock.Object, passwordService.Object);

            var result = await createUserHandler.Handle(new CreateUserCommand()
            {
                Email    = "asdasdasd",
                Password = "******",
                Username = "******"
            }, new CancellationToken());

            result.Should().NotBeNull();
        }
예제 #14
0
        public void DataMustBeSavedToDatabaseOnceSuccessfulPassValidation()
        {
            var fakeUserRepo  = A.Fake <IUserRepository>();
            var fakeValidator = new CreateUserValidator(fakeUserRepo);

            var testMessage = new CreateUserMessage
            {
                Username = "******",
                Password = "******",
                Role     = UserRole.Admin
            };
            var handler = new CreateUserHandler(fakeUserRepo, fakeValidator);

            handler.Handle(testMessage);

            A.CallTo(() => fakeUserRepo.Create(testMessage)).MustHaveHappened();
        }
예제 #15
0
        public void Should_throw_validation_exception_when_validation_fails()
        {
            var command = new CreateUser
            {
                Id       = Guid.NewGuid(),
                Email    = "*****@*****.**",
                UserName = "******"
            };

            var userRepositoryMock = new Mock <IUserRepository>();

            var validatorMock = new Mock <IValidator <CreateUser> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> {
                new ValidationFailure("Id", "Id Error")
            }));

            var createUserHandler = new CreateUserHandler(userRepositoryMock.Object, validatorMock.Object);

            Assert.Throws <ValidationException>(() => createUserHandler.Handle(command));
        }
예제 #16
0
        public void Should_validate_command_and_save_new_user()
        {
            var command = new CreateUser
            {
                Id       = Guid.NewGuid(),
                Email    = "*****@*****.**",
                UserName = "******"
            };

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.Create(It.IsAny <User>()));

            var validatorMock = new Mock <IValidator <CreateUser> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var createUserHandler = new CreateUserHandler(userRepositoryMock.Object, validatorMock.Object);

            createUserHandler.Handle(command);

            validatorMock.Verify(x => x.Validate(command));
            userRepositoryMock.Verify(x => x.Create(It.IsAny <User>()));
        }
        public async Task <ResponseCommand> Create([FromBody] CreateUserCommand command)
        {
            var result = await _createUserHandler.Handle(command);

            return(result);
        }
예제 #18
0
 public async Task <IActionResult> Create(UserCommand command)
 {
     return(DataResult(await _createUserHandler.Handle(command)));
 }
예제 #19
0
 public CreateUserResult CreateUser(CreateUserRequest createUserRequest)
 {
     return(_createUserHandler.Handle(createUserRequest));
 }
예제 #20
0
        public static void Operation()
        {
            var user = CreateUserHandler.Handle();

            UserInfoMenu.Display(user);
        }