public void Execute_Edge_DataSetFilled() { GraphClient session = new GraphClientFactory().Instantiate(ConnectionStringReader.GetLocaleGraph()) as GraphClient; var statement = Mock.Of <IQuery>(x => x.Statement == "g.E()"); GraphCommandOperation cosmosdbQuery = new GraphCommandFactory().Instantiate(session, statement, null).Implementation as GraphCommandOperation; var engine = new GraphExecutionEngine(session.CreateClientOperation(), cosmosdbQuery); var ds = engine.Execute(); Assert.That(ds.Tables, Has.Count.EqualTo(1)); Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(3)); Assert.That(ds.Tables[0].Columns, Has.Count.EqualTo(7)); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("id")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("label")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("type")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("inV")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("outV")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("inVLabel")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("outVLabel")); var outVs = new List <object>(); var inVs = new List <object>(); foreach (DataRow row in ds.Tables[0].Rows) { for (int i = 0; i < ds.Tables[0].Columns.Count; i++) { if (row.Table.Columns[i].ColumnName == "outV") { outVs.Add(row.ItemArray[i]); } else if (row.Table.Columns[i].ColumnName == "inV") { inVs.Add(row.ItemArray[i]); } } } foreach (var expectedInV in new[] { "mary", "ben", "robin" }) { Assert.That(inVs, Has.Member(expectedInV)); } foreach (var expectedOutV in new[] { "thomas", "ben" }) { Assert.That(outVs, Has.Member(expectedOutV)); } foreach (DataRow row in ds.Tables[0].Rows) { Assert.That(row["id"], Is.Not.Null.Or.Empty); Assert.That(row["inVLabel"], Is.EqualTo("person")); Assert.That(row["outVLabel"], Is.EqualTo("person")); Assert.That(row["label"], Is.EqualTo("knows")); Assert.That(row["type"], Is.EqualTo("edge")); } }
public void Execute_Vertex_DataSetFilled() { GraphClient session = new GraphClientFactory().Instantiate(ConnectionStringReader.GetLocaleGraph()) as GraphClient; var statement = Mock.Of <IQuery>(x => x.Statement == "g.V()"); GraphCommandOperation cosmosdbQuery = new GraphCommandFactory().Instantiate(session, statement, null).Implementation as GraphCommandOperation; var engine = new GraphExecutionEngine(session.CreateClientOperation(), cosmosdbQuery); var ds = engine.Execute(); Assert.That(ds.Tables, Has.Count.EqualTo(1)); Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(4)); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("id")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("label")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("type")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("firstName")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("age")); var firstNames = new List <object>(); var ages = new List <object>(); foreach (DataRow row in ds.Tables[0].Rows) { for (int i = 0; i < ds.Tables[0].Columns.Count; i++) { if (row.Table.Columns[i].ColumnName == "firstName") { firstNames.Add(row.ItemArray[i]); } else if (row.Table.Columns[i].ColumnName == "age") { ages.Add(row.ItemArray[i]); } } } foreach (var expectedFirstName in new[] { "Thomas", "Mary", "Ben", "Robin" }) { Assert.That(firstNames, Has.Member(expectedFirstName)); } foreach (var expectedAge in new object[] { 44, DBNull.Value, 39 }) { Assert.That(ages, Has.Member(expectedAge)); } foreach (DataRow row in ds.Tables[0].Rows) { Assert.That(row["id"], Is.Not.Null.Or.Empty); Assert.That(row["label"], Is.EqualTo("person")); Assert.That(row["type"], Is.EqualTo("vertex")); } }
public void Execute_ProjectionOfObjects_DataSetFilled() { GraphClient session = new GraphClientFactory().Instantiate(ConnectionStringReader.GetLocaleGraph()) as GraphClient; var statement = Mock.Of <IQuery>(x => x.Statement == "g.V().project('FirstName','KnowsCount').by('firstName').by(out().Count())"); GraphCommandOperation cosmosdbQuery = new GraphCommandFactory().Instantiate(session, statement).Implementation as GraphCommandOperation; var engine = new GraphExecutionEngine(session.CreateClientOperation(), cosmosdbQuery); var ds = engine.Execute(); Assert.That(ds.Tables, Has.Count.EqualTo(1)); Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(4)); Assert.That(ds.Tables[0].Columns, Has.Count.EqualTo(2)); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("FirstName")); Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("KnowsCount")); var firstNames = new List <object>(); var knowsCount = new List <object>(); foreach (DataRow row in ds.Tables[0].Rows) { for (int i = 0; i < ds.Tables[0].Columns.Count; i++) { if (row.Table.Columns[i].ColumnName == "FirstName") { firstNames.Add(row.ItemArray[i]); } else if (row.Table.Columns[i].ColumnName == "KnowsCount") { knowsCount.Add(row.ItemArray[i]); } } } foreach (var expectedFirstName in new[] { "Thomas", "Mary", "Ben", "Robin" }) { Assert.That(firstNames, Has.Member(expectedFirstName)); } foreach (var expectedKnowsCount in new object[] { 2, 1, 0 }) { Assert.That(knowsCount, Has.Member(expectedKnowsCount)); } }