public void Should_get_all_graphs() { List <String> vertexCollections = new List <String>(); vertexCollections.Add("vc1"); vertexCollections.Add("vc2"); List <ArangoGraphEdgeDefinition> eds = new List <ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition ed1 = new ArangoGraphEdgeDefinition( "ed1", new List <String> { "f1", "f2" }, new List <String> { "t1", "t2" } ); eds.Add(ed1); db.Graph.Create("UnitTestGraph1", eds, vertexCollections); db.Graph.Create("UnitTestGraph2"); var result = db.Graph.Get(); Assert.AreEqual(result.Count, 2); }
public void Should_get_graph_by_name() { List <String> vertexCollections = new List <String>(); vertexCollections.Add("vc1"); vertexCollections.Add("vc2"); vertexCollections.Add("t1"); List <ArangoGraphEdgeDefinition> eds = new List <ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition ed1 = new ArangoGraphEdgeDefinition( "ed1", new List <String> { "f1", "f2" }, new List <String> { "t1", "t2" } ); eds.Add(ed1); string name = "UnitTestGraph"; db.Graph.Create(name, eds, vertexCollections); ArangoGraph graph = db.Graph.Get(name); Assert.AreEqual(graph.Name, name); Assert.AreEqual(graph.edgeDefinitions.First().collection, ed1.collection); Assert.AreEqual(graph.edgeDefinitions.First().from, ed1.from); Assert.AreEqual(graph.edgeDefinitions.First().to, ed1.to); Assert.AreEqual(6, graph.vertexCollections().Count); }
private ArangoGraph documentToGraph(Document doc) { string graphName; if (doc.ContainsKey("name")) { graphName = doc.String("name"); } else { graphName = doc.String("_key"); } ArangoGraph graph = new ArangoGraph(_connection, graphName); graph.orphanCollections = doc.List <String>("orphanCollections"); List <Object> eDs = doc.List <Object>("edgeDefinitions"); List <ArangoGraphEdgeDefinition> edgeDefinitions = new List <ArangoGraphEdgeDefinition>(); foreach (Document eD in eDs) { ArangoGraphEdgeDefinition edgeDefinition = new ArangoGraphEdgeDefinition( eD.String("collection"), eD.List <String>("from"), eD.List <String>("to") ); edgeDefinitions.Add(edgeDefinition); } graph.edgeDefinitions = edgeDefinitions; return(graph); }
[SetUp()] public void Init() { Database.CreateTestDatabase(Database.TestDatabaseGeneral); db = Database.GetTestDatabase(); List <ArangoGraphEdgeDefinition> eds = new List <ArangoGraphEdgeDefinition>(); ed1 = new ArangoGraphEdgeDefinition( edgeCol1, new List <String> { fromCol1, fromCol2 }, new List <String> { toCol1, toCol2 } ); eds.Add(ed1); ed2 = new ArangoGraphEdgeDefinition( edgeCol2, new List <String> { fromCol2, fromCol3 }, new List <String> { toCol2, toCol3 } ); eds.Add(ed2); List <String> vertexCollections = new List <String>(); vertexCollections.Add(vertexCol1); vertexCollections.Add(vertexCol2); vertexCollections.Add(vertexCol3); g = db.Graph.Create(graphName, eds, vertexCollections); }
public void Should_get_all_single_edge_definition() { ArangoGraphEdgeDefinition result = g.edgeDefinition(edgeCol1); Assert.AreEqual(ed1.collection, result.collection); Assert.AreEqual(ed1.from, result.from); Assert.AreEqual(ed1.to, result.to); }
public void Should_add_an_edge_definition() { Assert.AreEqual(2, g.edgeDefinitions.Count()); string edgeCol = "UnitTestEdgeCol47"; ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( edgeCol, new List<string>{fromCol1}, new List<string>{toCol1} ); g.addEdgeDefinition(ed); Assert.AreEqual(3, g.edgeDefinitions.Count()); }
public void Should_add_an_edge_definition() { Assert.AreEqual(2, g.edgeDefinitions.Count()); string edgeCol = "UnitTestEdgeCol47"; ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( edgeCol, new List <string> { fromCol1 }, new List <string> { toCol1 } ); g.addEdgeDefinition(ed); Assert.AreEqual(3, g.edgeDefinitions.Count()); }
public void Should_update_an_edge_definition() { ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( edgeCol1, new List <string> { fromCol1, vertexCol1 }, new List <string> { toCol2, vertexCol3 } ); g.updateEdgeDefinition(ed); Assert.False(g.orphanCollections.Contains(vertexCol1)); Assert.True(g.orphanCollections.Contains(vertexCol2)); Assert.False(g.orphanCollections.Contains(vertexCol3)); Assert.True(g.orphanCollections.Contains(toCol1)); }
public void Should_update_an_edge_definition_error() { ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( "blub", new List <string> { fromCol1, vertexCol1 }, new List <string> { toCol2, vertexCol3 } ); try { g.updateEdgeDefinition(ed); } catch (ArangoException e) { Assert.NotNull(e); } }
public void Should_add_an_edge_definition_error() { Assert.AreEqual(2, g.edgeDefinitions.Count()); ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( edgeCol1, new List <string> { fromCol2 }, new List <string> { toCol2 } ); try { g.addEdgeDefinition(ed); } catch (ArangoException e) { Assert.NotNull(e); } }
/// <summary> /// Update an existing edge definition. /// </summary> internal ArangoGraph updateEdgeDefinition(ArangoGraphEdgeDefinition edgeDefinition) { var request = new Request(RequestType.Collection, HttpMethod.Put); request.RelativeUri = string.Join("/", _apiUri, "edge", edgeDefinition.collection); Document body = new Document(); body.Add("collection", edgeDefinition.collection); body.Add("from", edgeDefinition.from); body.Add("to", edgeDefinition.to); request.Body = body.Serialize(); var response = _connection.Process(request); ArangoGraph result = new ArangoGraph(_connection, _graphName); switch (response.StatusCode) { case HttpStatusCode.OK: result = this.responseToGraph(response); break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object <Exception>("driverInnerException") ); } break; } return(result); }
public void Should_create_and_get_graph_with_edge_definition() { ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( "unitTestEdge", new List <string> { "unitTestFrom" }, new List <string> { "unitTestTo" } ); List <ArangoGraphEdgeDefinition> edgeDefinitions = new List <ArangoGraphEdgeDefinition> { ed }; string name = "UnitTestGraph"; db.Graph.Create(name, edgeDefinitions); ArangoGraph graph = db.Graph.Get(name); Assert.AreEqual(name, graph.Name); Assert.AreEqual(1, graph.edgeDefinitions.Count); Assert.AreEqual(0, graph.orphanCollections.Count); }
public void Init() { Database.CreateTestDatabase(Database.TestDatabaseGeneral); db = Database.GetTestDatabase(); List<ArangoGraphEdgeDefinition> eds = new List<ArangoGraphEdgeDefinition>(); ed1 = new ArangoGraphEdgeDefinition( edgeCol1, new List<String>{fromCol1, fromCol2}, new List<String>{toCol1, toCol2} ); eds.Add(ed1); ed2 = new ArangoGraphEdgeDefinition( edgeCol2, new List<String>{fromCol2, fromCol3}, new List<String>{toCol2, toCol3} ); eds.Add(ed2); List<String> vertexCollections = new List<String>(); vertexCollections.Add(vertexCol1); vertexCollections.Add(vertexCol2); vertexCollections.Add(vertexCol3); g = db.Graph.Create(graphName, eds, vertexCollections); }
private ArangoGraph documentToGraph(Document doc) { string graphName; if (doc.ContainsKey("name")) { graphName = doc.String("name"); } else { graphName = doc.String("_key"); } ArangoGraph graph = new ArangoGraph(_connection, graphName); graph.orphanCollections = doc.List<String>("orphanCollections"); List<Object> eDs = doc.List<Object>("edgeDefinitions"); List<ArangoGraphEdgeDefinition> edgeDefinitions = new List<ArangoGraphEdgeDefinition>(); foreach(Document eD in eDs) { ArangoGraphEdgeDefinition edgeDefinition = new ArangoGraphEdgeDefinition( eD.String("collection"), eD.List<String>("from"), eD.List<String>("to") ); edgeDefinitions.Add(edgeDefinition); } graph.edgeDefinitions = edgeDefinitions; return graph; }
public void Should_create_and_get_graph_with_edge_definition() { ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( "unitTestEdge", new List<string>{"unitTestFrom"}, new List<string>{"unitTestTo"} ); List<ArangoGraphEdgeDefinition> edgeDefinitions = new List<ArangoGraphEdgeDefinition>{ed}; string name = "UnitTestGraph"; db.Graph.Create(name, edgeDefinitions); ArangoGraph graph = db.Graph.Get(name); Assert.AreEqual(name, graph.Name); Assert.AreEqual(1, graph.edgeDefinitions.Count); Assert.AreEqual(0, graph.orphanCollections.Count); }
public void Should_update_an_edge_definition_error() { ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( "blub", new List<string>{fromCol1, vertexCol1}, new List<string>{toCol2, vertexCol3} ); try { g.updateEdgeDefinition(ed); } catch (ArangoException e) { Assert.NotNull(e); } }
public void Should_get_all_graphs() { List<String> vertexCollections = new List<String>(); vertexCollections.Add("vc1"); vertexCollections.Add("vc2"); List<ArangoGraphEdgeDefinition> eds = new List<ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition ed1 = new ArangoGraphEdgeDefinition( "ed1", new List<String>{"f1", "f2"}, new List<String>{"t1", "t2"} ); eds.Add(ed1); db.Graph.Create("UnitTestGraph1", eds, vertexCollections); db.Graph.Create("UnitTestGraph2"); var result = db.Graph.Get(); Assert.AreEqual(result.Count, 2); }
public void Should_delete_existing_graph_and_drop_collections() { string v11 = "v11"; string v12 = "v12"; string t11 = "t11"; string t12 = "t12"; string f11 = "f11"; string f12 = "f12"; string ed1 = "ed1"; string name1 = "UnitTestGraph1"; string ed2 = "ed2"; string name2 = "UnitTestGraph2"; ArangoDatabase db = Database.GetTestDatabase(); //Graph 1 List<ArangoGraphEdgeDefinition> eds1 = new List<ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition edgeDef1 = new ArangoGraphEdgeDefinition( ed1, new List<String>{f11, f12}, new List<String>{t11, t12} ); eds1.Add(edgeDef1); List<String> vertexCollections1 = new List<String>(); vertexCollections1.Add(v11); vertexCollections1.Add(v12); db.Graph.Create(name1, eds1, vertexCollections1); //Graph 2 List<ArangoGraphEdgeDefinition> eds2 = new List<ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition edgeDef2 = new ArangoGraphEdgeDefinition( ed2, new List<String>{f11}, new List<String>{t12} ); eds2.Add(edgeDef2); List<String> vertexCollections2 = new List<String>(); vertexCollections2.Add(v12); db.Graph.Create(name2, eds2, vertexCollections2); Assert.AreEqual(2, db.Graph.Get().Count); Assert.True(db.Graph.Exists(name1)); Assert.True(db.Graph.Exists(name2)); Assert.True(db.Collection.Exists(ed1)); Assert.True(db.Collection.Exists(ed2)); Assert.True(db.Collection.Exists(f11)); Assert.True(db.Collection.Exists(f12)); Assert.True(db.Collection.Exists(t11)); Assert.True(db.Collection.Exists(t12)); Assert.True(db.Collection.Exists(v11)); Assert.True(db.Collection.Exists(v12)); db.Graph.Delete(name1, true); Assert.False(db.Graph.Exists(name1)); Assert.True(db.Graph.Exists(name2)); Assert.AreEqual(1, db.Graph.Get().Count); Assert.False(db.Collection.Exists(ed1)); Assert.True(db.Collection.Exists(ed2)); Assert.True(db.Collection.Exists(f11)); Assert.False(db.Collection.Exists(f12)); Assert.False(db.Collection.Exists(t11)); Assert.True(db.Collection.Exists(t12)); Assert.False(db.Collection.Exists(v11)); Assert.True(db.Collection.Exists(v12)); }
public void Should_get_graph_by_name() { List<String> vertexCollections = new List<String>(); vertexCollections.Add("vc1"); vertexCollections.Add("vc2"); vertexCollections.Add("t1"); List<ArangoGraphEdgeDefinition> eds = new List<ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition ed1 = new ArangoGraphEdgeDefinition( "ed1", new List<String>{"f1", "f2"}, new List<String>{"t1", "t2"} ); eds.Add(ed1); string name = "UnitTestGraph"; db.Graph.Create(name, eds, vertexCollections); ArangoGraph graph = db.Graph.Get(name); Assert.AreEqual(graph.Name, name); Assert.AreEqual(graph.edgeDefinitions.First().collection, ed1.collection); Assert.AreEqual(graph.edgeDefinitions.First().from, ed1.from); Assert.AreEqual(graph.edgeDefinitions.First().to, ed1.to); Assert.AreEqual(6, graph.vertexCollections().Count); }
public void Should_get_all_single_edge_definition_null() { ArangoGraphEdgeDefinition result = g.edgeDefinition("blub"); Assert.Null(result); }
public void Should_add_an_edge_definition_error() { Assert.AreEqual(2, g.edgeDefinitions.Count()); ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( edgeCol1, new List<string>{fromCol2}, new List<string>{toCol2} ); try { g.addEdgeDefinition(ed); } catch (ArangoException e) { Assert.NotNull(e); } }
/// <summary> /// Gets the list of all edge collections. /// </summary> internal ArangoGraph addEdgeDefinition(ArangoGraphEdgeDefinition edgeDefinition) { var request = new Request(RequestType.Collection, HttpMethod.Post); request.RelativeUri = string.Join("/", _apiUri, "edge"); Document body = new Document(); body.Add("collection", edgeDefinition.collection); body.Add("from", edgeDefinition.from); body.Add("to", edgeDefinition.to); request.Body = body.Serialize(); var response = _connection.Process(request); ArangoGraph result = new ArangoGraph(_connection, _graphName); switch (response.StatusCode) { case HttpStatusCode.Created: result = this.responseToGraph(response); break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object<Exception>("driverInnerException") ); } break; } return result; }
public void Should_update_an_edge_definition() { ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition( edgeCol1, new List<string>{fromCol1, vertexCol1}, new List<string>{toCol2, vertexCol3} ); g.updateEdgeDefinition(ed); Assert.False(g.orphanCollections.Contains(vertexCol1)); Assert.True(g.orphanCollections.Contains(vertexCol2)); Assert.False(g.orphanCollections.Contains(vertexCol3)); Assert.True(g.orphanCollections.Contains(toCol1)); }
/// <summary> /// Add new edge definition to the graph. /// </summary> public ArangoGraph addEdgeDefinition(ArangoGraphEdgeDefinition edgeDefinition) { ArangoGraph g = _graphGraphOps.addEdgeDefinition(edgeDefinition); this.updateGraph(g); return g; }
public void Should_delete_existing_graph_and_drop_collections() { string v11 = "v11"; string v12 = "v12"; string t11 = "t11"; string t12 = "t12"; string f11 = "f11"; string f12 = "f12"; string ed1 = "ed1"; string name1 = "UnitTestGraph1"; string ed2 = "ed2"; string name2 = "UnitTestGraph2"; ArangoDatabase db = Database.GetTestDatabase(); //Graph 1 List <ArangoGraphEdgeDefinition> eds1 = new List <ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition edgeDef1 = new ArangoGraphEdgeDefinition( ed1, new List <String> { f11, f12 }, new List <String> { t11, t12 } ); eds1.Add(edgeDef1); List <String> vertexCollections1 = new List <String>(); vertexCollections1.Add(v11); vertexCollections1.Add(v12); db.Graph.Create(name1, eds1, vertexCollections1); //Graph 2 List <ArangoGraphEdgeDefinition> eds2 = new List <ArangoGraphEdgeDefinition>(); ArangoGraphEdgeDefinition edgeDef2 = new ArangoGraphEdgeDefinition( ed2, new List <String> { f11 }, new List <String> { t12 } ); eds2.Add(edgeDef2); List <String> vertexCollections2 = new List <String>(); vertexCollections2.Add(v12); db.Graph.Create(name2, eds2, vertexCollections2); Assert.AreEqual(2, db.Graph.Get().Count); Assert.True(db.Graph.Exists(name1)); Assert.True(db.Graph.Exists(name2)); Assert.True(db.Collection.Exists(ed1)); Assert.True(db.Collection.Exists(ed2)); Assert.True(db.Collection.Exists(f11)); Assert.True(db.Collection.Exists(f12)); Assert.True(db.Collection.Exists(t11)); Assert.True(db.Collection.Exists(t12)); Assert.True(db.Collection.Exists(v11)); Assert.True(db.Collection.Exists(v12)); db.Graph.Delete(name1, true); Assert.False(db.Graph.Exists(name1)); Assert.True(db.Graph.Exists(name2)); Assert.AreEqual(1, db.Graph.Get().Count); Assert.False(db.Collection.Exists(ed1)); Assert.True(db.Collection.Exists(ed2)); Assert.True(db.Collection.Exists(f11)); Assert.False(db.Collection.Exists(f12)); Assert.False(db.Collection.Exists(t11)); Assert.True(db.Collection.Exists(t12)); Assert.False(db.Collection.Exists(v11)); Assert.True(db.Collection.Exists(v12)); }