Skip to content
Browse files

Update to support BATCH processing.

Added neo4jRestNet config section to app.cofig file.

refactored may methods in INode and IRelationship.

refactored Node/Relationship to be instance objects - breaking change for older versions

moved Cypher out of Plugin namespace since it is now core to Neo4j
  • Loading branch information...
1 parent dfeeed3 commit fe56e9196c994a9b82d65c0828379afca6277591 @SepiaGroup committed Jun 6, 2012
Showing with 4,470 additions and 1,205 deletions.
  1. +19 −6 Neo4jRestNet.Test/App.config
  2. +791 −0 Neo4jRestNet.Test/BatchStoreTest.cs
  3. +15 −21 Neo4jRestNet.Test/EncryptedIDTest.cs
  4. +7 −1 Neo4jRestNet.Test/Neo4jRestNet.Test.csproj
  5. +822 −0 Neo4jRestNet.Test/NodeClassTest.cs
  6. +0 −12 Neo4jRestNet.sln
  7. +19 −0 Neo4jRestNet/Configuration/ConnectionCollection.cs
  8. +81 −0 Neo4jRestNet/Configuration/ConnectionElement.cs
  9. +23 −0 Neo4jRestNet/Configuration/ConnectionManager.cs
  10. +14 −0 Neo4jRestNet/Configuration/ConnectionSettings.cs
  11. +121 −0 Neo4jRestNet/Core/BatchNodeStore.cs
  12. +122 −0 Neo4jRestNet/Core/BatchRelationshipStore.cs
  13. +716 −0 Neo4jRestNet/Core/BatchStore.cs
  14. +14 −0 Neo4jRestNet/Core/Exceptions/BatchDeleteNotSupported.cs
  15. +14 −0 Neo4jRestNet/Core/Exceptions/BatchGetRelationshipsNotSupported.cs
  16. +14 −0 Neo4jRestNet/Core/Exceptions/BatchRemoveFromIndexNotSupported.cs
  17. +14 −0 Neo4jRestNet/Core/Exceptions/NodeNotFound.cs
  18. +2 −0 Neo4jRestNet/Core/IGraphObject.cs
  19. +35 −0 Neo4jRestNet/Core/INodeStore.cs
  20. +35 −0 Neo4jRestNet/Core/IRelationshipStore.cs
  21. +256 −453 Neo4jRestNet/Core/Node.cs
  22. +57 −20 Neo4jRestNet/Core/Path.cs
  23. +11 −0 Neo4jRestNet/Core/Properties.cs
  24. +201 −287 Neo4jRestNet/Core/Relationship.cs
  25. +421 −0 Neo4jRestNet/Core/RestNodeStore.cs
  26. +449 −0 Neo4jRestNet/Core/RestRelationshipStore.cs
  27. +8 −12 Neo4jRestNet/{CypherPlugin → Cypher}/Cypher.cs
  28. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/CypherMatch.cs
  29. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/CypherOrderBy.cs
  30. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/CypherProperty.cs
  31. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/CypherReturn.cs
  32. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/CypherStart.cs
  33. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/CypherWhere.cs
  34. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/ICypherObject.cs
  35. +1 −1 Neo4jRestNet/{CypherPlugin → Cypher}/ParseWhereLambda.cs
  36. +12 −17 Neo4jRestNet/GremlinPlugin/Gremlin.cs
  37. +2 −2 Neo4jRestNet/GremlinPlugin/JavaStringCommands.cs
  38. +26 −10 Neo4jRestNet/Neo4jRestNet.csproj
  39. +7 −5 Neo4jRestNet/Properties/AssemblyInfo.cs
  40. +57 −18 Neo4jRestNet/Rest/HttpRest.cs
  41. +77 −26 Neo4jRestNet/Rest/Neo4jRestApi.cs
  42. +0 −13 Neo4jRestNetExamples/App.config
  43. +0 −62 Neo4jRestNetExamples/Examples.csproj
  44. +0 −196 Neo4jRestNetExamples/Program.cs
  45. +0 −36 Neo4jRestNetExamples/Properties/AssemblyInfo.cs
