public CypherExtensionTestHelper SetupGraphClient()
 {
     GraphClient = new Mock<IRawGraphClient>();
     GraphClient.Setup(x => x.JsonContractResolver).Returns(new DefaultContractResolver());
     Query = new CypherFluentQuery(GraphClient.Object);
     return this;
 }
        public void UsesJsonPropertyNameOverPropertyName()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client).Where((FooWithJsonProperties foo) => foo.Bar == "Bar").Query;

            Assert.AreEqual("WHERE (foo.bar = {p0})", query.QueryText);
        }
        public void ExecutingQueryMultipleTimesShouldResetParameters()
        {
            var client = Substitute.For<IRawGraphClient>();

            client
                .ExecuteGetCypherResults<ReturnPropertyQueryResult>(Arg.Any<CypherQuery>())
                .Returns(Enumerable.Empty<ReturnPropertyQueryResult>());

            var cypher = new CypherFluentQuery(client);
            var query1 = cypher
                .Start("a", (NodeReference)1)
                .Return<object>("a.Name")
                .Query;

            Assert.AreEqual(1, query1.QueryParameters.Count());
            Assert.AreEqual(1, query1.QueryParameters["p0"]);

            var query2 = cypher
                .Start("b", (NodeReference)2)
                .Return<object>("a.Name")
                .Query;

            Assert.AreEqual(1, query2.QueryParameters.Count());
            Assert.AreEqual(2, query2.QueryParameters["p0"]);
        }
        public void ThrowsExceptionWhenUriIsNull()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client);

            Assert.Throws<ArgumentException>(() => query.LoadCsv(null, "row"));
        }
        public void ComplexObjectInWithParam()
        {
            // Arrange
            var client = Substitute.For<IRawGraphClient>();

            // Act
            var query = new CypherFluentQuery(client)
                .Start("n", (NodeReference) 3)
                .CreateUnique("n-[:X]-(leaf {obj})")
                .WithParam("obj", new ComplexObjForWithParamTest
                                  {
                                      Id = 123,
                                      Name = "Bar",
                                      Currency = (decimal) 12.143
                                  })
                .Query;

            // Assert
            Assert.AreEqual("START n=node(3)" +
                            "\r\nCREATE UNIQUE n-[:X]-(leaf {" +
                            "\r\n  \"Id\": 123," +
                            "\r\n  \"Name\": \"Bar\"," +
                            "\r\n  \"Currency\": 12.143" +
                            "\r\n})", query.DebugQueryText);
            Assert.AreEqual(2, query.QueryParameters.Count);
        }
        public void MultipleMatchClausesWithPairedWhereClauses()
        {
            // MATCH (n)
            // WHERE n.Foo = {p0}
            // OPTIONAL MATCH (n)--(x)
            // WHERE x.Bar = {p1}
            // OPTIONAL MATCH (x)--(a)
            // WHERE a.Baz = {p2}
            // RETURN n, x

            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Match("(n)")
                .Where((FooBarBaz n) => n.Foo == "abc")
                .OptionalMatch("(n)--(x)")
                .Where((FooBarBaz x) => x.Bar == "def")
                .OptionalMatch("(x)--(a)")
                .Where((FooBarBaz a) => a.Baz == "ghi")
                .Query;

            const string expected = "MATCH (n)\r\nWHERE (n.Foo = {p0})\r\nOPTIONAL MATCH (n)--(x)\r\nWHERE (x.Bar = {p1})\r\nOPTIONAL MATCH (x)--(a)\r\nWHERE (a.Baz = {p2})";

            Assert.AreEqual(expected, query.QueryText);
            Assert.AreEqual(3, query.QueryParameters.Count());
        }
        public void ThrowsInvalidOperationException_WhenClientVersionIsLessThan_30()
        {
            var client = GraphClient_30;
            client.CypherCapabilities.Returns(CypherCapabilities.Cypher23);

            Assert.Throws<InvalidOperationException>(() => { var query = new CypherFluentQuery(client).Yield("uuid").Query; });
        }
 public void ThrowArgumentException_WhenNoStoredProcedureIsGiven()
 {
     var client = GraphClient_30;
     Assert.Throws<ArgumentException>(() =>
     {
         var query = new CypherFluentQuery(client).Yield(null).Query;
     });
 }
 public void ThrowInvalidOperationException_WhenAttemptingToDeleteProperty()
 {
     var client = GraphClient_230;
     var query = new CypherFluentQuery(client)
         .DetachDelete("andres.age")
         .Return<Node<object>>("andres")
         .Query;
 }
        public void YieldsGivenText()
        {
            var client = GraphClient_30;
            var query = new CypherFluentQuery(client)
                .Yield("uuid")
                .Query;

            Assert.AreEqual("YIELD uuid", query.QueryText);
        }
        public void ShouldReturnCountOnItsOwn()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(item => item.Count())
                .Query;

            Assert.AreEqual("WITH count(item)", query.QueryText);
        }
        public void ThrowsInvalidOperationException_WhenNeo4jVersionIsLessThan22()
        {
            var client = Substitute.For<IRawGraphClient>();
            client.CypherCapabilities.Returns(CypherCapabilities.Cypher19);

            var _ = new CypherFluentQuery(client)
                .Planner("FreePlanner")
                .Query;
        }
        public void ShouldReturnCustomFunctionCall()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(() => new { baz = "sum(foo.bar)" })
                .Query;

            Assert.AreEqual("WITH sum(foo.bar) AS baz", query.QueryText);
        }
        public void ShouldReturnSpecificPropertyOnItsOwn()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(a => a.As<Commodity>().Name)
                .Query;

            Assert.AreEqual("WITH a.Name", query.QueryText);
        }
        public void ShouldTranslateAnonymousObjectWithImplicitPropertyNames()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(a => new { a })
                .Query;

            Assert.AreEqual("WITH a", query.QueryText);
        }
        public void CallsStoredProcedureGiven()
        {
            var client = GraphClient_30;
            var query = new CypherFluentQuery(client)
                .Call("apoc.sp()")
                .Query;

            Assert.AreEqual("CALL apoc.sp()", query.QueryText);
        }
        public void TestUnwindConstruction()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Unwind("collection", "column")
                .Query;

            Assert.AreEqual("UNWIND collection AS column", query.QueryText);
        }
        public void ShouldReturnSpecificPropertyTakingIntoAccountJsonProperty()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(a => a.As<Cypher.FooWithJsonProperties>().Bar)
                .Query;

            Assert.AreEqual("WITH a.bar", query.QueryText);
        }
        public void TestLoadCsvWithHeadersAndCustomFieldTerminator()
        {
            const string expected = "LOAD CSV WITH HEADERS FROM 'file://localhost/c:/foo/bar.csv' AS row FIELDTERMINATOR '|'";
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .LoadCsv(new Uri("file://localhost/c:/foo/bar.csv"), "row", true, "|")
                .Query;

            Assert.AreEqual(expected, query.QueryText);
        }
        public void TestLoadCsvConstruction()
        {
            const string expected = "LOAD CSV FROM 'file://localhost/c:/foo/bar.csv' AS row";
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .LoadCsv(new Uri("file://localhost/c:/foo/bar.csv"), "row")
                .Query;

            Assert.AreEqual(expected, query.QueryText);
        }
        public void TestUnwindAfterWithTResultVariant()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(collection => new { collection })
                .Unwind("collection", "column")
                .Query;

            Assert.AreEqual("WITH collection\r\nUNWIND collection AS column", query.QueryText);
        }
