Inheritance: IGremlinQuery
 public void DebugQueryTextShouldReturnExpandedText()
 {
     var gremlinQuery = new GremlinQuery(
         null,
         "g[p0][p1][p2][p3][p4][p5][p6][p7][p8][p9][p10][p11]",
         new Dictionary<string, object>
         {
             { "p0", "val00" },
             { "p1", "val01" },
             { "p2", "val02" },
             { "p3", "val03" },
             { "p4", "val04" },
             { "p5", "val05" },
             { "p6", "val06" },
             { "p7", "val07" },
             { "p8", "val08" },
             { "p9", "val09" },
             { "p10", "val10" },
             { "p11", "val11" },
         },
         null);
     var enumerable = new GremlinNodeEnumerable<object>(gremlinQuery);
     Assert.AreEqual(
         "g['val00']['val01']['val02']['val03']['val04']['val05']['val06']['val07']['val08']['val09']['val10']['val11']",
         enumerable.DebugQueryText);
 }
 public void FormatGremlinFilterShouldReturnEmptyStringForNoCaseSensititiveFilters()
 {
     var filters = new List<Filter>();
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.Ordinal, baseQuery);
     Assert.AreEqual(string.Empty, filter.FilterText);
 }
        public void MoveNextShouldReturnFalseAfterLastRecordOnFirstPageIfThereAreNoFurtherPages()
        {
            var pages = new Queue<IEnumerable<int>>(new[]
            {
                Enumerable.Range(0, 100),
                Enumerable.Empty<int>()
            });

            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<int>> loadCallback =
                q => { loadedQueries.Add(q); return pages.Dequeue(); };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);

            var enumerator = new GremlinPagedEnumerator<int>(loadCallback, baseQuery);

            for (var i = 0; i < 100; i++)
                enumerator.MoveNext();

            Assert.IsFalse(enumerator.MoveNext());
        }
 public void FormatGremlinFilterShouldReturnIndexerSyntaxForSingleCaseInsensititiveGreaterThanFilterWithLongValue()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = long.MaxValue, ExpressionType = ExpressionType.GreaterThan},
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.OrdinalIgnoreCase, baseQuery);
     Assert.AreEqual(".filter{ it[p0] > p1 }", filter.FilterText);
     Assert.AreEqual("Foo", filter.FilterParameters["p0"]);
     Assert.AreEqual(9223372036854775807, filter.FilterParameters["p1"]);
 }
 public void FormatGremlinFilterShouldReturnIndexerSyntaxForSingleCaseSensititiveEqualFilterWithIntValue()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = 123, ExpressionType = ExpressionType.Equal  }
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.Ordinal, baseQuery);
     Assert.AreEqual(".filter{ it[p0] == p1 }", filter.FilterText);
     Assert.AreEqual("Foo", filter.FilterParameters["p0"]);
     Assert.AreEqual(123, filter.FilterParameters["p1"]);
 }
        public void FormatGremlinFilterShouldSupportGuidTypeInNotEqualsExpression()
        {
            const string guidString = "1a4e451c-aa87-4388-9b53-5d00b05ac728";
            var guidValue = Guid.Parse(guidString);

            var filters = new List<Filter>
            {
                new Filter { PropertyName= "Foo", Value = guidValue, ExpressionType = ExpressionType.NotEqual  }
            };
            var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
            var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.Ordinal, baseQuery);
            Assert.AreEqual(".filter{ it[p0] != p1 }", filter.FilterText);
            Assert.AreEqual("Foo", filter.FilterParameters["p0"]);
            Assert.AreEqual(guidString, filter.FilterParameters["p1"].ToString());
        }
 public void FormatGremlinFilterShouldReturnIndexerSyntaxForMultipleCaseSensititiveEqualFiltersWithStringValues()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = "Bar", ExpressionType = ExpressionType.Equal  },
         new Filter { PropertyName= "Baz", Value = "Qak", ExpressionType = ExpressionType.Equal  }
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.Ordinal, baseQuery);
     Assert.AreEqual(".filter{ it[p0].equals(p1) && it[p2].equals(p3) }", filter.FilterText);
     Assert.AreEqual("Foo", filter.FilterParameters["p0"]);
     Assert.AreEqual("Bar", filter.FilterParameters["p1"]);
     Assert.AreEqual("Baz", filter.FilterParameters["p2"]);
     Assert.AreEqual("Qak", filter.FilterParameters["p3"]);
 }
        public void ShouldNotLoadAnythingUntilEnumerated()
        {
            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<object>> loadCallback =
                q => { loadedQueries.Add(q); return new object[0]; };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);
            
            new GremlinPagedEnumerator<object>(loadCallback, baseQuery);

            Assert.AreEqual(0, loadedQueries.Count());
        }
        public void MoveNextShouldReturnFalseOnFirstCallIfThereAreNoResults()
        {
            var results = new int[0];

            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<int>> loadCallback =
                q => { loadedQueries.Add(q); return results; };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);

            var enumerator = new GremlinPagedEnumerator<int>(loadCallback, baseQuery);
            Assert.IsFalse(enumerator.MoveNext());
        }
        public void ShouldLoadFirstPageOfResultsWithFirstEnumeration()
        {
            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<object>> loadCallback =
                q => { loadedQueries.Add(q); return new object[0]; };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);

            var enumerator = new GremlinPagedEnumerator<object>(loadCallback, baseQuery);
            enumerator.MoveNext();

            Assert.AreEqual(1, loadedQueries.Count());
            Assert.AreEqual("g.v(p0).outV.drop(p1).take(p2)._()", loadedQueries[0].QueryText);
            Assert.AreEqual(0, loadedQueries[0].QueryParameters["p1"]);
            Assert.AreEqual(100, loadedQueries[0].QueryParameters["p2"]);
        }
        public void ShouldEnumerateOverFirstPageOfResults()
        {
            var results = Enumerable.Range(0, 100).ToArray();

            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<int>> loadCallback =
                q => { loadedQueries.Add(q); return results; };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);

            var enumerator = new GremlinPagedEnumerator<int>(loadCallback, baseQuery);
            for (var i = 0; i < 100; i++)
            {
                Assert.IsTrue(enumerator.MoveNext());
                Assert.AreEqual(results[i], enumerator.Current);
            }
        }
        public void ShouldLoadSecondPageWhenCallingMoveNextAfterLastRecordOfFirstPage()
        {
            var results = Enumerable.Range(0, 100).ToArray();

            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<int>> loadCallback =
                q => { loadedQueries.Add(q); return results; };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);

            var enumerator = new GremlinPagedEnumerator<int>(loadCallback, baseQuery);
            for (var i = 0; i < 100; i++)
            {
                enumerator.MoveNext();
            }

            enumerator.MoveNext();

            Assert.AreEqual(2, loadedQueries.Count());
            Assert.AreEqual("g.v(p0).outV.drop(p1).take(p2)._()", loadedQueries[0].QueryText);
            Assert.AreEqual(0, loadedQueries[0].QueryParameters["p1"]);
            Assert.AreEqual(100, loadedQueries[0].QueryParameters["p2"]);
            Assert.AreEqual("g.v(p0).outV.drop(p1).take(p2)._()", loadedQueries[1].QueryText);
            Assert.AreEqual(100, loadedQueries[1].QueryParameters["p1"]);
            Assert.AreEqual(100, loadedQueries[1].QueryParameters["p2"]);
        }
 public void FormatGremlinFilterShouldThrowNotSupportedExceptionForExpressionsThatAreNotRegisteredInFilterTypesToCompareNulls()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = null, ExpressionType = ExpressionType.Divide },
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     FilterFormatters.FormatGremlinFilter(filters, StringComparison.OrdinalIgnoreCase, baseQuery);
 }
 public void FormatGremlinFilterShouldThrowNotSupportedExceptionForCaseInsensitiveEqualFilterOfUnsupportedType()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = new ThreadStaticAttribute(), ExpressionType = ExpressionType.Equal  },
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     FilterFormatters.FormatGremlinFilter(filters, StringComparison.OrdinalIgnoreCase, baseQuery);
 }
 public void FormatGremlinFilterShouldReturnIndexerSyntaxForSingleCaseInsensititiveNotEqualFilterWithEnumValue()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = EnumForTesting.Bar, ExpressionType = ExpressionType.NotEqual  }
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.OrdinalIgnoreCase, baseQuery);
     Assert.AreEqual(".filter{ !it[p0].equalsIgnoreCase(p1) }", filter.FilterText);
     Assert.AreEqual("Foo", filter.FilterParameters["p0"]);
     Assert.AreEqual("Bar", filter.FilterParameters["p1"]);
 }
 public void FormatGremlinFilterShouldReturnIteratorSyntaxForSingleCaseSensititiveNotEqualFilterMaxLongValue()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName = "Foo", Value = 9223372036854775807, ExpressionType = ExpressionType.NotEqual },
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var filter = FilterFormatters.FormatGremlinFilter(filters, StringComparison.Ordinal, baseQuery);
     Assert.AreEqual(".filter{ it[p0] != p1 }", filter.FilterText);
     Assert.AreEqual("Foo", filter.FilterParameters["p0"]);
     Assert.AreEqual(9223372036854775807, filter.FilterParameters["p1"]);
 }
