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); }
public void FromError_ErrorNull_ArgumentNullException() { // arrange // act Action action = () => ErrorBuilder.FromError(null); // assert Assert.Throws <ArgumentNullException>(action); }
public void FromError() { // arrange IError error = new Error("123"); // act error = ErrorBuilder.FromError(error).Build(); // assert Assert.Equal("123", error.Message); }
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); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }