コード例 #1
0
        private void ConfigureRules()
        {
            RuleFor(request => request.ClientId)
            .NotEmpty()
            .WithMessage("Please specify client_id for searching.");

            RuleFor(request => request.SortKey)
            .Must(sortKey => string.IsNullOrWhiteSpace(sortKey) ||
                  ValidSortKeys.Contains(sortKey, StringComparer.OrdinalIgnoreCase))
            .WithMessage($"sort_key must be one of the following values: {ValidSortKeys}");

            RuleFor(request => request.SortDirection)
            .Must(sortDirection => string.IsNullOrWhiteSpace(sortDirection) ||
                  ValidSortDirections.Contains(sortDirection, StringComparer.OrdinalIgnoreCase))
            .WithMessage($"sort_dir must be one of the following values: {ValidSortDirections}");
        }
コード例 #2
0
        private void ConfigureRules()
        {
            RuleFor(request => request).Must(DoesContainRequiredFields)
            .WithMessage("Please specify 'client_id' OR 'grain' (for shared grain searches) but NOT both.")
            .WithState(c => ValidationEnums.ValidationState.MissingRequiredField);

            RuleFor(request => request.SortKey)
            .Must(sortKey => string.IsNullOrWhiteSpace(sortKey) ||
                  ValidSortKeys.Contains(sortKey, StringComparer.OrdinalIgnoreCase))
            .WithMessage($"sort_key must be one of the following values: {string.Join(", ", ValidSortKeys)}")
            .WithState(c => ValidationEnums.ValidationState.InvalidFieldValue);

            RuleFor(request => request.SortDirection)
            .Must(sortDirection => string.IsNullOrWhiteSpace(sortDirection) ||
                  ValidSortDirections.Contains(sortDirection, StringComparer.OrdinalIgnoreCase))
            .WithMessage($"sort_dir must be one of the following values: {ValidSortDirections}")
            .WithState(c => ValidationEnums.ValidationState.InvalidFieldValue);
        }