View
25 Neo4jRestNet.Test/App.config
@@ -1,13 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
- <connectionStrings>
- <add name="neo4j" connectionString="http://localhost:7474/db/data/" providerName="Neo4j" />
- <add name="neo4jGremlinExtension" connectionString="/ext/GremlinPlugin/graphdb/execute_script/" providerName="Neo4j"/>
- <add name="neo4jCypherExtension" connectionString="/ext/CypherPlugin/graphdb/execute_query/" providerName="Neo4j"/>
- </connectionStrings>
+ <configSections>
+ <section name="neo4jRestNet" type="Neo4jRestNet.Configuration.ConnectionSettings, Neo4jRestNet" />
+ </configSections>
+
+ <neo4jRestNet>
+ <databases>
+ <add name="neo4j" default="true" https="false" domain="localhost" port="7474" dataPath="/db/data" gremlinPath="/ext/GremlinPlugin/graphdb/execute_script" />
+ </databases>
+ </neo4jRestNet>
<appSettings>
<add key="EncryptIdKey" value="KeyForEncrypting"/>
<add key="EncryptIdIV" value="IVForEncrypting1"/>
</appSettings>
-</configuration>
+
+ <!-- This is required to support escaped '/' and '.' values in the URL (such as looking up an node via a index) -->
+ <uri>
+ <schemeSettings>
+ <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
+ <add name="https" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
+ </schemeSettings>
+ </uri>
+</configuration>
+
View
791 Neo4jRestNet.Test/BatchStoreTest.cs
@@ -0,0 +1,791 @@
+using System;
+using System.Collections;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Neo4jRestNet.Core;
+using Neo4jRestNet.Core.Exceptions;
+
+namespace Neo4jRestNet.Test
+{
+ [TestClass]
+ public class BatchStoreTest
+ {
+ private string UniqueValue()
+ {
+ return System.Web.Security.Membership.GeneratePassword(5, 0);
+ }
+
+ [TestMethod]
+ public void CreateNodeNoProperties()
+ {
+ var batch = new BatchStore();
+ var batchNode = Node.CreateNode(null, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ Assert.IsTrue(restNode.Id > 0);
+ }
+
+ [TestMethod]
+ public void CreateTwoNodeNoProperties()
+ {
+ var batch = new BatchStore();
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+
+ Assert.IsTrue(restNode1.Id > 0);
+ Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);
+ }
+
+ [TestMethod]
+ public void CreateNodeWithProperties()
+ {
+ var batch = new BatchStore();
+
+ var prop1 = new Properties();
+ prop1.SetProperty("name", "michael");
+ prop1.SetProperty("location", "new york");
+
+ var prop2 = new Properties();
+ prop2.SetProperty("color", "blue");
+ prop2.SetProperty("tree", "elm");
+
+ var batchNode1 = Node.CreateNode(prop1, batch);
+ var batchNode2 = Node.CreateNode(prop2, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+
+ Assert.IsTrue(restNode1.Id > 0);
+ Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);
+
+ Assert.IsTrue(restNode1.Properties.GetProperty<string>("name") == "michael");
+ Assert.IsTrue(restNode1.Properties.GetProperty<string>("location") == "new york");
+
+ Assert.IsTrue(restNode2.Properties.GetProperty<string>("color") == "blue");
+ Assert.IsTrue(restNode2.Properties.GetProperty<string>("tree") == "elm");
+ }
+
+ [TestMethod]
+ public void GetNode()
+ {
+ var node = Node.CreateNode();
+
+ var batch = new BatchStore();
+ var batchNode = Node.GetNode(node.Id, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ Assert.IsTrue(node == restNode);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(NodeNotFoundException))]
+ public void DeleteNode()
+ {
+ var node = Node.CreateNode();
+
+ var batch = new BatchStore();
+
+ batch.Delete(node);
+
+ Assert.IsTrue(batch.Execute());
+
+ Node.GetNode(node.Id);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(BatchDeleteNotSupportedException))]
+ public void DeleteBatchNode1()
+ {
+ var batch = new BatchStore();
+ var node = Node.CreateNode(batch);
+
+ node.Delete();
+
+ batch.Execute();
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(BatchDeleteNotSupportedException))]
+ public void DeleteBatchNode2()
+ {
+ var batch = new BatchStore();
+ var node = Node.CreateNode(batch);
+
+ batch.Delete(node);
+ batch.Execute();
+ }
+
+ [TestMethod]
+ public void CreateRelationshipNoProperties1()
+ {
+ var batch = new BatchStore();
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ var batchRelationship = batchNode1.CreateRelationshipTo(batchNode2, "friend");
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restNode1.Id > 0);
+ Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);
+
+ Assert.IsTrue(restRelationship.StartNode == restNode1);
+ Assert.IsTrue(restRelationship.EndNode == restNode2);
+ Assert.IsTrue(restRelationship.Type == "friend");
+ }
+
+ [TestMethod]
+ public void CreateRelationshipNoProperties2()
+ {
+ var batch = new BatchStore();
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ var batchRelationship = Relationship.CreateRelationship(batchNode1, batchNode2, "friend", null, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restNode1.Id > 0);
+ Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);
+
+ Assert.IsTrue(restRelationship.StartNode == restNode1);
+ Assert.IsTrue(restRelationship.EndNode == restNode2);
+ Assert.IsTrue(restRelationship.Type == "friend");
+ }
+
+ [TestMethod]
+ public void CreateRelationshipWithProperties1()
+ {
+ var batch = new BatchStore();
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ var prop = new Properties();
+
+ var since = DateTime.Now;
+
+ prop.SetProperty("since", since);
+ prop.SetProperty("approved", true);
+
+ var batchRelationship = batchNode1.CreateRelationshipTo(batchNode2, "friend", prop);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restNode1.Id > 0);
+ Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);
+
+ Assert.IsTrue(restRelationship.StartNode == restNode1);
+ Assert.IsTrue(restRelationship.EndNode == restNode2);
+ Assert.IsTrue(restRelationship.Type == "friend");
+
+ Assert.IsTrue(restRelationship.Properties.GetProperty<DateTime>("since") == since);
+ Assert.IsTrue(restRelationship.Properties.GetProperty<bool>("approved"));
+ }
+
+ [TestMethod]
+ public void CreateRelationshipWithProperties2()
+ {
+ var batch = new BatchStore();
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ var prop = new Properties();
+
+ var since = DateTime.Now;
+
+ prop.SetProperty("since", since);
+ prop.SetProperty("approved", true);
+
+ var batchRelationship = Relationship.CreateRelationship(batchNode1, batchNode2, "friend", prop, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restNode1.Id > 0);
+ Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);
+
+ Assert.IsTrue(restRelationship.StartNode == restNode1);
+ Assert.IsTrue(restRelationship.EndNode == restNode2);
+ Assert.IsTrue(restRelationship.Type == "friend");
+
+ Assert.IsTrue(restRelationship.Properties.GetProperty<DateTime>("since") == since);
+ Assert.IsTrue(restRelationship.Properties.GetProperty<bool>("approved"));
+ }
+
+
+ [TestMethod]
+ public void GetRelationshipWithProperties()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var props = new Properties();
+ props.SetProperty("name", "michael");
+ props.SetProperty("approved", true);
+ props.SetProperty("length", 123);
+
+ var relationship = node1.CreateRelationshipTo(node2, "friend", props);
+
+ var batch = new BatchStore();
+ var batchRelationship = Relationship.GetRelationship(relationship.Id, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restRelationship == relationship);
+ Assert.IsTrue(restRelationship.Properties.GetProperty<string>("name") == "michael");
+ Assert.IsTrue(restRelationship.Properties.GetProperty<bool>("approved"));
+ Assert.IsTrue(restRelationship.Properties.GetProperty<int>("length") == 123);
+ }
+
+ [TestMethod]
+ public void UpdateRelationshipProperties1()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var batch = new BatchStore();
+
+ var batchRelationship = Relationship.CreateRelationship(node1, node2, "likes", null, batch);
+
+ batchRelationship.Properties.SetProperty("name", "todd");
+ batchRelationship.Properties.SetProperty("moved", true);
+ batchRelationship.Properties.SetProperty("height", 13);
+
+ batchRelationship.SaveProperties();
+
+ Assert.IsTrue(batch.Execute());
+
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restRelationship.Properties.GetProperty<string>("name") == "todd");
+ Assert.IsTrue(restRelationship.Properties.GetProperty<bool>("moved"));
+ Assert.IsTrue(restRelationship.Properties.GetProperty<int>("height") == 13);
+ }
+
+ [TestMethod]
+ public void RemoveRelationshipProperties()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var batch = new BatchStore();
+
+ var batchRelationship = Relationship.CreateRelationship(node1, node2, "likes", null, batch);
+ batchRelationship.Properties.SetProperty("name", "joe");
+ batchRelationship.Properties.SetProperty("age", 12);
+
+ batchRelationship.SaveProperties();
+
+ batchRelationship.Properties.RemoveProperty("age");
+
+ batchRelationship.SaveProperties();
+
+ Assert.IsTrue(batch.Execute());
+
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ Assert.IsTrue(restRelationship.Properties.GetProperty<string>("name") == "joe");
+ Assert.IsTrue(restRelationship.Properties.GetPropertyOrDefault<int>("age") == 0);
+ }
+
+
+ [TestMethod]
+ [ExpectedException(typeof(BatchGetRelationshipsNotSupportedException))]
+ public void GetAllRelationships1()
+ {
+ var batch = new BatchStore();
+
+ var batchNode = Node.CreateNode(batch);
+ batchNode.GetRelationships();
+
+ batch.Execute();
+ }
+
+ [TestMethod]
+ public void GetAllRelationships2()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var node3 = Node.CreateNode();
+ var node4 = Node.CreateNode();
+
+ var restRelationship1 = node1.CreateRelationshipTo(node2, "like");
+ var restRelationship2 = node1.CreateRelationshipTo(node3, "like");
+ var restRelationship3 = node1.CreateRelationshipTo(node4, "like");
+
+ var batch = new BatchStore();
+ var batchRelationships = batch.GetRelationships(node1, RelationshipDirection.All);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restRelationships = batch.GetGraphObject(batchRelationships);
+
+ Assert.IsNotNull(restRelationships);
+
+ Assert.IsTrue(restRelationships.Count() == 3);
+ }
+
+ [TestMethod]
+ public void UpdatePropertyOnNode1()
+ {
+ var batch = new BatchStore();
+ var batchNode = Node.CreateNode(batch);
+
+ var props = new Properties();
+ props.SetProperty("name", "todd");
+ props.SetProperty("moved", true);
+ props.SetProperty("height", 13);
+
+ batchNode.SaveProperties(props);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ Assert.IsTrue(restNode.Properties.GetProperty<string>("name") == "todd");
+ Assert.IsTrue(restNode.Properties.GetProperty<bool>("moved"));
+ Assert.IsTrue(restNode.Properties.GetProperty<int>("height") == 13);
+ }
+
+ [TestMethod]
+ public void UpdatePropertyOnNode2()
+ {
+ var batch = new BatchStore();
+
+ var batchNode = Node.CreateNode(batch);
+
+ batchNode.Properties.SetProperty("name", "todd");
+ batchNode.Properties.SetProperty("moved", true);
+ batchNode.Properties.SetProperty("height", 13);
+
+ batchNode.SaveProperties();
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ Assert.IsTrue(restNode.Properties.GetProperty<string>("name") == "todd");
+ Assert.IsTrue(restNode.Properties.GetProperty<bool>("moved"));
+ Assert.IsTrue(restNode.Properties.GetProperty<int>("height") == 13);
+ }
+
+ [TestMethod]
+ public void GetPropertiesOnNode1()
+ {
+ var batch = new BatchStore();
+
+ var node = Node.CreateNode();
+
+ node.Properties.SetProperty("name", "todd");
+ node.Properties.SetProperty("moved", true);
+ node.Properties.SetProperty("height", 13);
+
+ node.SaveProperties();
+
+ var batchNode = Node.GetNode(node.Id, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ Assert.IsTrue(restNode.Properties.GetProperty<string>("name") == "todd");
+ Assert.IsTrue(restNode.Properties.GetProperty<bool>("moved"));
+ Assert.IsTrue(restNode.Properties.GetProperty<int>("height") == 13);
+ }
+
+ [TestMethod]
+ public void DeleteAPropertyFromNode()
+ {
+ var batch = new BatchStore();
+
+ var batchNode = Node.CreateNode(batch);
+
+ batchNode.Properties.SetProperty("name", "todd");
+ batchNode.Properties.SetProperty("moved", true);
+ batchNode.Properties.SetProperty("height", 13);
+
+ batchNode.SaveProperties();
+
+ batchNode.Properties.RemoveProperty("moved");
+
+ batchNode.SaveProperties();
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ Assert.IsTrue(restNode.Properties.GetProperty<string>("name") == "todd");
+ Assert.IsFalse(restNode.Properties.GetPropertyOrDefault<bool>("moved"));
+ Assert.IsTrue(restNode.Properties.GetProperty<int>("height") == 13);
+ }
+
+ [TestMethod]
+ public void AddNodeToIndex()
+ {
+ var batch = new BatchStore();
+
+ var batchNode = Node.CreateNode(batch);
+
+ var value1 = UniqueValue();
+
+ batchNode.AddToIndex("nodes", "a", value1);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == restNode);
+ }
+
+ [TestMethod]
+ public void AddRelationshipsToIndex()
+ {
+ var batch = new BatchStore();
+
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ var batchRelationship = batchNode1.CreateRelationshipTo(batchNode2, "friend");
+
+ var value1 = UniqueValue();
+
+ batchRelationship.AddToIndex("relationships", "a", value1);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restRelationship = batch.GetGraphObject(batchRelationship);
+
+ var relationships = Relationship.GetRelationship("relationships", "a", value1);
+ Assert.IsTrue(relationships.Count() == 1);
+ Assert.IsTrue(relationships.First() == restRelationship);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(BatchRemoveFromIndexNotSupportedException))]
+ public void RemoveNodeToIndex1()
+ {
+ var batch = new BatchStore();
+
+ var batchNode = Node.CreateNode(batch);
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+
+ batchNode.AddToIndex("nodes", "a", value1);
+
+ batchNode.RemoveFromIndex("nodes");
+ }
+
+ [TestMethod]
+ public void RemoveNodeToIndex2()
+ {
+ var batch = new BatchStore();
+
+ var node = Node.CreateNode();
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+
+ node.AddToIndex("nodes", "a", value1);
+ node.AddToIndex("nodes", "b", value2);
+
+ Node.RemoveFromIndex(node, "nodes", null, null, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var nodes1 = Node.GetNode("nodes", "a", value1);
+ var nodes2 = Node.GetNode("nodes", "b", value2);
+
+ Assert.IsTrue(!nodes1.Any());
+ Assert.IsTrue(!nodes2.Any());
+ }
+
+ [TestMethod]
+ public void RemoveNodeToIndex3()
+ {
+ var batch = new BatchStore();
+
+ var node = Node.CreateNode();
+
+ var value1 = UniqueValue();
+
+ node.AddToIndex("nodes", "a", value1);
+ node.AddToIndex("nodes", "b", value1);
+
+ Node.RemoveFromIndex(node, "nodes", "a", null, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var nodes1 = Node.GetNode("nodes", "a", value1);
+ var nodes2 = Node.GetNode("nodes", "b", value1);
+
+ Assert.IsTrue(!nodes1.Any());
+ Assert.IsTrue(nodes2.Count() == 1);
+ Assert.IsTrue(nodes2.First() == node);
+ }
+
+ [TestMethod]
+ public void RemoveNodeToIndex4()
+ {
+ var batch = new BatchStore();
+
+ var node = Node.CreateNode();
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+
+ node.AddToIndex("nodes", "a", value1);
+ node.AddToIndex("nodes", "a", value2);
+ node.AddToIndex("nodes", "b", value2);
+
+ Node.RemoveFromIndex(node, "nodes", "a", value2, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var nodes1 = Node.GetNode("nodes", "a", value1);
+ var nodes2 = Node.GetNode("nodes", "a", value2);
+ var nodes3 = Node.GetNode("nodes", "b", value2);
+
+ Assert.IsTrue(nodes1.Count() == 1);
+ Assert.IsTrue(nodes2.Count() == 0);
+ Assert.IsTrue(nodes3.Count() == 1);
+
+ Assert.IsTrue(nodes1.First() == node);
+ Assert.IsTrue(nodes3.First() == node);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(BatchRemoveFromIndexNotSupportedException))]
+ public void RemoveRelationshpToIndex1()
+ {
+ var batch = new BatchStore();
+
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+ var batchRelationship = batchNode1.CreateRelationshipTo(batchNode2, "like");
+
+ var value1 = UniqueValue();
+
+ batchRelationship.AddToIndex("relationships", "a", value1);
+
+ batchRelationship.RemoveFromIndex("nodes");
+ }
+
+ [TestMethod]
+ public void RemoveRelationshpToIndex2()
+ {
+ var batch = new BatchStore();
+
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var relationship1 = node1.CreateRelationshipTo(node2, "like");
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+
+ relationship1.AddToIndex("relationships", "a", value1);
+ relationship1.AddToIndex("relationships", "b", value2);
+
+ Relationship.RemoveFromIndex(relationship1, "relationships", null, null, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var relationships1 = Relationship.GetRelationship("relationships", "a", value1);
+ var relationships2 = Relationship.GetRelationship("relationships", "b", value2);
+
+ Assert.IsTrue(!relationships1.Any());
+ Assert.IsTrue(!relationships2.Any());
+ }
+
+ [TestMethod]
+ public void RemoveRelationshipToIndex3()
+ {
+ var batch = new BatchStore();
+
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var relationship1 = node1.CreateRelationshipTo(node2, "like");
+
+ var value1 = UniqueValue();
+
+ relationship1.AddToIndex("relationships", "a", value1);
+ relationship1.AddToIndex("relationships", "b", value1);
+
+ Relationship.RemoveFromIndex(relationship1, "relationships", "a", null, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var relationships1 = Relationship.GetRelationship("relationships", "a", value1);
+ var relationships2 = Relationship.GetRelationship("relationships", "b", value1);
+
+ Assert.IsTrue(!relationships1.Any());
+ Assert.IsTrue(relationships2.Count() == 1);
+ Assert.IsTrue(relationships2.First() == relationship1);
+ }
+
+ [TestMethod]
+ public void RemoveRelationshipToIndex4()
+ {
+ var batch = new BatchStore();
+
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var relationship1 = node1.CreateRelationshipTo(node2, "like");
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+
+ relationship1.AddToIndex("relationships", "a", value1);
+ relationship1.AddToIndex("relationships", "a", value2);
+ relationship1.AddToIndex("relationships", "b", value2);
+
+ Relationship.RemoveFromIndex(relationship1, "relationships", "a", value2, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var relationships1 = Relationship.GetRelationship("relationships", "a", value1);
+ var relationships2 = Relationship.GetRelationship("relationships", "a", value2);
+ var relationships3 = Relationship.GetRelationship("relationships", "b", value2);
+
+ Assert.IsTrue(relationships1.Count() == 1);
+ Assert.IsTrue(relationships2.Count() == 0);
+ Assert.IsTrue(relationships3.Count() == 1);
+
+ Assert.IsTrue(relationships1.First() == relationship1);
+ Assert.IsTrue(relationships3.First() == relationship1);
+ }
+
+ [TestMethod]
+ public void AddNodeToIndexUnique1()
+ {
+ var batch = new BatchStore();
+
+ var batchNode = Node.CreateNode(batch);
+
+ var value1 = UniqueValue();
+
+ var batchUniqueNode = batchNode.AddToIndex("nodes", "a", value1, true);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchUniqueNode);
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == restNode);
+ }
+
+ [TestMethod]
+ public void AddNodeToIndexUnique2()
+ {
+ var batch = new BatchStore();
+
+ var batchNode1 = Node.CreateNode(batch);
+ var batchNode2 = Node.CreateNode(batch);
+
+ var value1 = UniqueValue();
+
+ var batchUniqueNode1 = batchNode1.AddToIndex("nodes", "a", value1, true);
+ var batchUniqueNode2 = batchNode2.AddToIndex("nodes", "a", value1, true);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchUniqueNode1);
+ var restNode2 = batch.GetGraphObject(batchUniqueNode2);
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == restNode1);
+ Assert.IsTrue(restNode1 == restNode2);
+ }
+
+ [TestMethod]
+ public void CreateUniqueNodeInIndex1()
+ {
+ var batch = new BatchStore();
+
+ var value1 = UniqueValue();
+
+ var props = new Properties();
+ props.SetProperty("name", "jack");
+
+ var batchNode = Node.CreateUniqueNode("nodes", "a", value1, props, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode = batch.GetGraphObject(batchNode);
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == restNode);
+ Assert.IsTrue(restNode.Properties.GetProperty<string>("name") == "jack");
+ }
+
+ [TestMethod]
+ public void CreateUniqueNodeInIndex2()
+ {
+ var batch = new BatchStore();
+
+ var value1 = UniqueValue();
+
+ var props1 = new Properties();
+ props1.SetProperty("name", "jack");
+
+ var props2 = new Properties();
+ props2.SetProperty("name", "frank");
+
+ var batchNode1 = Node.CreateUniqueNode("nodes", "a", value1, props1, batch);
+ var batchNode2 = Node.CreateUniqueNode("nodes", "a", value1, props2, batch);
+
+ Assert.IsTrue(batch.Execute());
+
+ var restNode1 = batch.GetGraphObject(batchNode1);
+ var restNode2 = batch.GetGraphObject(batchNode2);
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == restNode1);
+ Assert.IsTrue(restNode1 == restNode2);
+ Assert.IsTrue(restNode1.Properties.GetProperty<string>("name") == "jack");
+ }
+ }
+}
View
36 Neo4jRestNet.Test/EncryptedIDTest.cs
@@ -1,12 +1,6 @@
-using System;
-using System.Text;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo4jRestNet.Core;
using System.Security.Cryptography;
-using Neo4jRestNet.Core.Implementation;
-using Neo4jRestNet.GremlinPlugin;
namespace Neo4jRestNet.Test
{
@@ -28,18 +22,18 @@ public void GetNode()
[TestMethod]
public void NewGEIDFromLong()
{
- EncryptId geid = new EncryptId(123);
+ var geid = new EncryptId(123);
Assert.AreEqual(123, (long)geid);
}
[TestMethod]
public void NewGEIDFromString()
{
- EncryptId geid = new EncryptId(123);
+ var geid = new EncryptId(123);
string strGEID = geid.ToString();
- EncryptId impGEID = new EncryptId(strGEID);
+ var impGEID = new EncryptId(strGEID);
Assert.AreEqual(strGEID, impGEID.ToString());
Assert.AreEqual(strGEID, impGEID.ToString());
@@ -48,8 +42,8 @@ public void NewGEIDFromString()
[TestMethod]
public void TryParseValid()
{
- EncryptId geid = new EncryptId(123);
- string strGEID = geid.ToString();
+ var geid = new EncryptId(123);
+ var strGEID = geid.ToString();
EncryptId tryGEID;
Assert.IsTrue(EncryptId.TryParse(strGEID, out tryGEID));
@@ -59,7 +53,7 @@ public void TryParseValid()
[TestMethod]
public void TryParseNotValid()
{
- string strGEID = "SomeBadValue";
+ var strGEID = "SomeBadValue";
EncryptId tryGEID;
Assert.IsFalse(EncryptId.TryParse(strGEID, out tryGEID));
@@ -75,9 +69,9 @@ public void ImplicitBadStringValue()
[TestMethod]
public void Equality()
{
- EncryptId geid1 = new EncryptId(123);
- EncryptId geid2 = new EncryptId(123);
- EncryptId geid3 = new EncryptId(321);
+ var geid1 = new EncryptId(123);
+ var geid2 = new EncryptId(123);
+ var geid3 = new EncryptId(321);
Assert.IsTrue(geid1 == geid2);
Assert.IsTrue(geid1.ToString() == geid2.ToString());
@@ -93,9 +87,9 @@ public void Equality()
[TestMethod]
public void Inequality()
{
- EncryptId geid1 = new EncryptId(123);
- EncryptId geid2 = new EncryptId(321);
- EncryptId geid3 = new EncryptId(123);
+ var geid1 = new EncryptId(123);
+ var geid2 = new EncryptId(321);
+ var geid3 = new EncryptId(123);
Assert.IsTrue(geid1 != geid2);
Assert.IsTrue(geid1.ToString() != geid2.ToString());
@@ -111,8 +105,8 @@ public void Inequality()
[TestMethod]
public void NullValue()
{
- EncryptId geidNull = EncryptId.Null;
- EncryptId geid = new EncryptId(123);
+ var geidNull = EncryptId.Null;
+ var geid = new EncryptId(123);
Assert.IsTrue(geidNull == EncryptId.Null);
Assert.IsFalse(geidNull != EncryptId.Null);
View
8 Neo4jRestNet.Test/Neo4jRestNet.Test.csproj
@@ -35,22 +35,28 @@
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
+ <Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
+ <Compile Include="BatchStoreTest.cs" />
<Compile Include="FilterLambdaTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="EncryptedIDTest.cs" />
+ <Compile Include="NodeClassTest.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="App.config" />
+ <None Include="App.config">
+ <SubType>Designer</SubType>
+ </None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Neo4jRestNet\Neo4jRestNet.csproj">
View
822 Neo4jRestNet.Test/NodeClassTest.cs
@@ -0,0 +1,822 @@
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Neo4jRestNet.Core;
+using Neo4jRestNet.Core.Exceptions;
+
+namespace Neo4jRestNet.Test
+{
+ [TestClass]
+ public class NodeClassTest
+ {
+ private string UniqueValue()
+ {
+ return System.Web.Security.Membership.GeneratePassword(5, 0);
+ }
+
+ [TestMethod]
+ public void CreateNode()
+ {
+ var node = Node.CreateNode();
+ Assert.IsNotNull(node);
+ }
+
+ [TestMethod]
+ public void CreateNodeWithNodeType()
+ {
+ var prop = new Properties();
+ prop.SetProperty("NodeType", "myNodeType");
+
+ var node = Node.CreateNode(prop);
+ Assert.IsNotNull(node);
+ Assert.IsTrue(node.Properties.GetProperty<string>("NodeType") == "myNodeType");
+ }
+
+ [TestMethod]
+ public void CreateNodeWithPropertyDictionary()
+ {
+ var properties = new Dictionary<string, object>();
+ properties.Add("A", 0);
+ properties.Add("B", "Foobar");
+ properties.Add("C", new DateTime(2012, 1, 1));
+ var node = Node.CreateNode(new Properties(properties));
+ Assert.IsNotNull(node);
+ Assert.IsTrue(node.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(node.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(node.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(node.Properties.ToDictionary().Count == 3);
+ }
+
+ [TestMethod]
+ public void CreateNodeWithProperties()
+ {
+ var properties = new Properties();
+ properties.SetProperty("A", 0);
+ properties.SetProperty("B", "Foobar");
+ properties.SetProperty("C", new DateTime(2012, 1, 1));
+ var node = Node.CreateNode(properties);
+ Assert.IsNotNull(node);
+ Assert.IsTrue(node.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(node.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(node.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(node.Properties.ToDictionary().Count == 3);
+ }
+
+ [TestMethod]
+ public void GetNode()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.GetNode(node1.Id);
+ Assert.IsNotNull(node2);
+ Assert.IsTrue(node1.Equals(node2));
+ }
+
+ [TestMethod]
+ public void GetNodeWithPropertyDictionary()
+ {
+ var dicProperties = new Dictionary<string, object>();
+ dicProperties.Add("A", 0);
+ dicProperties.Add("B", "Foobar");
+ dicProperties.Add("C", new DateTime(2012, 1, 1));
+
+ var properties = new Properties(dicProperties);
+
+ var node1 = Node.CreateNode(properties);
+ Assert.IsNotNull(node1);
+ Assert.IsTrue(node1.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(node1.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(node1.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(node1.Properties.ToDictionary().Count == 3);
+
+ var node2 = Node.GetNode(node1.Id);
+ Assert.IsNotNull(node2);
+ Assert.IsTrue(node1.Equals(node2));
+ Assert.IsTrue(node2.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(node2.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(node2.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(node2.Properties.ToDictionary().Count == 3);
+ }
+
+ [TestMethod]
+ public void GetRootNode()
+ {
+ var node1 = Node.GetRootNode();
+ Assert.IsNotNull(node1);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(NodeNotFoundException))]
+ public void DeleteNode()
+ {
+ var node1 = Node.CreateNode();
+ node1.Delete();
+ Node.GetNode(node1.Id); // Should throw NodeNotFoundException
+ }
+
+ [TestMethod]
+ public void AddNodeToIndex()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+ var value3 = UniqueValue();
+
+ var node3 = Node.AddToIndex(node1, "nodes", "a", value1);
+ Assert.IsNotNull(node3);
+ Assert.IsTrue(node3.Equals(node1));
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == (node3));
+
+ var node4 = Node.AddToIndex(node1, "nodes", "b", value2);
+ Assert.IsNotNull(node4);
+ Assert.IsTrue(node4 == node1);
+
+ var node5 = Node.GetNode("nodes", "b", value2).FirstOrDefault();
+ Assert.IsNotNull(node5);
+ Assert.IsTrue(node5 == node1);
+
+ var node6 = Node.AddToIndex(node1, "nodes", "b", value3);
+ Assert.IsNotNull(node6);
+ Assert.IsTrue(node6 == node1);
+
+ nodes = Node.GetNode("nodes", "b", value3);
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First() == node1);
+
+ var node9 = Node.AddToIndex(node1, "nodes", "a", value1);
+ var node10 = Node.AddToIndex(node2, "nodes", "a", value1);
+ Assert.IsNotNull(node9);
+ Assert.IsTrue(node9.Equals(node1));
+ Assert.IsNotNull(node10);
+ Assert.IsTrue(node10.Equals(node2));
+
+ nodes = Node.GetNode("nodes", "a", value1);
+ Assert.IsNotNull(nodes);
+
+ Assert.IsTrue(nodes.Count() == 2);
+ if (nodes.First() == node1)
+ {
+ Assert.IsTrue(nodes.First().Equals(node1));
+ Assert.IsTrue(nodes.ElementAt(1).Equals(node2));
+ }
+ else
+ {
+ Assert.IsTrue(nodes.First().Equals(node2));
+ Assert.IsTrue(nodes.ElementAt(1).Equals(node1));
+ }
+ }
+
+ [TestMethod]
+ public void RemoveNodeFromIndex()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var value1 = UniqueValue();
+ var value2 = UniqueValue();
+
+ var nodeA = Node.AddToIndex(node1, "nodes", "a", value1);
+ Node.AddToIndex(node2, "nodes", "a", value1);
+
+ var result1 = Node.RemoveFromIndex(node1, "nodes");
+ Assert.IsTrue(result1);
+
+ var nodes = Node.GetNode("nodes", "a", value1);
+ Assert.IsTrue(nodes.Count() == 1);
+ Assert.IsTrue(nodes.First().Equals(node2));
+
+ Node.AddToIndex(node1, "nodes", "b", value1);
+ Node.AddToIndex(node1, "nodes", "b", value2);
+ Node.AddToIndex(node2, "nodes", "c", value2);
+ var result2 = Node.RemoveFromIndex(node1, "nodes", "b", value1);
+
+ Assert.IsTrue(result2);
+ Assert.IsTrue(Node.GetNode("nodes", "b", value2).Count() == 1);
+
+ var nodesB = Node.GetNode("nodes", "b", value2);
+ Assert.IsTrue(nodesB.Count() == 1);
+ Assert.IsTrue(nodesB.First().Equals(node1));
+
+ var nodesC = Node.GetNode("nodes", "c", value2);
+ Assert.IsTrue(nodesC.Count() == 1);
+ Assert.IsTrue(nodesC.First().Equals(node2));
+ }
+
+ [TestMethod]
+ public void CreateRelationshipTo()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var relationship = node1.CreateRelationshipTo(node2, "Test");
+ Assert.IsNotNull(relationship);
+ Assert.IsTrue(relationship.StartNode.Equals(node1));
+ Assert.IsTrue(relationship.EndNode.Equals(node2));
+ Assert.IsTrue(relationship.Type == "Test");
+ }
+
+ [TestMethod]
+ public void CreateRelationshipToWithProperties()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var properties = new Properties();
+ properties.SetProperty("A", 0);
+ properties.SetProperty("B", "Foobar");
+ properties.SetProperty("C", new DateTime(2012, 1, 1));
+ var relationship = node1.CreateRelationshipTo(node2, "Test", properties);
+ Assert.IsNotNull(relationship);
+ Assert.IsTrue(relationship.StartNode.Equals(node1));
+ Assert.IsTrue(relationship.EndNode.Equals(node2));
+ Assert.IsTrue(relationship.Type == "Test");
+ Assert.IsTrue(relationship.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(relationship.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(relationship.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(relationship.Properties.ToDictionary().Count == 3);
+ }
+
+ [TestMethod]
+ public void GetRelationship()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var relationship1 = node1.CreateRelationshipTo(node2, "Test");
+ var relationship2 = Relationship.GetRelationship(relationship1.Id);
+ Assert.IsNotNull(relationship2);
+ Assert.IsTrue(relationship2.StartNode.Equals(node1));
+ Assert.IsTrue(relationship2.EndNode.Equals(node2));
+ Assert.IsTrue(relationship2.Type == "Test");
+ }
+
+ [TestMethod]
+ public void GetRelationshipWithProperties()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var properties = new Properties();
+ properties.SetProperty("A", 0);
+ properties.SetProperty("B", "Foobar");
+ properties.SetProperty("C", new DateTime(2012, 1, 1));
+ var relationship1 = node1.CreateRelationshipTo(node2, "Test", properties);
+ var relationship2 = Relationship.GetRelationship(relationship1.Id);
+ Assert.IsNotNull(relationship2);
+ Assert.IsTrue(relationship2.StartNode.Equals(node1));
+ Assert.IsTrue(relationship2.EndNode.Equals(node2));
+ Assert.IsTrue(relationship2.Type == "Test");
+ Assert.IsTrue(relationship2.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(relationship2.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(relationship2.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(relationship2.Properties.ToDictionary().Count == 3);
+ }
+
+ [TestMethod]
+ public void GetRelationships()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var relationship1 = node1.CreateRelationshipTo(node2, "Test");
+ var relationships = node1.GetRelationships("Test");
+ Assert.IsNotNull(relationships);
+ Assert.IsTrue(relationships.Count() == 1);
+ Assert.IsTrue(relationships.First().Equals(relationship1));
+ }
+
+ [TestMethod]
+ public void GetRelationships2()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var node3 = Node.CreateNode();
+ var relationship1 = node1.CreateRelationshipTo(node2, "Test");
+ var relationship2 = node2.CreateRelationshipTo(node3, "Test");
+ var relationships1 = node1.GetRelationships("Test");
+ Assert.IsNotNull(relationships1);
+ Assert.IsTrue(relationships1.Count() == 1);
+ Assert.IsTrue(relationships1.First().Equals(relationship1));
+
+ var relationships2 = node2.GetRelationships("Test");
+ Assert.IsNotNull(relationships2);
+ Assert.IsTrue(relationships2.Count() == 2);
+
+ if (relationships2.First().StartNode == node1)
+ {
+ Assert.IsTrue(relationships2.First().Equals(relationship1));
+ Assert.IsTrue(relationships2.ElementAt(1).Equals(relationship2));
+ }
+ else
+ {
+ Assert.IsTrue(relationships2.First().Equals(relationship2));
+ Assert.IsTrue(relationships2.ElementAt(1).Equals(relationship1));
+ }
+
+ var relationships3 = node3.GetRelationships("Test");
+ Assert.IsNotNull(relationships3);
+ Assert.IsTrue(relationships3.Count() == 1);
+ Assert.IsTrue(relationships3.First().Equals(relationship2));
+ }
+
+ [TestMethod]
+ public void GetRelationships3()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var node3 = Node.CreateNode();
+ var relationship1 = node1.CreateRelationshipTo(node2, "Test");
+ var relationship2 = node1.CreateRelationshipTo(node3, "Test");
+
+ var relationships1 = node1.GetRelationships("Test");
+ Assert.IsNotNull(relationships1);
+ Assert.IsTrue(relationships1.Count() == 2);
+
+ if (relationships1.First().EndNode == node2)
+ {
+ Assert.IsTrue(relationships1.First().Equals(relationship1));
+ Assert.IsTrue(relationships1.ElementAt(1).Equals(relationship2));
+ }
+ else
+ {
+ Assert.IsTrue(relationships1.First().Equals(relationship2));
+ Assert.IsTrue(relationships1.ElementAt(1).Equals(relationship1));
+ }
+
+ var relationships2 = node2.GetRelationships("Test");
+ Assert.IsNotNull(relationships2);
+ Assert.IsTrue(relationships2.Count() == 1);
+ Assert.IsTrue(relationships2.First().Equals(relationship1));
+
+ var relationships3 = node3.GetRelationships("Test");
+ Assert.IsNotNull(relationships3);
+ Assert.IsTrue(relationships3.Count() == 1);
+ Assert.IsTrue(relationships3.First().Equals(relationship2));
+ }
+
+ [TestMethod]
+ public void CreateUniqueNode()
+ {
+ var value = string.Concat("michael-", DateTime.Now.Millisecond);
+ var node1 = Node.CreateUniqueNode("people", "name", value);
+ Assert.IsNotNull(node1);
+
+ var node2 = Node.CreateUniqueNode("people", "name", value);
+ Assert.IsNull(node2);
+ }
+
+ [TestMethod]
+ public void AddNodeToIndexUnique()
+ {
+
+ var node1 = Node.CreateNode();
+
+ var node2 = Node.AddToIndex(node1, "people", "id", node1.Id, true);
+ Assert.IsNotNull(node2);
+
+ var node3 = node1.AddToIndex("people", "id", node1.Id, true);
+
+ Assert.IsNull(node3);
+
+ var node4 = node1.AddToIndex("people", "id", node1.Id);
+
+ Assert.IsNotNull(node4);
+ }
+
+
+ [TestMethod]
+ public void CreateUniqueRelationship()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+
+ var value = string.Concat("good-", DateTime.Now.Millisecond);
+
+ var relationship1 = Relationship.CreateUniqueRelationship(node1, node2, "knows", "rels", "friends", value);
+ Assert.IsNotNull(relationship1);
+
+ var relationship2 = Relationship.CreateUniqueRelationship(node1, node2, "knows", "rels", "friends", value);
+ Assert.IsNull(relationship2);
+ }
+
+ [TestMethod]
+ public void AddRelationshipToIndexUnique()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var relationship1 = Relationship.CreateRelationship(node1, node2, "knows");
+
+ var relationship2 = relationship1.AddToIndex("rels", "id", relationship1.Id, true);
+ Assert.IsNotNull(relationship2);
+
+ var relationship3 = relationship1.AddToIndex("rels", "id", relationship1.Id, true);
+
+ Assert.IsNull(relationship3);
+
+ var relationship4 = relationship1.AddToIndex("rels", "id", relationship1.Id);
+
+ Assert.IsNotNull(relationship4);
+ }
+
+ [TestMethod]
+ public void GetRelationships4()
+ {
+ var node1 = Node.CreateNode();
+ var node2 = Node.CreateNode();
+ var node3 = Node.CreateNode();
+ var relationship1 = Relationship.CreateRelationship(node1, node2, "a");
+ var relationship2 = Relationship.CreateRelationship(node1, node3, "b");
+
+ var relationships1 = node1.GetRelationships("a");
+ Assert.IsNotNull(relationships1);
+ Assert.IsTrue(relationships1.Count() == 1);
+ Assert.IsTrue(relationships1.First().Equals(relationship1));
+
+ var relationships2 = node1.GetRelationships("b");
+ Assert.IsNotNull(relationships2);
+ Assert.IsTrue(relationships2.Count() == 1);
+ Assert.IsTrue(relationships2.First().Equals(relationship2));
+
+ var relationships3 = node3.GetRelationships("a");
+ Assert.IsNotNull(relationships3);
+ Assert.IsTrue(relationships3.Count() == 0);
+ }
+
+ //[TestMethod]
+ //public void GetRelationships5()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "a");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node3.Id, "b");
+
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, new List<string> {"a", "b"});
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 2);
+ // Assert.IsTrue(relationships1.First().Equals(relationship1));
+ // Assert.IsTrue(relationships1.ElementAt(1).Equals(relationship2));
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, new List<string> { "a", "b" });
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship1));
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node3.Id, new List<string> { "a" });
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 0);
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsOut()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 1);
+ // Assert.IsTrue(relationships1.First().Equals(relationship1));
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 0);
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsOut2()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node2.Id, node3.Id, "Test");
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 1);
+ // Assert.IsTrue(relationships1.First().Equals(relationship1));
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship2));
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node3.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 0);
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsOut3()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node3.Id, "Test");
+
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 2);
+ // Assert.IsTrue(relationships1.First().Equals(relationship1));
+ // Assert.IsTrue(relationships1.ElementAt(1).Equals(relationship2));
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 0);
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node3.Id, RelationshipDirection.Out);
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 0);
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsOut4()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "a");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node3.Id, "b");
+
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out, "a");
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 1);
+ // Assert.IsTrue(relationships1.First().Equals(relationship1));
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out, "b");
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship2));
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.Out, "b");
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 0);
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsOut5()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "a");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node3.Id, "b");
+
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out, new List<string> { "a", "b" });
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 2);
+ // Assert.IsTrue(relationships1.First().Equals(relationship1));
+ // Assert.IsTrue(relationships1.ElementAt(1).Equals(relationship2));
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.Out, new List<string> { "b" });
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship2));
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.Out, new List<string> { "a" });
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 0);
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsIn()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 0);
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship1));
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsIn2()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node2.Id, node3.Id, "Test");
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 0);
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship1));
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node3.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 1);
+ // Assert.IsTrue(relationships3.First().Equals(relationship2));
+ //}
+
+ //[TestMethod]
+ //public void GetRelationshipsIn3()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node3.Id, "Test");
+
+ // var relationships1 = _nodeGraphStore.GetRelationships(node1.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships1);
+ // Assert.IsTrue(relationships1.Count() == 0);
+
+ // var relationships2 = _nodeGraphStore.GetRelationships(node2.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships2);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship1));
+
+ // var relationships3 = _nodeGraphStore.GetRelationships(node3.Id, RelationshipDirection.In);
+ // Assert.IsNotNull(relationships3);
+ // Assert.IsTrue(relationships3.Count() == 1);
+ // Assert.IsTrue(relationships3.First().Equals(relationship2));
+ //}
+
+ //[TestMethod]
+ //[ExpectedException(typeof(RelationshipNotFoundException))]
+ //public void DeleteRelationship()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var result = _nodeGraphStore.DeleteRelationship(relationship1.Id);
+ // Assert.IsTrue(result);
+ // _nodeGraphStore.GetRelationship(relationship1.Id); // Should throw RelationshipNotFoundException
+ //}
+
+ //[TestMethod]
+ //public void AddRelationshipToIndex()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+
+ // var relationship2 = _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "a", "foobar");
+ // Assert.IsTrue(relationship1.Equals(relationship2));
+
+ // var relationship3 = _nodeGraphStore.GetRelationships("relationships", "a", "foobar").Last();
+ // Assert.IsTrue(relationship1.Equals(relationship3));
+
+ // var relationship4 = _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "b", 42);
+ // Assert.IsTrue(relationship1.Equals(relationship4));
+
+ // var relationship5 = _nodeGraphStore.GetRelationships("relationships", "b", 42).Last();
+ // Assert.IsTrue(relationship1.Equals(relationship5));
+
+ // var relationship6 = _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "c", new DateTime(2012, 1, 1));
+ // Assert.IsTrue(relationship1.Equals(relationship6));
+
+ // var relationship7 = _nodeGraphStore.GetRelationships("relationships", "c", new DateTime(2012, 1, 1)).Last();
+ // Assert.IsTrue(relationship1.Equals(relationship7));
+ //}
+
+ //[TestMethod]
+ //public void RemoveRelationshipFromIndex()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+ // var node3 = _nodeGraphStore.CreateNode();
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "Test");
+ // var relationship2 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node3.Id, "Test");
+
+ // _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "a", "foobar");
+ // _nodeGraphStore.AddRelationshipToIndex(relationship2.Id, "relationships2", "a", "foobar");
+ // var result1 = _nodeGraphStore.RemoveRelationshipFromIndex(relationship1.Id, "relationships");
+ // Assert.IsTrue(result1);
+ // Assert.IsTrue(_nodeGraphStore.GetRelationships("relationships", "a", "foobar").Count() == 0);
+ // var relationships = _nodeGraphStore.GetRelationships("relationships2", "a", "foobar");
+ // Assert.IsTrue(relationships.Count() == 1);
+ // Assert.IsTrue(relationships.First().Equals(relationship2));
+
+ // _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "a", "foobar");
+ // _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "a", 42);
+ // _nodeGraphStore.AddRelationshipToIndex(relationship2.Id, "relationships", "b", 42);
+ // var result2 = _nodeGraphStore.RemoveRelationshipFromIndex(relationship1.Id, "relationships", "a");
+ // Assert.IsTrue(result2);
+ // Assert.IsTrue(_nodeGraphStore.GetRelationships("relationships", "a", "foobar").Count() == 0);
+ // Assert.IsTrue(_nodeGraphStore.GetRelationships("relationships", "a", 42).Count() == 0);
+ // var relationships1 = _nodeGraphStore.GetRelationships("relationships", "b", 42);
+ // Assert.IsTrue(relationships1.Count() == 1);
+ // Assert.IsTrue(relationships1.First().Equals(relationship2));
+
+ // _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "a", "foobar");
+ // _nodeGraphStore.AddRelationshipToIndex(relationship1.Id, "relationships", "a", 42);
+ // _nodeGraphStore.AddRelationshipToIndex(relationship2.Id, "relationships", "b", 42);
+ // var result3 = _nodeGraphStore.RemoveRelationshipFromIndex(relationship1.Id, "relationships", "a", "foobar");
+ // Assert.IsTrue(result3);
+ // Assert.IsTrue(_nodeGraphStore.GetRelationships("relationships", "a", "foobar").Count() == 0);
+ // var relationships2 = _nodeGraphStore.GetRelationships("relationships", "a", 42);
+ // Assert.IsTrue(relationships2.Count() == 1);
+ // Assert.IsTrue(relationships2.First().Equals(relationship1));
+ // var relationships3 = _nodeGraphStore.GetRelationships("relationships", "b", 42);
+ // Assert.IsTrue(relationships3.Count() == 1);
+ // Assert.IsTrue(relationships3.First().Equals(relationship2));
+ //}
+
+ //[TestMethod]
+ //public void LoadNodeProperties()
+ //{
+ // var properties1 = new Dictionary<string, object>();
+ // properties1.Add("A", 0);
+ // properties1.Add("B", "Foobar");
+ // properties1.Add("C", new DateTime(2012, 1, 1));
+ // var node1 = Node.CreateNode(new Properties(properties1));
+
+ // var properties2 = _nodeGraphStore.LoadNodeProperties(node1.Id);
+ // Assert.IsNotNull(properties2);
+ // Assert.IsTrue(properties2.GetProperty("A").Equals(0));
+ // Assert.IsTrue(properties2.GetProperty("B").Equals("Foobar"));
+ // Assert.IsTrue(properties2.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ // Assert.IsTrue(properties2.ToDictionary().Count == 3);
+ //}
+
+
+ //[TestMethod]
+ //[ExpectedException(typeof(NodeNotFoundException))]
+ //public void LoadNodePropertiesNotFound()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // _nodeGraphStore.LoadNodeProperties(node1.Id + 1); // Should throw exception
+ //}
+
+ [TestMethod]
+ public void SaveNodeProperties()
+ {
+ var properties1 = new Dictionary<string, object>();
+ properties1.Add("A", 0);
+ properties1.Add("B", "Foobar");
+ properties1.Add("C", new DateTime(2012, 1, 1));
+ var node1 = Node.CreateNode();
+ node1.SaveProperties(new Properties(properties1));
+
+ var node2 = Node.GetNode(node1.Id);
+ Assert.IsTrue(node2.Properties.GetProperty("A").Equals(0));
+ Assert.IsTrue(node2.Properties.GetProperty("B").Equals("Foobar"));
+ Assert.IsTrue(node2.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ Assert.IsTrue(node2.Properties.ToDictionary().Count == 3);
+ }
+
+ //[TestMethod]
+ //[ExpectedException(typeof(NodeNotFoundException))]
+ //public void SaveNodePropertiesNotFound()
+ //{
+ // var properties1 = new Dictionary<string, object>();
+ // properties1.Add("A", 0);
+ // properties1.Add("B", "Foobar");
+ // properties1.Add("C", new DateTime(2012, 1, 1));
+ // var node1 = _nodeGraphStore.CreateNode();
+ // _nodeGraphStore.SaveNodeProperties(node1.Id + 1, new Properties(properties1)); // Should throw exception
+ //}
+
+ //[TestMethod]
+ //public void LoadRelationshipProperties()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+
+ // var properties1 = new Dictionary<string, object>();
+ // properties1.Add("A", 0);
+ // properties1.Add("B", "Foobar");
+ // properties1.Add("C", new DateTime(2012, 1, 1));
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "test", new Properties(properties1));
+
+ // var properties2 = _nodeGraphStore.LoadRelationshipProperties(relationship1.Id);
+ // Assert.IsNotNull(properties2);
+ // Assert.IsTrue(properties2.GetProperty("A").Equals(0));
+ // Assert.IsTrue(properties2.GetProperty("B").Equals("Foobar"));
+ // Assert.IsTrue(properties2.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ // Assert.IsTrue(properties2.ToDictionary().Count == 3);
+ //}
+
+ //[TestMethod]
+ //public void SaveRelationshipProperties()
+ //{
+ // var node1 = _nodeGraphStore.CreateNode();
+ // var node2 = _nodeGraphStore.CreateNode();
+
+ // var properties1 = new Dictionary<string, object>();
+ // properties1.Add("A", 0);
+ // properties1.Add("B", "Foobar");
+ // properties1.Add("C", new DateTime(2012, 1, 1));
+ // var relationship1 = _nodeGraphStore.CreateRelationshipTo(node1.Id, node2.Id, "test");
+ // _nodeGraphStore.SaveRelationshipProperties(relationship1.Id, new Properties(properties1));
+
+ // var relationship2 = _nodeGraphStore.GetRelationship(relationship1.Id);
+ // Assert.IsTrue(relationship2.Properties.GetProperty("A").Equals(0));
+ // Assert.IsTrue(relationship2.Properties.GetProperty("B").Equals("Foobar"));
+ // Assert.IsTrue(relationship2.Properties.GetProperty("C").Equals(new DateTime(2012, 1, 1).ToString("s")));
+ // Assert.IsTrue(relationship2.Properties.ToDictionary().Count == 3);
+ //}
+ }
+}
View
12 Neo4jRestNet.sln
@@ -1,8 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Neo4jRestNetExamples\Examples.csproj", "{212505B1-8F5B-4835-966C-94806ED90D6C}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo4jRestNet.Test", "Neo4jRestNet.Test\Neo4jRestNet.Test.csproj", "{E0F54D59-3E2E-4328-B140-2211591ACB19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo4jRestNet", "Neo4jRestNet\Neo4jRestNet.csproj", "{D3704E7B-3783-4173-8114-D3E2647CBD8A}"
@@ -17,16 +15,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Debug|Any CPU.ActiveCfg = Debug|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Debug|x86.ActiveCfg = Debug|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Debug|x86.Build.0 = Debug|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Release|Any CPU.ActiveCfg = Release|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Release|Mixed Platforms.Build.0 = Release|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Release|x86.ActiveCfg = Release|x86
- {212505B1-8F5B-4835-966C-94806ED90D6C}.Release|x86.Build.0 = Release|x86
{E0F54D59-3E2E-4328-B140-2211591ACB19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0F54D59-3E2E-4328-B140-2211591ACB19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0F54D59-3E2E-4328-B140-2211591ACB19}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
View
19 Neo4jRestNet/Configuration/ConnectionCollection.cs
@@ -0,0 +1,19 @@
+using System.Configuration;
+
+namespace Neo4jRestNet.Configuration
+{
+
+ [ConfigurationCollection(typeof(ConnectionElement))]
+ public class ConnectionCollection : ConfigurationElementCollection
+{
+ protected override ConfigurationElement CreateNewElement()
+ {
+ return new ConnectionElement();
+ }
+
+ protected override object GetElementKey(ConfigurationElement element)
+ {
+ return ((ConnectionElement)element).Name;
+ }
+}
+}
View
81 Neo4jRestNet/Configuration/ConnectionElement.cs
@@ -0,0 +1,81 @@
+using System.Configuration;
+
+namespace Neo4jRestNet.Configuration
+{
+ public class ConnectionElement : ConfigurationElement
+ {
+ public string DbUrl
+ {
+ get
+ {
+ return string.Format("{0}://{1}:{2}{3}", Https ? "https" : "http", Domain, Port, DataPath);
+ }
+ }
+
+ public string CypherUrl
+ {
+ get
+ {
+ return string.Concat(DbUrl, "/cypher");
+ }
+ }
+
+ public string GremlinUrl
+ {
+ get
+ {
+ return string.Concat(DbUrl, GremlinPath);
+ }
+ }
+
+ [ConfigurationProperty("name", IsKey = true, IsRequired = true)]
+ public string Name
+ {
+ get { return (string)this["name"]; }
+ set { this["name"] = value; }
+ }
+
+ [ConfigurationProperty("https", IsRequired = false, DefaultValue = false)]
+ public bool Https
+ {
+ get { return (bool)this["https"]; }
+ set { this["https"] = value; }
+ }
+
+ [ConfigurationProperty("default", IsRequired = false, DefaultValue = false)]
+ public bool Default
+ {
+ get { return (bool)this["default"]; }
+ set { this["default"] = value; }
+ }
+
+ [ConfigurationProperty("domain", IsRequired = true)]
+ public string Domain
+ {
+ get { return (string)this["domain"]; }
+ set { this["domain"] = value; }
+ }
+
+ [ConfigurationProperty("port", IsRequired = false, DefaultValue = "7474")]
+ public string Port
+ {
+ get { return (string)this["port"]; }
+ set { this["port"] = value; }
+ }
+
+ [ConfigurationProperty("dataPath", IsRequired = false, DefaultValue = "/db/data")]
+ public string DataPath
+ {
+ get { return (string)this["dataPath"]; }
+ set { this["dataPath"] = string.Concat('/', value.TrimStart('/').TrimEnd('/')); }
+ }
+
+ [ConfigurationProperty("gremlinPath", IsRequired = false, DefaultValue = "/ext/GremlinPlugin/graphdb/execute_script")]
+ public string GremlinPath
+ {
+ get { return (string)this["gremlinPath"]; }
+ set { this["gremlinPath"] = string.Concat('/', value.TrimStart('/').TrimEnd('/')); }
+ }
+
+ }
+}
View
23 Neo4jRestNet/Configuration/ConnectionManager.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+
+namespace Neo4jRestNet.Configuration
+{
+ public static class ConnectionManager
+ {
+ private static readonly ConnectionSettings ConnectionConfiguration = ConfigurationManager.GetSection("neo4jRestNet") as ConnectionSettings;
+ private static readonly IEnumerable<ConnectionElement> Connections = ConnectionConfiguration.Connections.Cast<ConnectionElement>().ToList();
+
+ public static ConnectionElement Connection()
+ {
+ return Connections.First(f => f.Default);
+ }
+
+ public static ConnectionElement Connection(string name)
+ {
+ return Connections.First(f => f.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
+ }
+ }
+}
View
14 Neo4jRestNet/Configuration/ConnectionSettings.cs
@@ -0,0 +1,14 @@
+using System.Configuration;
+
+namespace Neo4jRestNet.Configuration
+{
+ public class ConnectionSettings : ConfigurationSection
+ {
+ [ConfigurationProperty("databases", IsDefaultCollection = true)]
+ public ConnectionCollection Connections
+ {
+ get { return (ConnectionCollection)this["databases"]; }
+ set { this["databases"] = value; }
+ }
+ }
+}
View
121 Neo4jRestNet/Core/BatchNodeStore.cs
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using Neo4jRestNet.Configuration;
+using Neo4jRestNet.Core.Exceptions;
+
+namespace Neo4jRestNet.Core
+{
+ public class BatchNodeStore : INodeStore
+ {
+ private BatchStore _batchStore;
+
+ public BatchNodeStore(BatchStore batchStore)
+ {
+ _batchStore = batchStore;
+ }
+
+ public Node GetRootNode(ConnectionElement connection)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Node GetNode(ConnectionElement connection, long nodeId)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable<Node> GetNode(ConnectionElement connection, string indexName, string key, object value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable<Node> GetNode(ConnectionElement connection, string indexName, string searchQuery)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Node CreateNode(ConnectionElement connection, Properties properties)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Node CreateUniqueNode(ConnectionElement connection, Properties properties, string indexName, string key, object value)
+ {
+ return _batchStore.CreateUniqueNode(connection, properties, indexName, key, value);
+ }
+
+ public Node Initilize(ConnectionElement connection, long id, Properties properties)
+ {
+ Id = id;
+ return new Node(this, properties);
+ }
+
+ public Node Initilize(string selfUri, Properties properties)
+ {
+ throw new NotImplementedException();
+ }
+
+ public HttpStatusCode DeleteNode()
+ {
+ throw new BatchDeleteNotSupportedException();
+ }
+
+ public Properties GetProperties()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SaveProperties(Properties properties)
+ {
+ _batchStore.SaveProperties(this, properties);
+ }
+
+ public Relationship CreateRelationship(Node startNode, Node endNode, string relationshipType, Properties properties)
+ {
+ return _batchStore.CreateRelationship(startNode, endNode, relationshipType, properties);
+ }
+
+ public IEnumerable<Relationship> GetRelationships(RelationshipDirection direction, IEnumerable<string> relationshipTypes)
+ {
+ throw new BatchGetRelationshipsNotSupportedException();
+ }
+
+ public Node AddToIndex(ConnectionElement connection, Node node, string indexName, string key, object value, bool unique = false)
+ {
+ return _batchStore.AddToIndex(connection, node, indexName, key, value, unique);
+ }
+
+ public bool RemoveFromIndex(ConnectionElement connection, Node node, string indexName)
+ {
+ throw new BatchRemoveFromIndexNotSupportedException();
+ }
+
+ public bool RemoveFromIndex(ConnectionElement connection, Node node, string indexName, string key)
+ {
+ throw new BatchRemoveFromIndexNotSupportedException();
+ }
+
+ public bool RemoveFromIndex(ConnectionElement connection, Node node, string indexName, string key, object value)
+ {
+ throw new BatchRemoveFromIndexNotSupportedException();
+ }
+
+ public long Id { get; private set; }
+
+ public string DbUrl
+ {
+ get { return "batch"; }
+ }
+
+ public string Self
+ {
+ get
+ {
+ return string.Concat("batch/node/", Id);
+ }
+ }
+ }
+}
View
122 Neo4jRestNet/Core/BatchRelationshipStore.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Neo4jRestNet.Configuration;
+using Neo4jRestNet.Core.Exceptions;
+
+namespace Neo4jRestNet.Core
+{
+ public class BatchRelationshipStore : IRelationshipStore
+ {
+ private BatchStore _batchStore;
+
+ public BatchRelationshipStore(BatchStore batchStore)
+ {
+ _batchStore = batchStore;
+ }
+
+ public Relationship GetRelationship(ConnectionElement connection, long relationshipId)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable<Relationship> GetRelationship(ConnectionElement connection, string indexName, string key, object value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable<Relationship> GetRelationship(ConnectionElement connection, string indexName, string searchQuery)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Relationship CreateRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Relationship CreateUniqueRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties, string indexName, string key, object value)
+ {
+ return _batchStore.CreateUniqueRelationship(connection, startNode, endNode, name, properties, indexName, key, value);
+ }
+
+ public Relationship Initilize(ConnectionElement connection, long id, Properties properties)
+ {
+ Id = id;
+ return new Relationship(this, properties);
+ }
+
+ public Relationship Initilize(string selfUri, Properties properties)
+ {
+ throw new NotImplementedException();
+ }
+
+ public System.Net.HttpStatusCode DeleteRelationship(ConnectionElement connection)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Properties GetProperties()
+ {
+ _batchStore.GetProperties(this);
+
+ return null;
+ }
+
+ public void SaveProperties(Properties properties)
+ {
+ _batchStore.SaveProperties(this, properties);
+ }
+
+ public Node StartNode
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public Node EndNode
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public string Type
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public Relationship AddToIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value, bool unique = false)
+ {
+ return _batchStore.AddToIndex(connection, relationship, indexName, key, value, unique);
+ }
+
+ public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName)
+ {
+ throw new BatchRemoveFromIndexNotSupportedException();
+ }
+
+ public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName, string key)
+ {
+ throw new BatchRemoveFromIndexNotSupportedException();
+ }
+
+ public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
+ {
+ throw new BatchRemoveFromIndexNotSupportedException();
+ }
+
+ public long Id { get; private set; }
+
+ public string DbUrl
+ {
+ get { return "batch"; }
+ }
+
+ public string Self
+ {
+ get
+ {
+ return string.Concat("batch/relationship/", Id);
+ }
+ }
+ }
+}
View
716 Neo4jRestNet/Core/BatchStore.cs
@@ -0,0 +1,716 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using Neo4jRestNet.Configuration;
+using Neo4jRestNet.Core.Exceptions;
+using Neo4jRestNet.Rest;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Linq;
+
+namespace Neo4jRestNet.Core
+{
+
+ class BatchJob
+ {
+ public HttpRest.Method Method { get; set; }
+ public string To { get; set; }
+ public JObject Body { get; set; }
+ public object GraphObject { get; set; }
+ public long Id { get; set; }
+ public bool ReloadProperties { get; set; }
+ }
+
+ public class BatchStore : INodeStore, IRelationshipStore
+ {
+
+ private List<BatchJob> _jobs = new List<BatchJob>();
+ public bool Open { get; private set; }
+
+ private string _jsonResponse;
+ private bool _parsed;
+
+ public BatchStore()
+ {
+ Open = true;
+ }
+
+ private bool IsBatchObject(IGraphObject obj)
+ {
+ return obj != null && obj.DbUrl == "batch";
+ }
+
+ public bool Execute()
+ {
+ return Execute(ConnectionManager.Connection());
+ }
+
+ public bool Execute(ConnectionElement connection)
+ {
+ Open = false; // Close the Batch
+
+ var jsonJobs = new JArray();
+
+ var index = 0;
+ foreach (var job in _jobs)
+ {
+ var jsonJobDescription = new JObject
+ {
+ {"method", JToken.FromObject(job.Method.ToString())},
+ {"to", JToken.FromObject(job.To)},
+ {"id", JToken.FromObject(index)}
+ };
+
+ if (job.Body != null)
+ {
+ jsonJobDescription.Add("body", job.Body);
+ }
+
+ jsonJobs.Add(jsonJobDescription);
+
+ index++;
+ }
+
+ string response;
+ var status = HttpRest.Post(string.Concat(connection.DbUrl, "/batch"), jsonJobs.ToString(Formatting.None, new IsoDateTimeConverter()), out response);
+
+ if (status != HttpStatusCode.OK)
+ {
+ return false;
+ }
+
+ _jsonResponse = response;
+
+ return true;
+ }
+
+ private IGraphObject ParseJsonGraphObject(JObject jsonGraphObject, bool reloadProperties)
+ {
+ var selfArray = jsonGraphObject["self"].Value<string>().Split('/');
+ if (selfArray.Length < 2)
+ {
+ throw new Exception("Invalid response from batch");
+ }
+
+ switch (selfArray[selfArray.Length - 2])
+ {
+ case "node":
+ var node = RestNodeStore.CreateNodeFromJson(jsonGraphObject);
+ if (reloadProperties)
+ {
+ node.Properties = null;
+ }
+
+ return node;
+
+ case "relationship":
+ var relationship = RestRelationshipStore.CreateRelationshipFromJson(jsonGraphObject);
+ if (reloadProperties)
+ {
+ relationship.Properties = null;
+ }
+
+ return relationship;
+
+ default:
+ throw new Exception("Invalid response from batch");
+ }
+ }
+
+ private void ParseJsonResponse()
+ {
+ foreach (var jobResponse in JArray.Parse(_jsonResponse))
+ {
+ var id = jobResponse["id"].Value<int>();
+ //var from = jobResponse["from"].Value<string>();
+ //var location = jobResponse["location"].Value<string>();
+
+ if (jobResponse["body"] == null)
+ {
+ return;
+ }
+
+ switch (jobResponse["body"].Type)
+ {
+ case JTokenType.Object:
+ _jobs[id].GraphObject = ParseJsonGraphObject(jobResponse["body"].Value<JObject>(), _jobs[id].ReloadProperties);
+ break;
+
+ case JTokenType.Array:
+ _jobs[id].GraphObject = jobResponse["body"].Value<JArray>().Select(objBody => ParseJsonGraphObject((JObject)objBody, _jobs[id].ReloadProperties)).ToList();
+ break;
+
+ default:
+ throw new Exception("Invalid response from batch");
+ }
+ }
+ }
+
+ public T GetGraphObject<T>(T graphObject) where T : IGraphObject
+ {
+ if (Open)
+ {
+ throw new Exception("Batch store must be closed before a calling GetGraphObject");
+ }
+
+ if (!_parsed)
+ {
+ ParseJsonResponse();
+ _parsed = true;
+ }
+
+ return (T)_jobs[(int)graphObject.Id].GraphObject;
+ }
+
+ public IEnumerable<T> GetGraphObject<T>(IEnumerable<T> graphObjects) where T : IGraphObject
+ {