public void DeepConflict_ReportsToNearestCommonAncestor()
        {
            var errors = Validate(@"
                {
                    field {
                        deepField {
                            x: a
                        }
                        deepField {
                            x: b
                        }
                    },
                    field {
                        deepField {
                            y
                        }
                    }
                }
            ");

            ErrorAssert.AreEqual(
                "Fields \"deepField\" conflict because subfields \"x\" conflict because a and b are different fields" +
                ". Use different aliases on the fields to fetch both if this was " +
                "intentional.",
                errors.Single(),
                new[] { 4, 25 },
                new[] { 5, 29 },
                new[] { 7, 25 },
                new[] { 8, 29 });
        }
示例#2
0
        public async Task UpdateSuite_WhenFieldMoreThanMaxLengthValue_ShouldReturnBadRequest(
            string serializedSuite, string typeOfError)
        {
            //Arrange
            SetAuthorization();

            var projectModel = ProjectFactory.GetProjectModel();
            var suiteModel   = SuiteFactory.GetSuiteModel();

            var project = await ProjectService.AddProject(projectModel);

            var projectId = ProjectSteps.GetProjectId(project);

            var suite = await SuiteService.AddSuite(projectId, suiteModel);

            var suiteId          = SuiteSteps.GetSuiteId(suite);
            var updateSuiteModel = NewtonsoftJsonSerializer.DefaultDeserialize <RequestSuiteModel>(serializedSuite);

            //Act
            var response = await SuiteService.UpdateSuite(suiteId, updateSuiteModel);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var errorResponse = response.GetErrors();

            ErrorAssert.ValidateErrorMessage(errorResponse, typeOfError);
        }
        public void DeepConflictWithMultipleIssues_ReportsError()
        {
            var errors = Validate(@"
                {
                    field {
                        x: a
                        y: c
                    },
                    field {
                        x: b
                        y: d
                    }
                }
            ");

            ErrorAssert.AreEqual(
                "Fields \"field\" conflict because subfields \"x\" conflict because a and b are different fields and subfields \"y\" conflict because c and d are different fields" +
                ". Use different aliases on the fields to fetch both if this was " +
                "intentional.",
                errors.Single(),
                new[] { 3, 21 },
                new[] { 4, 25 },
                new[] { 5, 25 },
                new[] { 7, 21 },
                new[] { 8, 25 },
                new[] { 9, 25 });
        }
示例#4
0
        public void UnknownTypeNamesAreInvalid()
        {
            var errors = this.Validate(@"
              query Foo($var: JumbledUpLetters) {
                complicatedArgs {
                  intArgField
                  complicatedObjectArgField { ... on Badger { name }, ...complFields }
                }
              }
              fragment complFields on ComplicatedObjectTypeee {
                booleanField
              }
            ");

            var jumbledUpLettersError = errors.ElementAt(0);
            var badgerError           = errors.ElementAt(1);
            var complicatedObjectArgFieldddddddError = errors.ElementAt(2);

            ErrorAssert.StartsWith("Unknown type \"JumbledUpLetters\".",
                                   jumbledUpLettersError, 2, 31);
            ErrorAssert.StartsWith("Unknown type \"Badger\".",
                                   badgerError, 5, 54);
            ErrorAssert.StartsWith("Unknown type \"ComplicatedObjectTypeee\". Did you mean \"ComplicatedObjectType\"",
                                   complicatedObjectArgFieldddddddError, 8, 39);
        }
        public void ComparesDeepTypesIncludingLists()
        {
            var errors = Validate(@"
                 {
                  connection {
                    ...edgeID
                    edges {
                      node {
                        id: name
                      }
                    }
                  }
                }
                fragment edgeID on Connection {
                  edges {
                    node {
                      id
                    }
                  }
                }
            ");

            ErrorAssert.AreEqual(
                "Fields \"edges\" conflict because subfields \"node\" conflict because subfields \"id\"" +
                " conflict because name and id are different fields. " +
                "Use different aliases on the fields to fetch both if this was intentional.",
                errors.Single(),
                new[] { 5, 21 },
                new[] { 6, 23 },
                new[] { 7, 25 },
                new[] { 13, 19 },
                new[] { 14, 21 },
                new[] { 15, 23 });
        }
示例#6
0
        public void Execute_FullPathForFieldsInNestedList()
        {
            dynamic result = this.schema.Execute(@"
            query {
                nullableA {
                    nullableAList {
                        nullableAList {
                            nullableA {
                                throws
                            }
                        }
                    }
                }
            }
            ");

            dynamic nullableAList = result.data.nullableA.nullableAList as IList <object>;

            Assert.AreEqual(4, nullableAList.Count);
            Assert.AreEqual("did not throw", nullableAList[0].nullableAList[0].nullableA.throws);
            Assert.AreEqual(null, nullableAList[3].nullableAList[3].nullableA);

            var errors = result.errors as IList <GraphQLException>;

            Assert.AreEqual(8, errors.Count);

            for (var i = 0; i < 4; i++)
            {
                ErrorAssert.AreEqual("Catch me if you can", errors[i * 2], 7, 33,
                                     new object[] { "nullableA", "nullableAList", i, "nullableAList", 1, "nullableA", "throws" });
                ErrorAssert.AreEqual("Catch me if you can", errors[i * 2 + 1], 7, 33,
                                     new object[] { "nullableA", "nullableAList", i, "nullableAList", 3, "nullableA", "throws" });
            }
        }
示例#7
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(IEnumerable <Error> expected, DomReadWriteErrors actual)
        {
            if (expected == null)
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);

            Assert.Equal(DomNodeType.Errors, actual.NodeType);

            var expectedCollection = expected.SafeToReadOnlyList();

            var actualNodes = actual.Nodes()
                              .ToList();

            var actualDomErrorsCount = actualNodes.Count;

            Assert.Equal(expectedCollection.Count, actualDomErrorsCount);

            var count = expectedCollection.Count;

            for (var i = 0; i < count; ++i)
            {
                var expectedError = expectedCollection[i];

                var actualNode     = actualNodes[i];
                var actualDomError = (IDomError)actualNode;
                var actualError    = actualDomError.Error;

                ErrorAssert.Equal(expectedError, actualError);
            }
        }
示例#8
0
        public void DeeplyNestedUnknownArguments_ReportsMultipleErrors()
        {
            var errors = Validate(@"
            {
                complicatedArgs {
                    enumArgField(unknown: true)
                }
                field(ab: ""yes"") {
                    complicatedArgs {
                        nested {
                            ... on ComplicatedArgs {
                                enumArgField(unknown: true)
                            }
                        }
                    }
                }
            }
            ");

            Assert.AreEqual(3, errors.Count());

            ErrorAssert.AreEqual("Unknown argument \"unknown\" on field \"enumArgField\" of type \"ComplicatedArgs\".",
                                 errors.ElementAt(0), 4, 34);
            ErrorAssert.AreEqual("Unknown argument \"ab\" on field \"field\" of type \"QueryRoot\". Did you mean \"a\" or \"b\"?",
                                 errors.ElementAt(1), 6, 23);
            ErrorAssert.AreEqual("Unknown argument \"unknown\" on field \"enumArgField\" of type \"ComplicatedArgs\".",
                                 errors.ElementAt(2), 10, 46);
        }
示例#9
0
        public void Execute_FullPathForFieldsInList()
        {
            dynamic result = this.schema.Execute(@"
            query {
                nullableAList {
                    foo
                    throwAlias : throws
                }
            }
            ");

            var nullableAList = (IList <object>)result.data.nullableAList;

            Assert.AreEqual(4, nullableAList.Count);

            Assert.IsNotNull(nullableAList.ElementAt(0));
            Assert.IsNull(nullableAList.ElementAt(1));
            Assert.IsNotNull(nullableAList.ElementAt(2));
            Assert.IsNull(nullableAList.ElementAt(3));

            var errors = result.errors as IEnumerable <GraphQLException>;

            Assert.AreEqual(2, errors.Count());

            ErrorAssert.AreEqual("Catch me if you can", errors.ElementAt(0), 5, 21, new object[] { "nullableAList", 1, "throwAlias" });
            ErrorAssert.AreEqual("Catch me if you can", errors.ElementAt(1), 5, 21, new object[] { "nullableAList", 3, "throwAlias" });
        }
        public void MultipleMisplacedDirectives_ReportsMultipleErrors()
        {
            var errors = Validate(@"
            query Foo @include(if: true) {
                foo @onQuery
                ...Frag @onQuery
                ... @onField {
                    name
                }
            }

            mutation Bar @onQuery {
                insertInputObject {
                    intField
                }
            }

            subscription Sub @onMutation {
                __typename
            }
            ");

            Assert.AreEqual(6, errors.Count());

            ErrorAssert.AreEqual("Directive \"include\" may not be used on QUERY.", errors.ElementAt(0), 2, 23);
            ErrorAssert.AreEqual("Directive \"onQuery\" may not be used on FIELD.", errors.ElementAt(1), 3, 21);
            ErrorAssert.AreEqual("Directive \"onQuery\" may not be used on FRAGMENT_SPREAD.", errors.ElementAt(2), 4, 25);
            ErrorAssert.AreEqual("Directive \"onField\" may not be used on INLINE_FRAGMENT.", errors.ElementAt(3), 5, 21);
            ErrorAssert.AreEqual("Directive \"onQuery\" may not be used on MUTATION.", errors.ElementAt(4), 10, 26);
            ErrorAssert.AreEqual("Directive \"onMutation\" may not be used on SUBSCRIPTION.", errors.ElementAt(5), 16, 30);
        }
示例#11
0
        public void MultipleVariablesNotUsedInFragments()
        {
            var errors = Validate(@"
               query Foo($a: String, $b: String, $c: String) {
                ...FragA
              }
              fragment FragA on QueryRoot {
                field {
                  ...FragB
                }
              }
              fragment FragB on QueryRoot {
                field(b: $b) {
                  ...FragC
                }
              }
              fragment FragC on QueryRoot {
                field
              }
            ");

            Assert.AreEqual(2, errors.Count());

            ErrorAssert.AreEqual($"Variable \"$a\" is never used in operation \"Foo\".", errors.ElementAt(0), 2, 26);
            ErrorAssert.AreEqual($"Variable \"$c\" is never used in operation \"Foo\".", errors.ElementAt(1), 2, 50);
        }
示例#12
0
        public void SpreadingItselfDeeply_ReportsError()
        {
            var errors = Validate(@"
                fragment fragA on Dog { ...fragB }
                fragment fragB on Dog { ...fragC }
                fragment fragC on Dog { ...fragO }
                fragment fragX on Dog { ...fragY }
                fragment fragY on Dog { ...fragZ }
                fragment fragZ on Dog { ...fragO }
                fragment fragO on Dog { ...fragP }
                fragment fragP on Dog { ...fragA, ...fragX }
            ");

            Assert.AreEqual(2, errors.Count());

            ErrorAssert.AreEqual("Cannot spread fragment \"fragA\" within itself via fragB, fragC, fragO, fragP.",
                                 errors.ElementAt(0),
                                 new[] { 2, 41 },
                                 new[] { 3, 41 },
                                 new[] { 4, 41 },
                                 new[] { 8, 41 },
                                 new[] { 9, 41 });

            ErrorAssert.AreEqual("Cannot spread fragment \"fragO\" within itself via fragP, fragX, fragY, fragZ.",
                                 errors.ElementAt(1),
                                 new[] { 8, 41 },
                                 new[] { 9, 51 },
                                 new[] { 5, 41 },
                                 new[] { 6, 41 },
                                 new[] { 7, 41 });
        }
        public void DisallowsDifferingDeepReturnTypesDespiteNoOverlap()
        {
            var errors = Validate(@"
                {
                  someBox {
                    ... on IntBox {
                      box: stringBox {
                        scalar
                      }
                    }
                    ... on StringBox {
                      box: intBox {
                        scalar
                      }
                    }
                  }
                }
            ");

            ErrorAssert.AreEqual(
                "Fields \"box\" conflict because subfields \"scalar\" conflict because they return conflicting types String and Int. " +
                "Use different aliases on the fields to fetch both if this was intentional.",
                errors.Single(),
                new[] { 5, 23 },
                new[] { 6, 25 },
                new[] { 10, 23 },
                new[] { 11, 25 });
        }
        public void DisallowsDifferingSubfields()
        {
            var errors = Validate(@"
                 {
                  someBox {
                    ... on IntBox {
                      box: stringBox {
                        val: scalar
                        val: unrelatedField
                      }
                    }
                    ... on StringBox {
                      box: stringBox {
                        val: scalar
                      }
                    }
                  }
                }
            ");

            ErrorAssert.AreEqual(
                "Fields \"val\" conflict because scalar and unrelatedField are different fields. " +
                "Use different aliases on the fields to fetch both if this was intentional.",
                errors.Single(), new[] { 6, 25 }, new[] { 7, 25 });
        }
示例#15
0
        public void SpreadingItselfDirectly_ReportsError()
        {
            var errors = Validate(@"
                fragment fragA on Dog { ...fragA }
            ");

            ErrorAssert.AreEqual("Cannot spread fragment \"fragA\" within itself.", errors.Single(), 2, 41);
        }
示例#16
0
        public void SpreadingRecursivelyWithinField_ReportsError()
        {
            var errors = Validate(@"
                fragment fragA on Human { relatives { ...fragA } }
            ");

            ErrorAssert.AreEqual("Cannot spread fragment \"fragA\" within itself.", errors.Single(), 2, 55);
        }
        public void ReportsCorrectlyWhenNonExclusiveFollowsAnExclusive()
        {
            var errors = Validate(@"
                {
                  someBox {
                    ... on IntBox {
                      deepBox {
                        ...X
                      }
                    }
                  }
                  someBox {
                    ... on StringBox {
                      deepBox {
                        ...Y
                      }
                    }
                  }
                  memoed: someBox {
                    ... on IntBox {
                      deepBox {
                        ...X
                      }
                    }
                  }
                  memoed: someBox {
                    ... on StringBox {
                      deepBox {
                        ...Y
                      }
                    }
                  }
                  other: someBox {
                    ...X
                  }
                  other: someBox {
                    ...Y
                  }
                }
                fragment X on SomeBox {
                  scalar
                }
                fragment Y on SomeBox {
                  scalar: unrelatedField
                }
            ");

            ErrorAssert.AreEqual(
                "Fields \"other\" conflict because subfields \"scalar\" conflict because scalar and unrelatedField are different fields." +
                " Use different aliases on the fields to fetch both if this was intentional.",
                errors.Single(),
                new[] { 31, 19 },
                new[] { 39, 19 },
                new[] { 34, 19 },
                new[] { 42, 19 });
        }
        public void ObjectTypeMissingSelection()
        {
            var errors = this.Validate(@"
                query directQueryOnObjectWithoutSubFields { complicatedArgs }");

            ErrorAssert.AreEqual(
                "Field \"complicatedArgs\" of type \"ComplicatedArgs\" must have a selection of subfields. " +
                "Did you mean \"complicatedArgs { ... }\"?",
                errors.Single(), 2, 61);
        }
        public void ScalarSelectionNotAllowedOnEnum()
        {
            var errors = this.Validate(@"
                query directQueryOnObjectWithoutSubFields { interfaceObject { enumField { stuff } } }");

            ErrorAssert.AreEqual(
                "Field \"enumField\" must not have a selection since " +
                "type \"FurColor\" has no subfields.",
                errors.Single(), 2, 89);
        }
示例#20
0
        public void SpreadingItselfIndirectlyInReverseOrder_ReportsError()
        {
            var errors = Validate(@"
                fragment fragB on Dog { ...fragA }
                fragment fragA on Dog { ...fragB }
            ");

            ErrorAssert.AreEqual("Cannot spread fragment \"fragB\" within itself via fragA.",
                                 errors.Single(), new[] { 2, 41 }, new[] { 3, 41 });
        }
        public void ScalarSelectionNotAllowedOnListOfString()
        {
            var errors = this.Validate(@"
                query directQueryOnObjectWithoutSubFields { interfaceObject { stringListField { stuff } } }");

            ErrorAssert.AreEqual(
                "Field \"stringListField\" must not have a selection since " +
                "type \"[String]\" has no subfields.",
                errors.Single(), 2, 95);
        }
示例#22
0
        public void VariableNotUsed()
        {
            var errors = Validate(@"
               query ($a: String, $b: String, $c: String) {
                field(a: $a, b: $b) { foo }
              }
            ");

            ErrorAssert.AreEqual($"Variable \"$c\" is never used.", errors.Single(), 2, 47);
        }
        public void UnknownDirective_ReportsSingleError()
        {
            var errors = Validate(@"
            {
                foo @unknown(directive: ""value"")
            }
            ");

            ErrorAssert.AreEqual("Unknown directive \"unknown\".", errors.Single(), 3, 21);
        }
        public void IntrospectedObjectTypeMissingSelection()
        {
            var errors = this.Validate(@"
                query directIntrospectionQuerytWithoutSubFields { __schema }");

            ErrorAssert.AreEqual(
                "Field \"__schema\" of type \"__Schema\" must have a selection of subfields. " +
                "Did you mean \"__schema { ... }\"?",
                errors.Single(), 2, 67);
        }
示例#25
0
        public void DuplicateFieldArguments()
        {
            var errors = this.Validate(@"
            {
                foo(a: 1, a: 2)
            }");

            ErrorAssert.AreEqual("There can be only one argument named \"a\".",
                                 errors.Single(), new[] { 3, 21 }, new[] { 3, 27 });
        }
示例#26
0
        public void DuplicateDirectiveArguments()
        {
            var errors = this.Validate(@"
            {
                foo @directive(a: 1, a: 2)
            }");

            ErrorAssert.AreEqual("There can be only one argument named \"a\".",
                                 errors.Single(), new[] { 3, 32 }, new[] { 3, 38 });
        }
        public void InterfaceTypeWithMissingSelection()
        {
            var errors = this.Validate(@"
                query directQueryOnObjectWithoutSubFields { interfaceObject }");

            ErrorAssert.AreEqual(
                "Field \"interfaceObject\" of type \"ComplicatedInterfaceType\" must have a selection of subfields. " +
                "Did you mean \"interfaceObject { ... }\"?",
                errors.Single(), 2, 61);
        }
示例#28
0
        public void OneVariableUndefinedInAnonymousOperation_ExpectsSingleError()
        {
            var errors = Validate(@"
            query {
                bar(a: $a)
            }
            ");

            ErrorAssert.AreEqual("Variable \"$a\" is not defined.",
                                 errors.Single(), new[] { 3, 24 }, new[] { 2, 13 });
        }
示例#29
0
        public void OneVariableUndefined_ExpectsSingleError()
        {
            var errors = Validate(@"
            query foo($a: Int, $b: Int) {
                foo(a: $a, b: $b, c: $c) 
            }
            ");

            ErrorAssert.AreEqual("Variable \"$c\" is not defined by operation \"foo\".",
                                 errors.Single(), new[] { 3, 38 }, new[] { 2, 13 });
        }
示例#30
0
        public void FieldOnScalarType_ReportsSingleError()
        {
            var errors = Validate(@"
            fragment scalarFragment on Boolean {
                foo
            }
            ");

            ErrorAssert.AreEqual("Cannot query field \"foo\" on type \"Boolean\".",
                                 errors.Single(), 3, 17);
        }