Exemplo n.º 22
0
        public void Union()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Union()
                .Query;

            Assert.AreEqual("UNION", query.QueryText);
            Assert.AreEqual(0, query.QueryParameters.Count());
        }
        public void TestLoadCsvAfterWithTResultVariant()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .With(n => new {n})
                .LoadCsv(new Uri("file://localhost/c:/foo/bar.csv"), "row")
                .Query;

            Assert.AreEqual("WITH n\r\nLOAD CSV FROM 'file://localhost/c:/foo/bar.csv' AS row", query.QueryText);
        }
Exemplo n.º 24
0
        public void CountDistinct()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Return(n => new { Foo = n.CountDistinct() })
                .Query;

            Assert.AreEqual("RETURN count(distinct n) AS Foo", query.QueryText);
            Assert.AreEqual(0, query.QueryParameters.Count());
        }
        public void ShouldReturnSpecificPropertyOnItsOwnCamelAs()
        {
            var client = Substitute.For<IRawGraphClient>();
            client.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
            var query = new CypherFluentQuery(client)
                .With(a => new Commodity(){ Name = a.As<Commodity>().Name})
                .Query;

            Assert.AreEqual("WITH a.name? AS Name", query.QueryText);
        }
        public void UsingEmptyIndexIsInvalid(string index)
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Match("(foo:Bar { id: 123 })")
                .UsingIndex(index)
                .Return(foo => new { qux = foo.As<object>() } )
                .Query;

        }
        public void ComparePropertiesAcrossEntitiesNotEqual()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Where<Foo, Foo>((a, b) => a.Bar != b.Bar)
                .Query;

            Assert.AreEqual("WHERE (a.Bar <> b.Bar)", query.QueryText);
            Assert.AreEqual(0, query.QueryParameters.Count);
        }
        public void BinaryExpressionIsNull()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Match("(a)")
                .Return(a => new { IsNull = a == null })
                .Query;

            Assert.AreEqual("MATCH (a)\r\nRETURN a IS NULL AS IsNull", query.QueryText);
        }
        public void DeleteIdentifier()
        {
            var client = GraphClient_230;
            var query = new CypherFluentQuery(client)
                .Match("n")
                .DetachDelete("n")
                .Query;

            Assert.AreEqual("MATCH n\r\nDETACH DELETE n", query.QueryText);
        }
        public void NestOrAndAndCorrectly()
        {
            var client = Substitute.For<IRawGraphClient>();
            var query = new CypherFluentQuery(client)
                .Where((Foo a, Foo b) => a.Bar == 123 || b.Bar == 456)
                .AndWhere((Foo c) => c.Bar == 789)
                .Query;

            Assert.AreEqual("WHERE ((a.Bar = {p0}) OR (b.Bar = {p1}))\r\nAND (c.Bar = {p2})", query.QueryText);
            Assert.AreEqual(3, query.QueryParameters.Count);
        }
