Beispiel #1
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, Schema, config.Rules);

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

            config.Assertions.Apply((assert, idx) =>
            {
                var error = result.Errors.Skip(idx).First();
                error.Message.ShouldEqual(assert.Message);

                assert.Locations.Apply((assertLoc, locIdx) =>
                {
                    var errorLoc = error.Locations.Skip(locIdx).First();
                    errorLoc.Line.ShouldEqual(
                        assertLoc.Line,
                        $"Expected line {assertLoc.Line} but was {errorLoc.Line} - {error.Message} ({errorLoc.Line},{errorLoc.Column})");
                    errorLoc.Column.ShouldEqual(
                        assertLoc.Column,
                        $"Expected column {assertLoc.Column} but was {errorLoc.Column} - {error.Message} ({errorLoc.Line},{errorLoc.Column})");
                });

                error.Locations.Count().ShouldEqual(assert.Locations.Count());
            });
        }
Beispiel #2
0
        protected void ShouldFailRule(Action <ValidationTestConfig> configure)
        {
            var config = new ValidationTestConfig();

            configure(config);

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

            var count = 0;

            config.Assertions.Apply(assert =>
            {
                var error = result.Errors.Skip(count).First();
                error.Message.ShouldEqual(assert.Message);

                if (assert.Line != null)
                {
                    var location = error.Locations.Single();
                    location.Line.ShouldEqual(assert.Line.Value);
                    location.Column.ShouldEqual(assert.Column.Value);
                }
            });

            result.IsValid.ShouldBeFalse();
        }
Beispiel #3
0
 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);
     });
 }
 private void missingDirectiveArg(
     ValidationTestConfig _,
     string directiveName,
     string argName,
     string typeName,
     int line,
     int column)
 {
     _.Error(Rule.MissingDirectiveArgMessage(directiveName, argName, typeName), line, column);
 }
Beispiel #5
0
        protected void ShouldPassRule(Action <ValidationTestConfig> configure)
        {
            var config = new ValidationTestConfig();

            configure(config);

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

            result.IsValid.ShouldBeTrue();
        }
Beispiel #6
0
 private void missingDirectiveArg(
     ValidationTestConfig _,
     string directiveName,
     string argName,
     string typeName,
     int line,
     int column)
 {
     _.Error(ProvidedNonNullArgumentsError.MissingDirectiveArgMessage(directiveName, argName, typeName), line, column);
 }
 private void missingFieldArg(
     ValidationTestConfig _,
     string fieldName,
     string argName,
     string typeName,
     int line,
     int column)
 {
     _.Error(Rule.MissingFieldArgMessage(fieldName, argName, typeName), line, column);
 }
 private void undefFrag(
     ValidationTestConfig _,
     string fragName,
     int line,
     int column)
 {
     _.Error(err =>
     {
         err.Message = Rule.UnknownFragmentMessage(fragName);
         err.Loc(line, column);
     });
 }
Beispiel #9
0
 private void unusedFrag(
     ValidationTestConfig _,
     string varName,
     int line,
     int column
     )
 {
     _.Error(err =>
     {
         err.Message = Rule.UnusedFragMessage(varName);
         err.Loc(line, column);
     });
 }
Beispiel #10
0
        private void undefinedField(
            ValidationTestConfig _,
            string field,
            string type,
            IEnumerable <string> suggestedTypes  = null,
            IEnumerable <string> suggestedFields = null,
            int line   = 0,
            int column = 0)
        {
            suggestedTypes  = suggestedTypes ?? Enumerable.Empty <string>();
            suggestedFields = suggestedFields ?? Enumerable.Empty <string>();

            _.Error(Rule.UndefinedFieldMessage(field, type, suggestedTypes, suggestedFields), line, column);
        }
 private void unusedVar(
     ValidationTestConfig _,
     string varName,
     string opName,
     int line,
     int column
     )
 {
     _.Error(err =>
     {
         err.Message = NoUnusedVariablesError.UnusedVariableMessage(varName, opName);
         err.Loc(line, column);
     });
 }
 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);
     });
 }
 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);
     });
 }
