Esempio n. 1
0
        private IReadOnlyList <HCError> ValidateQueryDocuments(ISchema schema)
        {
            var errors = new List <HCError>();

            try
            {
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddValidation();
                IDocumentValidator validator = serviceCollection.BuildServiceProvider()
                                               .GetService <IDocumentValidatorFactory>().CreateValidator();

                foreach (DocumentInfo documentInfo in _queries.Values)
                {
                    DocumentValidatorResult validationResult =
                        validator.Validate(schema, documentInfo.Document);

                    if (validationResult.HasErrors)
                    {
                        foreach (HCError error in validationResult.Errors)
                        {
                            errors.Add(HCErrorBuilder.FromError(error)
                                       .SetExtension("fileName", documentInfo.FileName)
                                       .SetExtension("document", documentInfo.Document)
                                       .Build());
                        }
                    }
                }
            }
            catch (GeneratorException ex)
            {
                errors.AddRange(ex.Errors);
            }

            return(errors);
        }
Esempio n. 2
0
        public void FromError_ErrorNull_ArgumentNullException()
        {
            // arrange
            // act
            Action action = () => ErrorBuilder.FromError(null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
Esempio n. 3
0
        public void FromError()
        {
            // arrange
            IError error = new Error("123");

            // act
            error = ErrorBuilder.FromError(error).Build();

            // assert
            Assert.Equal("123", error.Message);
        }
Esempio n. 4
0
        public void FromError()
        {
            // arrange
            IError error = new Error {
                Message = "123"
            };

            // act
            ErrorBuilder builder = ErrorBuilder.FromError(error);

            error = builder.Build();

            // assert
            Assert.Equal("123", error.Message);
        }
Esempio n. 5
0
        public void FromError_ClearLocations()
        {
            // arrange
            IError error = new Error
                           (
                "123",
                locations: ImmutableList <Location>
                .Empty
                .Add(new Location(1, 2))
                           );

            // act
            error = ErrorBuilder.FromError(error).ClearLocations().Build();

            // assert
            Assert.Equal("123", error.Message);
            Assert.Null(error.Locations);
        }
Esempio n. 6
0
        public void FromError_ClearExtensions()
        {
            // arrange
            IError error = new Error
                           (
                "123",
                extensions: new OrderedDictionary <string, object>
            {
                { "foo", "bar" }
            }
                           );

            // act
            error = ErrorBuilder.FromError(error).ClearExtensions().Build();

            // assert
            Assert.Equal("123", error.Message);
            Assert.Null(error.Extensions);
        }
Esempio n. 7
0
        public void FromError_WithExtensions()
        {
            // arrange
            IError error = new Error(
                "123",
                extensions: new OrderedDictionary <string, object>
            {
                { "foo", "bar" }
            });

            // act
            var builder = ErrorBuilder.FromError(error);

            error = builder.Build();

            // assert
            Assert.Equal("123", error.Message);
            Assert.Collection(error.Extensions !,
                              t => Assert.Equal("bar", t.Value));
        }
Esempio n. 8
0
        public void FromError_WithLocations()
        {
            // arrange
            IError error = new Error
                           (
                "123",
                locations: ImmutableList <Location>
                .Empty
                .Add(new Location(1, 2))
                           );

            // act
            var builder = ErrorBuilder.FromError(error);

            error = builder.Build();

            // assert
            Assert.Equal("123", error.Message);
            Assert.Collection(error.Locations,
                              t => Assert.Equal(1, t.Line));
        }
Esempio n. 9
0
        public void FromError_WithExtensions()
        {
            // arrange
            IError error = new Error
            {
                Message    = "123",
                Extensions = ImmutableDictionary <string, object>
                             .Empty
                             .Add("foo", "bar")
            };

            // act
            ErrorBuilder builder = ErrorBuilder.FromError(error);

            error = builder.Build();

            // assert
            Assert.Equal("123", error.Message);
            Assert.Collection(error.Extensions,
                              t => Assert.Equal("bar", t.Value));
        }
Esempio n. 10
0
        public void FromError_RemoveExtension()
        {
            // arrange
            IError error = new Error
            {
                Message    = "123",
                Extensions = new OrderedDictionary <string, object>
                {
                    { "foo", "bar" },
                    { "bar", "foo" }
                }
            };

            // act
            error = ErrorBuilder.FromError(error)
                    .RemoveExtension("bar")
                    .Build();

            // assert
            Assert.Equal("123", error.Message);
            Assert.Collection(error.Extensions,
                              t => Assert.Equal("bar", t.Value));
        }