Exemplo n.º 31
0
            public void SerializesTimeSpanCorrectly()
            {
                var ts = new TimeSpan(1, 2, 3, 4, 5);
                
                var query = new CypherFluentQuery(MockGc.Object)
                    .WithParam("tsParam", ts);

                var actual = query.Query.ToNeo4jDriverParameters(MockGc.Object);
                actual.Keys.Should().Contain("tsParam");
                var tsParam = actual["tsParam"].ToString();
                tsParam.Should().Be("1.02:03:04.0050000");
            }
Exemplo n.º 32
0
        public void SetClient_TResult()
        {
            var client1 = Substitute.For <IRawGraphClient>();
            var client2 = Substitute.For <IRawGraphClient>();

            var query = new CypherFluentQuery(client1).Match("(n)").Return(n => n.Count());

            Assert.Same(((CypherFluentQuery)query).Client, client1);

            query = query.Advanced.SetClient <long>(client2);
            Assert.Same(((CypherFluentQuery)query).Client, client2);
        }
Exemplo n.º 33
0
        public void SetsTheIdentifer_WhenValid()
        {
            const string identifier = "MyQuery";
            var          mockGc     = new Mock <IRawGraphClient>();

            var cfq = new CypherFluentQuery(mockGc.Object);

            cfq.WithIdentifier(identifier);
            var query = cfq.Query;

            query.Identifier.Should().Be(identifier);
        }
