Beispiel #1
0
        public void InstantiateUnderlyingSession_CosmosDbConnectionString_ISession()
        {
            var factory = new GremlinLikeClientFactory();
            var client  = factory.Instantiate($@"Hostname=your-endpoint.gremlin.cosmosdb.azure.com;port=443;EnableSsl=true;Username=/dbs/database/colls/;password=p@ssw0rd;api=gremlin");

            Assert.That(client.UnderlyingSessionType, Is.EqualTo(typeof(GremlinClientOperation)));
        }
Beispiel #2
0
        public void Instantiate_GremlinLikeConnectionString_CorrectPort()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinLikeConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.Port, Is.EqualTo(443));
        }
Beispiel #3
0
        public void Instantiate_GremlinLikeConnectionString_CorrectHostName()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinLikeConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.Hostname, Is.EqualTo("my-endpoint.documents.azure.com"));
        }
Beispiel #4
0
        public void Instantiate_GremlinConnectionString_GremlinClient()
        {
            var factory = new GremlinLikeClientFactory();
            var session = factory.Instantiate($@"Hostname=your-endpoint.gremlin.cosmosdb.azure.com;port=443;EnableSsl=true;Username=/dbs/database/colls/collection;password=p@ssw0rd;api=gremlin");

            Assert.That(session, Is.Not.Null);
            Assert.That(session, Is.TypeOf <GremlinClient>());
        }
Beispiel #5
0
        public void Instantiate_GremlinLikeConnectionString_CorrectPassword()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinLikeConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.Password, Is.EqualTo("xLNOQPTaBpDrCxMoUTFVavrtnjkpSw5qaVbbxSazCtKNFopFjAZE9aeLKAdCuiQSqTUaRhffFGrJKJA89GTsdg=="));
        }
Beispiel #6
0
        public void Instantiate_GremlinLikeConnectionString_CorrectUsername()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinLikeConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.Username, Is.EqualTo("/dbs/myDatabase/colls/myCollection"));
        }
Beispiel #7
0
        public void Instantiate_GremlinShortConnectionString_CorrectUsername()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinShortConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.Username, Is.EqualTo("admin"));
        }
Beispiel #8
0
        public void Instantiate_GremlinShortConnectionString_CorrectPassword()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinShortConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.Password, Is.EqualTo("p@ssw0rd"));
        }
Beispiel #9
0
        public void Instantiate_GremlinLikeConnectionString_CorrectEnableSsl()
        {
            var factory       = new GremlinLikeClientFactory();
            var session       = factory.Instantiate(GremlinLikeConnectionString);
            var gremlinClient = session as GremlinClient;

            Assert.That(gremlinClient.EnableSsl, Is.EqualTo(true));
        }
Beispiel #10
0
        public void InstantiateCreate_CosmosDbConnectionString_ISession()
        {
            var factory           = new GremlinLikeClientFactory();
            var client            = factory.Instantiate($@"Hostname=your-endpoint.gremlin.cosmosdb.azure.com;port=443;EnableSsl=true;Username=/dbs/database/colls/;password=p@ssw0rd;api=gremlin");
            var underlyingSession = client.CreateNew();

            Assert.That(underlyingSession, Is.Not.Null);
            Assert.That(underlyingSession, Is.AssignableTo <GremlinClientOperation>());
        }
        public void Execute_Vertex_DataSetFilled()
        {
            var client    = new GremlinLikeClientFactory().Instantiate(ConnectionStringReader.GetGremlin());
            var statement = Mock.Of <IQuery>(x => x.Statement == "g.V()");
            GremlinCommandOperation gremlinQuery = new GremlinCommandFactory().Instantiate(client, statement).Implementation as GremlinCommandOperation;

            var engine = new GremlinExecutionEngine((GremlinClientOperation)(client.CreateNew()), gremlinQuery);

            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_NullString_ScalarReturned()
        {
            var client    = new GremlinLikeClientFactory().Instantiate(ConnectionStringReader.GetGremlin());
            var statement = Mock.Of <IQuery>(x => x.Statement == "g.V().has('firstName','Thomas').values('lastName')");
            GremlinCommandOperation commandOperation = new GremlinCommandFactory().Instantiate(client, statement).Implementation as GremlinCommandOperation;

            var engine = new GremlinExecutionEngine((GremlinClientOperation)(client.CreateNew()), commandOperation);

            var count = engine.ExecuteScalar();

            Assert.That(count, Is.Null);
        }
        public void Execute_Integer_ScalarReturned()
        {
            var client       = new GremlinLikeClientFactory().Instantiate(ConnectionStringReader.GetGremlin());
            var statement    = Mock.Of <IQuery>(x => x.Statement == "g.V().count()");
            var gremlinQuery = new GremlinCommandFactory().Instantiate(client, statement).Implementation as GremlinCommandOperation;

            var engine = new GremlinExecutionEngine((GremlinClientOperation)(client.CreateNew()), gremlinQuery);

            var count = engine.ExecuteScalar();

            Assert.That(count, Is.EqualTo(4));
        }
        public void Execute_Edge_DataSetFilled()
        {
            var client       = new GremlinLikeClientFactory().Instantiate(ConnectionStringReader.GetGremlin());
            var statement    = Mock.Of <IQuery>(x => x.Statement == "g.E()");
            var gremlinQuery = new GremlinCommandFactory().Instantiate(client, statement).Implementation as GremlinCommandOperation;

            var engine = new GremlinExecutionEngine((GremlinClientOperation)(client.CreateNew()), gremlinQuery);

            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]);
                    }
                }
            }

            Assert.That(inVs, Has.Count.EqualTo(3));
            Assert.That(outVs, Has.Count.EqualTo(3));
            Assert.That(outVs.Distinct().Count(), Is.EqualTo(2));

            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_ListOfString_ListReturned()
        {
            var client       = new GremlinLikeClientFactory().Instantiate(ConnectionStringReader.GetGremlin());
            var statement    = Mock.Of <IQuery>(x => x.Statement == "g.V().values('lastName')");
            var gremlinQuery = new GremlinCommandFactory().Instantiate(client, statement).Implementation as GremlinCommandOperation;

            var engine = new GremlinExecutionEngine((GremlinClientOperation)(client.CreateNew()), gremlinQuery);

            var count = engine.ExecuteList <string>();

            Assert.That(count, Has.Member("Andersen"));
            Assert.That(count, Has.Member("Miller"));
            Assert.That(count, Has.Member("Wakefield"));
        }
        public void Execute_ProjectionOfObjects_DataSetFilled()
        {
            var client       = new GremlinLikeClientFactory().Instantiate(ConnectionStringReader.GetGremlin());
            var statement    = Mock.Of <IQuery>(x => x.Statement == "g.V().project('FirstName','KnowsCount').by('firstName').by(out().count())");
            var gremlinQuery = new GremlinCommandFactory().Instantiate(client, statement).Implementation as GremlinCommandOperation;

            var engine = new GremlinExecutionEngine((GremlinClientOperation)(client.CreateNew()), gremlinQuery);

            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));
            }
        }
Beispiel #17
0
        public void CanHandle_OleDbConnectionString_False()
        {
            var factory = new GremlinLikeClientFactory();

            Assert.That(factory.CanHandle("data source=SERVER;initial catalog=DB;IntegratedSecurity=true;Provider=OLEDB.1"), Is.False);
        }
Beispiel #18
0
        public void CanHandle_GremlinLikeConnectionString_True()
        {
            var factory = new GremlinLikeClientFactory();

            Assert.That(factory.CanHandle(GremlinLikeConnectionString), Is.True);
        }