Beispiel #14
0
 private void duplicateFrag(
     ValidationTestConfig _,
     string fragName,
     int line1,
     int column1,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = Rule.DuplicateFragmentNameMessage(fragName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
Beispiel #15
0
 private void duplicateDirective(
     ValidationTestConfig _,
     string directiveName,
     int line1,
     int column1,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = Rule.DuplicateDirectiveMessage(directiveName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
 private void undefVar(
     ValidationTestConfig _,
     string varName,
     int line1,
     int column1,
     string opName,
     int line2,
     int column2)
 {
     _.Error(err =>
     {
         err.Message = Rule.UndefinedVarMessage(varName, opName);
         err.Loc(line1, column1);
         err.Loc(line2, column2);
     });
 }
        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);
        }
        public static void badValue(
            this ArgumentsOfCorrectType rule,
            ValidationTestConfig config,
            string argName,
            string typeName,
            string value,
            int line,
            int column,
            IEnumerable <string> errors = null)
        {
            errors ??= new[] { $"Expected type \"{typeName}\", found {value}." };

            config.Error(
                ArgumentsOfCorrectTypeError.BadValueMessage(argName, value, errors),
                line,
                column);
        }
Beispiel #19
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);
            var message = "";

            if (result.Errors?.Any() == true)
            {
                message = string.Join(", ", result.Errors.Select(x => x.Message));
            }
            result.IsValid.ShouldBeTrue(message);
        }
        private void badValue(
            ValidationTestConfig _,
            string argName,
            string typeName,
            string value,
            int?line   = null,
            int?column = null,
            IEnumerable <string> errors = null)
        {
            if (errors == null)
            {
                errors = new [] { $"Expected type \"{typeName}\", found {value}." };
            }

            _.Error(
                _rule.BadValueMessage(argName, null, value, errors),
                line,
                column);
        }
Beispiel #21
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);

            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.ToList();

                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);
            }
        }
Beispiel #22
0
        public static void badValue(
            this ArgumentsOfCorrectType rule,
            ValidationTestConfig _,
            string argName,
            string typeName,
            string value,
            int?line   = null,
            int?column = null,
            IEnumerable <string> errors = null)
        {
            if (errors == null)
            {
                errors = new [] { $"Expected type \"{typeName}\", found {value}." };
            }

            _.Error(
                rule.BadValueMessage(argName, null, value, errors),
                line,
                column);
        }
 private void errorAnon(ValidationTestConfig _, string parentType, string fragType, int line, int column)
 {
     _.Error(Rule.TypeIncompatibleAnonSpreadMessage(parentType, fragType), line, column);
 }
 private void error(ValidationTestConfig _, string fragName, string typeName, int line, int column)
 {
     _.Error(Rule.FragmentOnNonCompositeErrorMessage(fragName, typeName), line, column);
 }
 private void unknownDirective(ValidationTestConfig _, string name, int line, int column)
 {
     _.Error(Rule.UnknownDirectiveMessage(name), line, column);
 }
 private void misplacedDirective(ValidationTestConfig _, string name, DirectiveLocation placement, int line, int column)
 {
     _.Error(Rule.MisplacedDirectiveMessage(name, placement.ToString()), line, column);
 }
 private void misplacedDirective(ValidationTestConfig _, string name, DirectiveLocation placement, int line, int column)
 {
     _.Error($"Directive '{name}' may not be used on {placement}.", line, column);
 }
Beispiel #28
0
 private void error(ValidationTestConfig _, string fragName, string parentType, string fragType, int line, int column)
 {
     _.Error(PossibleFragmentSpreadsError.TypeIncompatibleSpreadMessage(fragName, parentType, fragType), line, column);
 }
 private void unknownDirective(ValidationTestConfig _, string name, int line, int column)
 {
     _.Error($"Unknown directive '{name}'.", line, column);
 }