Exemplo n.º 34
0
        public void SetClient()
        {
            var client1 = Substitute.For <IRawGraphClient>();
            var client2 = Substitute.For <IRawGraphClient>();

            var query = new CypherFluentQuery(client1).Match("(n)");

            Assert.Same(((CypherFluentQuery)query).Client, client1);

            query = query.Advanced.SetClient(client2);
            Assert.Same(((CypherFluentQuery)query).Client, client2);
        }
        public void ShouldUseProjectionResultModeForNamedObjectReturnWithConcreteProperties()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .With(a => new ProjectionResult
            {
                Commodity = a.As <Commodity>()
            })
                         .Query;

            Assert.Equal("WITH a AS Commodity", query.QueryText);
        }
        public void ShouldUseProjectionResultModeForNamedObjectReturnWithICypherResultItems()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .With(a => new CypherProjectionResult
            {
                Foo = a
            })
                         .Query;

            Assert.Equal("WITH a AS Foo", query.QueryText);
        }
        public void OrWhereIfFalseCamel()
        {
            var client = Substitute.For <IRawGraphClient>();

            client.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
            var query = new CypherFluentQuery(client)
                        .Where((FooCamel a, FooCamel b) => a.LongBar == 123 || b.Bar == 456)
                        .OrWhereIf(11 == 12, (FooCamel c) => c.B == 789)
                        .Query;

            Assert.Equal("WHERE ((a.longBar = $p0) OR (b.bar = $p1))", query.QueryText);
            Assert.Equal(2, query.QueryParameters.Count);
        }
        public void RemoveLabel()
        {
            // Arrange
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Match("n")
                         .Remove("n:Person")
                         .Return <Node <Object> >("n")
                         .Query;

            // Assert
            Assert.Equal("MATCH n" + Environment.NewLine + "REMOVE n:Person" + Environment.NewLine + "RETURN n", query.QueryText);
        }
Exemplo n.º 39
0
        public void MergeOnCreate()
        {
            // Arrange
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Merge("(robert:Person)")
                         .OnCreate()
                         .Set("robert.Created = timestamp()")
                         .Query;

            // Assert
            Assert.Equal("MERGE (robert:Person)" + Environment.NewLine + "ON CREATE" + Environment.NewLine + "SET robert.Created = timestamp()", query.QueryText);
        }
Exemplo n.º 40
0
        public void ForEachRawText()
        {
            // http://docs.neo4j.org/chunked/milestone/query-foreach.html
            // FOREACH (n IN nodes(p) | SET n.marked = TRUE)

            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .ForEach("(n IN nodes(p) | SET n.marked = TRUE)")
                         .Query;

            Assert.Equal("FOREACH (n IN nodes(p) | SET n.marked = TRUE)", query.QueryText);
            Assert.Equal(0, query.QueryParameters.Count);
        }
        public void ReturnWithLimit()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Start("n", (NodeReference)3)
                         .Return <object>("n")
                         .Limit(5)
                         .Query;

            Assert.AreEqual("START n=node({p0})\r\nRETURN n\r\nLIMIT {p1}", query.QueryText);
            Assert.AreEqual(3, query.QueryParameters["p0"]);
            Assert.AreEqual(5, query.QueryParameters["p1"]);
        }
Exemplo n.º 42
0
        public void DropIndex()
        {
            // http://docs.neo4j.org/chunked/milestone/query-schema-index.html#schema-index-drop-index-on-a-label
            // DROP INDEX ON :Person(name)

            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Drop("INDEX ON :Person(name)")
                         .Query;

            Assert.Equal("DROP INDEX ON :Person(name)", query.QueryText);
            Assert.Equal(0, query.QueryParameters.Count);
        }
