Ejemplo n.º 1
0
        public void ValidateSparql(string endpointName)
        {
            string key = endpointName
                         .Remove(endpointName.Length - 5, 5)
                         .Remove(0, 1);
            OpenApiPathItem endpoint     = Resources.GetApiPathItem(key);
            EndpointType    endpointType = Resources.GetEndpointType(endpoint);

            if (endpointType == EndpointType.HardCoded)
            {
                return;
            }

            var queryString = Resources.GetSparql(key);
            var query       = new SparqlParameterizedString(queryString);

            query.SetUri("schemaUri", new Uri("http://example.com"));
            query.SetUri("instanceUri", new Uri("http://example.com"));

            OpenApiParameter[] parameters = Resources.GetSparqlParameters(endpoint).ToArray();
            if (parameters.Any())
            {
                var values = parameters.ToDictionary(
                    parameter => parameter.Name,
                    parameter =>
                {
                    switch (Resources.GetParameterType(parameter))
                    {
                    case ParameterType.Uri:
                        return("http://example.com");

                    case ParameterType.Literal:
                        if (parameter?.Example?.GetType() == typeof(Microsoft.OpenApi.Any.OpenApiInteger))
                        {
                            return("0");
                        }
                        else
                        {
                            return("EXAMPLE");
                        }

                    default:
                        return("EXAMPLE");
                    }
                });

                FixedQueryController.SetParameters(query, parameters, values);
            }

            var validator = new SparqlQueryValidator();
            var result    = validator.Validate(query.ToString());

            Assert.IsTrue(result.IsValid, result.Message);
        }
Ejemplo n.º 2
0
        public void ValidateSparql(string endpointName)
        {
            var endpoint = Resources.DB.Endpoints[endpointName];

            if (endpoint.Type == EndpointType.HardCoded)
            {
                return;
            }

            var queryString = Resources.GetSparql(endpointName);
            var query       = new SparqlParameterizedString(queryString);

            query.SetUri("schemaUri", new Uri("http://example.com"));

            if (endpoint.Parameters != null)
            {
                var values = endpoint.Parameters.ToDictionary(
                    parameter => parameter.Key,
                    parameter =>
                {
                    switch (parameter.Value)
                    {
                    case ParameterType.Uri:
                        return("http://example.com");

                    default:
                        return("EXAMPLE");
                    }
                });

                FixedQueryController.SetParameters(query, endpoint.Parameters, values);
            }

            var validator = new SparqlQueryValidator();
            var result    = validator.Validate(query.ToString());

            Assert.IsTrue(result.IsValid, result.Message);
        }