コード例 #1
0
        public void ValidGetTeamRequestReturnsNoErrorsOnValidation()
        {
            var createTeamRequest = TestHelpers.CreateGetTeamsRequest();
            var validator         = new GetTeamsRequestValidator();

            var validationResponse = validator.Validate(createTeamRequest);

            validationResponse.IsValid.Should().Be(true);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
            }
        }