コード例 #1
0
        public RegisterConsultantValidatorsTest()
        {
            var command  = RegisterConsultantCommandFactory.ValidRegisterConsultantCommandWithExistingEmail();
            var mockRepo = new Mock <IConsultantRepository>();

            mockRepo.Setup(db => db.CheckUniqueEmail(command.Email).Result).Returns(true);
            _validator = new RegisterConsultantCommandValidator(mockRepo.Object);
        }
コード例 #2
0
        public void GivenValidData_WhenValidateRegister_ThenReturnNoErrors()
        {
            var command = RegisterConsultantCommandFactory.ValidRegisterConsultantCommand();

            var result = _validator.TestValidate(command);

            result.IsValid.Should().BeTrue();
            result.ShouldNotHaveAnyValidationErrors();
        }
コード例 #3
0
        public async Task GivenConsultantController_WhenRegisterIsCalled_ThenReturnConsultant()
        {
            var command = RegisterConsultantCommandFactory.ValidRegisterConsultantCommand();

            var result = await _controller.Register(command);

            var okResult = result as OkObjectResult;

            okResult.Should().NotBeNull();
            okResult.StatusCode.Should().Be(200);
            A.CallTo(() => _mediator.Send(command, default)).MustHaveHappenedOnceExactly();
        }
コード例 #4
0
        public void GivenShortPassword_WhenValidateRegister_ThenReturnValidationErrors()
        {
            var command = RegisterConsultantCommandFactory.RegisterConsultantCommandWithShortPassword();

            var result = _validator.TestValidate(command);

            result.IsValid.Should().BeFalse();
            result.ShouldHaveValidationErrorFor(c => c.Password)
            .WithErrorMessage(ValidationErrors.ShortPassword);
            result.ShouldNotHaveValidationErrorFor(user => user.Email);
            result.ShouldNotHaveValidationErrorFor(user => user.Location);
            result.ShouldNotHaveValidationErrorFor(user => user.Username);
        }
コード例 #5
0
        public void GivenNoData_WhenValidateRegister_ThenReturnValidationErrors()
        {
            var command = RegisterConsultantCommandFactory.RegisterConsultantCommandWithNoData();

            var result = _validator.TestValidate(command);

            result.IsValid.Should().BeFalse();
            result.ShouldHaveAnyValidationError();
            result.ShouldHaveValidationErrorFor(c => c.Email)
            .WithErrorMessage(ValidationErrors.EmptyEmail);
            result.ShouldHaveValidationErrorFor(c => c.Username)
            .WithErrorMessage(ValidationErrors.EmptyUsername);
            result.ShouldHaveValidationErrorFor(c => c.Location)
            .WithErrorMessage(ValidationErrors.EmptyLocation);
            result.ShouldHaveValidationErrorFor(c => c.Password)
            .WithErrorMessage(ValidationErrors.EmptyPassword);
        }