public void ValidGetTeamRequestReturnsNoErrorsOnValidation() { var createTeamRequest = TestHelpers.CreateGetTeamsRequest(); var validator = new GetTeamsRequestValidator(); var validationResponse = validator.Validate(createTeamRequest); validationResponse.IsValid.Should().Be(true); }
public IActionResult GetTeams([FromQuery] GetTeamsRequest request) { var validator = new GetTeamsRequestValidator(); var validationResults = validator.Validate(request); if (!validationResults.IsValid) { return(BadRequest(validationResults.ToString())); } var teams = _teamsUseCase.ExecuteGet(request); return(Ok(teams)); }
public void GetTeamsRequestValidationWithInvalidPropertiesReturnsError() { var badGetTeamsRequests = new List <(GetTeamsRequest, string)>() { (TestHelpers.CreateGetTeamsRequest(contextFlag: "d"), "Context flag must be 'A' or 'C'"), (TestHelpers.CreateGetTeamsRequest(contextFlag: ""), "Context flag must be 'A' or 'C'"), (TestHelpers.CreateGetTeamsRequest(contextFlag: "aa"), "Context flag must be 1 character in length"), }; var validator = new GetTeamsRequestValidator(); foreach (var(request, expectedErrorMessage) in badGetTeamsRequests) { var validationResponse = validator.Validate(request); validationResponse.IsValid.Should().Be(false); validationResponse.ToString().Should().Be(expectedErrorMessage); } }