Exemplo n.º 17
0
 public void FormatGremlinFilterShouldThrowNotSupportedExceptionForCaseSensitiveEqualFilterOfUnsupportedType()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = new ThreadStaticAttribute(), ExpressionType = ExpressionType.Equal  },
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var ex = Assert.Throws<NotSupportedException>(() => FilterFormatters.FormatGremlinFilter(filters, StringComparison.Ordinal, baseQuery));
     Assert.AreEqual("One or more of the supplied filters is of an unsupported type or expression. Unsupported filters were: Foo of type System.ThreadStaticAttribute, with expression Equal", ex.Message);
 }
Exemplo n.º 18
0
 public void FormatGremlinFilterShouldThrowNotSupportedExceptionForExpressionsThatAreNotRegisteredInFilterTypesToCompareNulls()
 {
     var filters = new List<Filter>
     {
         new Filter { PropertyName= "Foo", Value = null, ExpressionType = ExpressionType.Divide },
     };
     var baseQuery = new GremlinQuery(null, null, new Dictionary<string, object>(), new List<string>());
     var ex = Assert.Throws<NotSupportedException>(() => FilterFormatters.FormatGremlinFilter(filters, StringComparison.OrdinalIgnoreCase, baseQuery));
     Assert.AreEqual("One or more of the supplied filters is of an unsupported type or expression. Unsupported filters were: Foo with null value and expression Divide", ex.Message);
 }
        public void ShouldEnumerateOverMultiplePagesOfResults(int pageCount)
        {
            var pages = new Queue<IEnumerable<int>>();
            for (var pageIndex = 0; pageIndex < pageCount; pageIndex++)
            {
                pages.Enqueue(Enumerable.Range(pageIndex * 100, 100));
            }

            var loadedQueries = new List<IGremlinQuery>();
            Func<IGremlinQuery, IEnumerable<int>> loadCallback =
                q => { loadedQueries.Add(q); return pages.Dequeue(); };

            var baseQuery = new GremlinQuery(
                null,
                "g.v(p0).outV",
                new Dictionary<string, object> { { "p0", 0 } },
                null);

            var enumerator = new GremlinPagedEnumerator<int>(loadCallback, baseQuery);
            for (var i = 0; i < pageCount * 100; i++)
            {
                Assert.IsTrue(enumerator.MoveNext());
                Assert.AreEqual(i, enumerator.Current);
            }
        }