private void duplicateDirective(ValidationTestConfig _, string directiveName, int line, int column)
 {
     _.Error(err =>
     {
         err.Message = $"The directive '{directiveName}' can only be used once at this location.";
         err.Loc(line, column);
     });
 }
コード例 #2
0
 private void missingDirectiveArg(
     ValidationTestConfig _,
     string directiveName,
     string argName,
     string typeName,
     int line,
     int column)
 {
     _.Error(ProvidedNonNullArgumentsError.MissingDirectiveArgMessage(directiveName, argName, typeName), line, column);
 }
コード例 #3
0
 private void undefFrag(
     ValidationTestConfig _,
     string fragName,
     int line,
     int column)
 {
     _.Error(err =>
     {
         err.Message = KnownFragmentNamesError.UnknownFragmentMessage(fragName);
         err.Loc(line, column);
     });
 }
コード例 #4
0
 private void unusedFrag(
     ValidationTestConfig _,
     string varName,
     int line,
     int column
     )
 {
     _.Error(err =>
     {
         err.Message = NoUnusedFragmentsError.UnusedFragMessage(varName);
         err.Loc(line, column);
     });
 }
コード例 #5
0
 private void unusedVar(
     ValidationTestConfig _,
     string varName,
     string opName,
     int line,
     int column
     )
 {
     _.Error(err =>
     {
         err.Message = NoUnusedVariablesError.UnusedVariableMessage(varName, opName);
         err.Loc(line, column);
     });
 }
コード例 #6
0
    private void undefinedField(
        ValidationTestConfig _,
        string field,
        string type,
        IEnumerable <string> suggestedTypes  = null,
        IEnumerable <string> suggestedFields = null,
        int line   = 0,
        int column = 0)
    {
        suggestedTypes ??= Enumerable.Empty <string>();
        suggestedFields ??= Enumerable.Empty <string>();

        _.Error(FieldsOnCorrectTypeError.UndefinedFieldMessage(field, type, suggestedTypes, suggestedFields), line, column);
    }
コード例 #7
0
 private static void duplicateFrag(
     ValidationTestConfig _,
     string fragName,
     int line1,
     int column1,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = UniqueFragmentNamesError.DuplicateFragmentNameMessage(fragName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
コード例 #8
0
 private void duplicateArg(
     ValidationTestConfig _,
     string argName,
     int line1,
     int column1,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = UniqueArgumentNamesError.DuplicateArgMessage(argName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
コード例 #9
0
 private void duplicateVariable(
     ValidationTestConfig _,
     string variableName,
     int line1,
     int column1,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = UniqueVariableNamesError.DuplicateVariableMessage(variableName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
コード例 #10
0
 private void undefVar(
     ValidationTestConfig _,
     string varName,
     int line1,
     int column1,
     string opName,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = NoUndefinedVariablesError.UndefinedVarMessage(varName, opName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
コード例 #11
0
    private IValidationResult Validate(ValidationTestConfig config)
    {
        HttpContext.User = config.User;
        var documentBuilder = new GraphQLDocumentBuilder();
        var document        = documentBuilder.Build(config.Query);
        var validator       = new DocumentValidator();

        return(validator.ValidateAsync(new ValidationOptions
        {
            Schema = config.Schema,
            Document = document,
            Operation = document.Definitions.OfType <GraphQLOperationDefinition>().First(),
            Rules = config.Rules,
            Variables = config.Variables
        }).GetAwaiter().GetResult().validationResult);
    }
コード例 #12
0
    protected void ShouldFailRule(Action <ValidationTestConfig> configure)
    {
        var config = new ValidationTestConfig();

        config.Rules.Add(Rule);
        configure(config);

        config.Rules.Any().ShouldBeTrue("Must provide at least one rule to validate against.");

        config.Schema.Initialize();

        var result = Validate(config);

        result.IsValid.ShouldBeFalse("Expected validation errors though there were none.");
        config.ValidateResult(result);
    }
コード例 #13
0
    public static void badValue(
        this ArgumentsOfCorrectType rule,
        ValidationTestConfig config,
        string argName,
        string typeName,
        string value,
        int line,
        int column,
        string errors = null)
    {
        errors ??= $"Expected type '{typeName}', found {value}.";

        config.Error(
            ArgumentsOfCorrectTypeError.BadValueMessage(argName, errors),
            line,
            column);
    }
コード例 #14
0
    protected void ShouldPassRule(Action <ValidationTestConfig> configure)
    {
        var config = new ValidationTestConfig();

        config.Rule(Rule);
        configure(config);

        config.Rules.Any().ShouldBeTrue("Must provide at least one rule to validate against.");

        var result  = Validate(config.Query, config.Schema ?? Schema, config.Rules, config.Variables);
        var message = "";

        if (result.Errors?.Any() == true)
        {
            message = string.Join(", ", result.Errors.Select(x => x.Message));
        }
        result.IsValid.ShouldBeTrue(message);
    }
コード例 #15
0
    protected void ShouldFailRule(Action <ValidationTestConfig> configure)
    {
        var config = new ValidationTestConfig();

        config.Rule(Rule);
        configure(config);

        config.Rules.Any().ShouldBeTrue("Must provide at least one rule to validate against.");

        var result = Validate(config.Query, config.Schema ?? Schema, config.Rules, config.Variables);

        result.IsValid.ShouldBeFalse("Expected validation errors though there were none.");
        result.Errors.Count.ShouldBe(
            config.Assertions.Count,
            $"The number of errors found ({result.Errors.Count}) does not match the number of errors expected ({config.Assertions.Count}).");

        for (int i = 0; i < config.Assertions.Count; i++)
        {
            var assert = config.Assertions[i];
            var error  = result.Errors[i];

            error.Message.ShouldBe(assert.Message);

            var allLocations = string.Concat(error.Locations.Select(l => $"({l.Line},{l.Column})"));
            var locations    = error.Locations;

            for (int j = 0; j < assert.Locations.Count; j++)
            {
                var assertLoc = assert.Locations[j];
                var errorLoc  = locations[j];

                errorLoc.Line.ShouldBe(
                    assertLoc.Line,
                    $"Expected line {assertLoc.Line} but was {errorLoc.Line} - {error.Message} {allLocations}");
                errorLoc.Column.ShouldBe(
                    assertLoc.Column,
                    $"Expected column {assertLoc.Column} but was {errorLoc.Column} - {error.Message} {allLocations}");
            }

            locations.Count.ShouldBe(assert.Locations.Count);
        }
    }
コード例 #16
0
 private void errorAnon(ValidationTestConfig _, string parentType, string fragType, int line, int column)
 {
     _.Error(PossibleFragmentSpreadsError.TypeIncompatibleAnonSpreadMessage(parentType, fragType), line, column);
 }
コード例 #17
0
 private void unknownDirective(ValidationTestConfig _, string name, int line, int column)
 {
     _.Error($"Unknown directive '{name}'.", line, column);
 }
コード例 #18
0
 private void misplacedDirective(ValidationTestConfig _, string name, DirectiveLocation placement, int line, int column)
 {
     _.Error($"Directive '{name}' may not be used on {placement}.", line, column);
 }
コード例 #19
0
 private void error(ValidationTestConfig _, string fragName, string typeName, int line, int column)
 {
     _.Error(FragmentsOnCompositeTypesError.FragmentOnNonCompositeErrorMessage(fragName, typeName), line, column);
 }