Commits

Tatham Oddie  committed 3dc96ec

Remove the Cypher ResultSet property. It's just confusing having both Results and ResultSet on the API when we are smart enough to work it out ourselves.

  • Participants
  • Parent commits 0d709cd

Comments (0)

Files changed (8)

File Neo4jClient/Cypher/CypherFluentQuery`TResult.cs

-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Diagnostics;
 
 namespace Neo4jClient.Cypher
         {
             get
             {
-                return Client.ExecuteGetCypherResults<TResult>(Query, CypherResultMode.Projection);
+                return Client.ExecuteGetCypherResults<TResult>(Query);
             }
         }
 
+        [Obsolete("Use the Results propery instead.", true)]
         public IEnumerable<TResult> ResultSet
         {
-            get
-            {
-                return Client.ExecuteGetCypherResults<TResult>(Query, CypherResultMode.Set);
-            }
+            get { throw new NotSupportedException("Use the Results propery instead."); }
         }
     }
 }

File Neo4jClient/Cypher/CypherQuery.cs

     {
         readonly string queryText;
         readonly IDictionary<string, object> queryParameters;
+        readonly CypherResultMode resultMode;
 
-        public CypherQuery(string queryText, IDictionary<string, object> queryParameters)
+        public CypherQuery(
+            string queryText,
+            IDictionary<string, object> queryParameters,
+            CypherResultMode resultMode)
         {
             this.queryText = queryText;
             this.queryParameters = queryParameters;
+            this.resultMode = resultMode;
         }
 
         public IDictionary<string, object> QueryParameters
             get { return queryText; }
         }
 
+        public CypherResultMode ResultMode
+        {
+            get { return resultMode; }
+        }
+
         protected string DebugQueryText
         {
             get

File Neo4jClient/Cypher/CypherQueryBuilder.cs

         string whereText;
         string returnText;
         bool returnDistinct;
+        CypherResultMode resultMode;
         int? limit;
         int? skip;
         string orderBy;
                 whereText = whereText,
                 returnText = returnText,
                 returnDistinct = returnDistinct,
+                resultMode = resultMode,
                 limit = limit,
                 skip = skip,
                 startBits = startBits,
             var newBuilder = Clone();
             newBuilder.returnText = identity;
             newBuilder.returnDistinct = distinct;
+            newBuilder.resultMode = CypherResultMode.Set;
             return newBuilder;
         }
 
             var newBuilder = Clone();
             newBuilder.returnText = CypherReturnExpressionBuilder.BuildText(expression);
             newBuilder.returnDistinct = distinct;
+            newBuilder.resultMode = CypherResultMode.Projection;
             return newBuilder;
         }
 
             WriteSkipClause(queryTextBuilder, queryParameters);
             WriteLimitClause(queryTextBuilder, queryParameters);
 
-            return new CypherQuery(queryTextBuilder.ToString(), queryParameters);
+            return new CypherQuery(queryTextBuilder.ToString(), queryParameters, resultMode);
         }
 
         public static string CreateParameter(IDictionary<string, object> parameters, object paramValue)

File Neo4jClient/Cypher/ICypherFluentQueryReturned.cs

+using System;
 using System.Collections.Generic;
 
 namespace Neo4jClient.Cypher
         ICypherFluentQueryReturned<TResult> OrderBy(params string[] properties);
         ICypherFluentQueryReturned<TResult> OrderByDescending(params string[] properties);
 
-        /// <summary>
-        /// Return custom projections i.e. Multiple columns in the result.
-        /// </summary>
         IEnumerable<TResult> Results { get; }
 
-        /// <summary>
-        /// Return either Nodes, Or Relationships, Paths i.e. Only one column in the result.
-        /// </summary>
+        [Obsolete("Use the Results property instead.", true)]
         IEnumerable<TResult> ResultSet { get; }
     }
 }

File Neo4jClient/GraphClient.cs

             return results;
         }
 
-        public virtual IEnumerable<TResult> ExecuteGetCypherResults<TResult>(CypherQuery query, CypherResultMode resultMode = CypherResultMode.Projection)
+        public virtual IEnumerable<TResult> ExecuteGetCypherResults<TResult>(CypherQuery query)
         {
             CheckRoot();
 
                 string.Format("The query was: {0}", query.QueryText),
                 HttpStatusCode.OK);
 
-            var deserializer = new CypherJsonDeserializer<TResult>(this, resultMode);
+            var deserializer = new CypherJsonDeserializer<TResult>(this, query.ResultMode);
             var results = deserializer
                 .Deserialize(response)
                 .ToList();

File Neo4jClient/IGraphClient.cs

 
         string ExecuteScalarGremlin(string query, IDictionary<string, object> parameters);
 
-        IEnumerable<TResult> ExecuteGetCypherResults<TResult>(CypherQuery query, CypherResultMode resultMode = CypherResultMode.Projection);
+        IEnumerable<TResult> ExecuteGetCypherResults<TResult>(CypherQuery query);
 
         IEnumerable<TResult> ExecuteGetAllProjectionsGremlin<TResult>(IGremlinQuery query) where TResult : new();
 

File Test/Cypher/CypherFluentQueryResultsTests.cs

             // RETURN a
 
             var client = Substitute.For<IGraphClient>();
-
+            var set = new[] { new Node<FooNode>(new FooNode(), (NodeReference<FooNode>)123) };
             client
-                .ExecuteGetCypherResults<Node<FooNode>>(Arg.Any<CypherQuery>())
-                .Returns(Enumerable.Empty<Node<FooNode>>());
+                .ExecuteGetCypherResults<Node<FooNode>>(
+                    Arg.Is<CypherQuery>(q => q.ResultMode == CypherResultMode.Set))
+                .Returns(set);
 
             var cypher = new CypherFluentQuery(client);
             var results = cypher
                 .Start("a", (NodeReference)1)
                 .Return<Node<FooNode>>("a")
-                .ResultSet;
+                .Results;
 
-            Assert.IsInstanceOf<IEnumerable<Node<FooNode>>>(results);
+            CollectionAssert.AreEqual(set, results);
         }
 
         [Test]

File Test/GraphClientTests/Cypher/ExecuteGetCypherResultsTests.cs

                 {
                     {"p0", 215},
                     {"p1", 219}
-                });
+                },
+                CypherResultMode.Set);
 
             var httpFactory = MockHttpFactory.Generate("http://foo/db/data", new Dictionary<IRestRequest, IHttpResponse>
             {
             graphClient.Connect();
 
             //Act
-            var results = graphClient.ExecuteGetCypherResults<PathsResult>(query,CypherResultMode.Set);
+            var results = graphClient.ExecuteGetCypherResults<PathsResult>(query);
 
             //Assert
             Assert.IsInstanceOf<IEnumerable<PathsResult>>(results);
                 new Dictionary<string, object>
                 {
                     {"p0", 123}
-                });
+                },
+                CypherResultMode.Projection);
 
             var httpFactory = MockHttpFactory.Generate("http://foo/db/data", new Dictionary<IRestRequest, IHttpResponse>
             {
                 new Dictionary<string, object>
                 {
                     {"p0", 123}
-                });
+                },
+                CypherResultMode.Projection);
 
             var httpFactory = MockHttpFactory.Generate("http://foo/db/data", new Dictionary<IRestRequest, IHttpResponse>
             {
                 new Dictionary<string, object>
                 {
                     {"p0", 123}
-                });
+                },
+                CypherResultMode.Projection);
 
             var httpFactory = MockHttpFactory.Generate("http://foo/db/data", new Dictionary<IRestRequest, IHttpResponse>
             {