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); }
public void GivenValidData_WhenValidateRegister_ThenReturnNoErrors() { var command = RegisterConsultantCommandFactory.ValidRegisterConsultantCommand(); var result = _validator.TestValidate(command); result.IsValid.Should().BeTrue(); result.ShouldNotHaveAnyValidationErrors(); }
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(); }
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); }
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); }