Exemplo n.º 43
0
        public void NestOrAndAndCorrectlyCamel()
        {
            var client = Substitute.For <IRawGraphClient>();

            client.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
            var query = new CypherFluentQuery(client)
                        .Where((FooCamel a, FooCamel b) => a.LongBar == 123 || b.Bar == 456)
                        .AndWhere((FooCamel c) => c.B == 789)
                        .Query;

            Assert.AreEqual("WHERE ((a.longBar = {p0}) OR (b.bar = {p1}))\r\nAND (c.b = {p2})", query.QueryText);
            Assert.AreEqual(3, query.QueryParameters.Count);
        }
        public void ThrowsInvalidOperationException_WhenNeo4jVersionIsLessThan22()
        {
            var client = Substitute.For <IRawGraphClient>();

            client.CypherCapabilities.Returns(CypherCapabilities.Cypher19);

            Assert.Throws <InvalidOperationException>(() =>
            {
                var _ = new CypherFluentQuery(client)
                        .Planner("FreePlanner")
                        .Query;
            });
        }
Exemplo n.º 45
0
        public void CountAll()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Return(() => new
            {
                Foo = All.Count()
            })
                         .Query;

            Assert.AreEqual("RETURN count(*) AS Foo", query.QueryText);
            Assert.AreEqual(0, query.QueryParameters.Count());
        }
Exemplo n.º 46
0
        public async Task <IEnumerable <Violation> > GetUserViolations(Guid userId)
        {
            var relationship = new UserViolationRelationship("user", "violation");
            var query        = new CypherFluentQuery(_graphClientFunc)
                               .Match("(user:User{azureId: {userId}})")
                               .WithParam("userId", userId)
                               .MatchRelationship(relationship)
                               .Return(violation => violation.As <Violation>());

            var results = await _repositoryPolicy.ExecuteAsync(async() => await query.ResultsAsync);

            return(results);
        }
        public void SetWithoutReturn()
        {
            // Arrange
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Start("n", (NodeReference)3)
                         .Set("n.name = \"Ted\"")
                         .Query;

            // Assert
            Assert.AreEqual("START n=node({p0})\r\nSET n.name = \"Ted\"", query.QueryText);
            Assert.AreEqual(3, query.QueryParameters["p0"]);
        }
Exemplo n.º 48
0
        public void AllowDeleteClauseAfterWhere()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Start("n", (NodeReference)3)
                         .Where("(...)")
                         .Delete("n")
                         .Query;

            // Assert
            Assert.Equal("START n=node({p0})\r\nWHERE (...)\r\nDELETE n", query.QueryText);
            Assert.Equal(3L, query.QueryParameters["p0"]);
        }
Exemplo n.º 49
0
        public void MergeOnMatch()
        {
            // Arrange
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Merge("(robert:Person)")
                         .OnMatch()
                         .Set("robert.LastSeen = timestamp()")
                         .Query;

            // Assert
            Assert.Equal("MERGE (robert:Person)\r\nON MATCH\r\nSET robert.LastSeen = timestamp()", query.QueryText);
        }
        public void ShouldUseProjectionResultModeForNamedObjectReturnCamel()
        {
            var client = Substitute.For <IRawGraphClient>();

            client.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
            var query = new CypherFluentQuery(client)
                        .Return(a => new ProjectionResult {
                Commodity = a.As <Commodity>()
            })
                        .Query;

            Assert.Equal(CypherResultMode.Projection, query.ResultMode);
        }
