private void Test_correctness_of_query(int queryIndex)
        {
            Tuple <System.Linq.IQueryable <IPerson>, string, string, string, string, string, string> query = _testQueries[queryIndex];
            string computedCommandText            = string.Empty;
            string computedMetaGraphVariableName  = string.Empty;
            string computedEntityVariableName     = string.Empty;
            string computedSubjectVariableName    = string.Empty;
            string computedPredicateVariableName  = string.Empty;
            string computedObjectVariableName     = string.Empty;
            IEnumerable <EntityId> actualEntities = new HashSet <EntityId>();

            _entitySource.Setup(e => e.ExecuteEntityQuery(It.IsAny <Query>(), out actualEntities)).Returns <Query, IEnumerable <EntityId> >((model, resultingEntities) =>
            {
                GenericSparqlQueryVisitor visitor = VisitModel(model);
                computedCommandText           = visitor.CommandText;
                computedMetaGraphVariableName = visitor.Variables.MetaGraph;
                computedEntityVariableName    = visitor.Variables.Entity;
                computedSubjectVariableName   = visitor.Variables.Subject;
                computedPredicateVariableName = visitor.Variables.Predicate;
                computedObjectVariableName    = visitor.Variables.Object;
                resultingEntities             = actualEntities;
                return(GetSamplePersonTriples(5));
            });

            query.Item1.ToList();
            computedCommandText = Regex.Replace(computedCommandText, @"\s+", string.Empty).Trim();
            var expectedText = Regex.Replace(query.Item2, @"\s+", string.Empty).Trim();

            Assert.That(computedCommandText, Is.EqualTo(expectedText));
            Assert.That(computedMetaGraphVariableName, Is.EqualTo(query.Item3));
            Assert.That(computedEntityVariableName, Is.EqualTo(query.Item4));
            Assert.That(computedSubjectVariableName, Is.EqualTo(query.Item5));
            Assert.That(computedPredicateVariableName, Is.EqualTo(query.Item6));
            Assert.That(computedObjectVariableName, Is.EqualTo(query.Item7));
        }
        protected GenericSparqlQueryVisitor VisitModel(Query queryModel)
        {
            GenericSparqlQueryVisitor visitor = new GenericSparqlQueryVisitor();

            visitor.MetaGraphUri = new Uri("http://app.magi/graphs");
            visitor.VisitQuery(queryModel);
            return(visitor);
        }
        /// <inheritdoc />
        public virtual SparqlQuery GetSparqlQuery(IQuery sparqlQuery, out SparqlQueryVariables variables)
        {
            GenericSparqlQueryVisitor queryVisitor = new GenericSparqlQueryVisitor()
            {
                MetaGraphUri = MetaGraphUri
            };

            queryVisitor.VisitQuery(sparqlQuery);
            variables = queryVisitor.Variables;
            SparqlQueryParser parser = new SparqlQueryParser();

            return(parser.ParseFromString(queryVisitor.CommandText));
        }