Exemplo n.º 51
0
        public async Task SaveAlert(Alert alert, Guid transportationId)
        {
            alert.CreatedAt = (float)DateTime.UtcNow.Subtract(DateTime.MinValue.AddYears(1969)).TotalSeconds;
            alert.AlertId   = Guid.NewGuid();
            var relationship = new TransportationAlertRelationship("transportation", "alert");
            var query        = new CypherFluentQuery(_graphClientFunc)
                               .Match("(transportation:Transportation{transportationId: {transportationId}})")
                               .WithParam("transportationId", transportationId)
                               .CreateEntity(alert, "alert")
                               .CreateRelationship(relationship);

            await _repositoryPolicy.ExecuteAsync(async() => await query.ExecuteWithoutResultsAsync());
        }
        public void SetProperty()
        {
            // Arrange
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Match("n")
                         .Set("n.age = 30")
                         .Return <Node <Object> >("n")
                         .Query;

            // Assert
            Assert.Equal("MATCH n" + Environment.NewLine + "SET n.age = 30" + Environment.NewLine + "RETURN n", query.QueryText);
        }
        public void ReturnWithLimit()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Match("n")
                         .Return <object>("n")
                         .Limit(5)
                         .Query;

            Assert.Equal("MATCH n" + Environment.NewLine + "RETURN n" + Environment.NewLine + "LIMIT $p0", query.QueryText);
            Assert.Equal(5, query.QueryParameters["p0"]);
            Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
        }
        public void SetsBookmark_InQuery()
        {
            const string bookmarkName = "Bookmark1";
            var          mockGc       = new Mock <IRawGraphClient>();

            var cfq = new CypherFluentQuery(mockGc.Object);

            cfq.WithBookmark(bookmarkName);
            var query = cfq.Query;

            query.Bookmarks.Should().HaveCount(1);
            query.Bookmarks.SelectMany(b => b.Values).Should().Contain(bookmarkName);
        }
        public void DoesNothing_WhenBookmarkIsWhitespaceOrNull_ForBookmarks(string bookmark)
        {
            var mockGc = new Mock <IRawGraphClient>();
            var list   = new List <string> {
                bookmark
            };
            var cfq = new CypherFluentQuery(mockGc.Object);

            cfq.WithBookmarks(list.ToArray());
            var query = cfq.Query;

            query.Bookmarks.Should().HaveCount(0);
        }
Exemplo n.º 56
0
        public void CountUsingICypderFluentQuery()
        {
            var client = Substitute.For <IRawGraphClient>();
            ICypherFluentQuery query = new CypherFluentQuery(client);

            var resultQuery =
                query.Return(() => new { Foo = All.Count() })
                .Query;

            Assert.AreEqual("RETURN count(*) AS Foo", resultQuery.QueryText);
            Assert.AreEqual(0, resultQuery.QueryParameters.Count());
            Assert.AreEqual(CypherResultFormat.DependsOnEnvironment, resultQuery.ResultFormat);
        }
Exemplo n.º 57
0
        public void UsingEmptyIndexIsInvalid(string index)
        {
            var client = Substitute.For <IRawGraphClient>();

            Assert.Throws <ArgumentException>(() =>
            {
                var query = new CypherFluentQuery(client)
                            .Match("(foo:Bar { id: 123 })")
                            .UsingIndex(index)
                            .Return(foo => new { qux = foo.As <object>() })
                            .Query;
            });
        }
Exemplo n.º 58
0
        public void ShouldTranslateAnonymousObjectWithMixedProperties()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .With((a, b) => new
            {
                a,
                foo = b.Count(),
                bar = b.CollectAs <object>()
            })
                         .Query;

            Assert.AreEqual("WITH a, count(b) AS foo, collect(b) AS bar", query.QueryText);
        }
        public void ReturnDistinctWithLimit()
        {
            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .Start("n", (NodeReference)3)
                         .ReturnDistinct <object>("n")
                         .Limit(5)
                         .Query;

            Assert.Equal("START n=node({p0})\r\nRETURN distinct n\r\nLIMIT {p1}", query.QueryText);
            Assert.Equal(3L, query.QueryParameters["p0"]);
            Assert.Equal(5, query.QueryParameters["p1"]);
            Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
        }
        public void OptionalMatch()
        {
            // http://docs.neo4j.org/chunked/2.0.0-RC1/query-optional-match.html
            // OPTIONAL MATCH (n)--(x)
            // RETURN n, x

            var client = Substitute.For <IRawGraphClient>();
            var query  = new CypherFluentQuery(client)
                         .OptionalMatch("(n)--(x)")
                         .Query;

            Assert.Equal("OPTIONAL MATCH (n)--(x)", query.QueryText);
            Assert.Equal(0, query.QueryParameters.Count());
        }