Пример #1
0
        public void Execute_Edge_DataSetFilled()
        {
            SqlClient           session          = new SqlClientFactory().Instantiate(ConnectionStringReader.GetLocaleSql()) as SqlClient;
            var                 statement        = Mock.Of <IQuery>(x => x.Statement == "SELECT * FROM FoF f WHERE f.label='knows'");
            SqlCommandOperation commandOperation = new SqlCommandFactory().Instantiate(session, statement).Implementation as SqlCommandOperation;

            var engine = new SqlExecutionEngine(session.CreateClientOperation(), commandOperation);

            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(12));
            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("_sink"));
            Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("_vertexId"));
            Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("_sinkLabel"));
            Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("_vertexLabel"));

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                Assert.That(row["id"], Is.Not.Null.Or.Empty);
                Assert.That(row["_vertexLabel"], Is.EqualTo("person"));
                Assert.That(row["_sinkLabel"], Is.EqualTo("person"));
                Assert.That(row["_isEdge"], Is.True);
            }
        }
Пример #2
0
        public void Execute_NullString_ScalarReturned()
        {
            SqlClient           session       = new SqlClientFactory().Instantiate(ConnectionStringReader.GetLocaleSql()) as SqlClient;
            var                 statement     = Mock.Of <IQuery>(x => x.Statement == "SELECT VALUE p.lastName[0]._value FROM ROOT p WHERE p.label = 'person' and p.firstName[0]._value = 'Thomas'");
            SqlCommandOperation cosmosdbQuery = new SqlCommandFactory().Instantiate(session, statement).Implementation as SqlCommandOperation;

            var engine = new SqlExecutionEngine(session.CreateClientOperation(), cosmosdbQuery);

            var count = engine.ExecuteScalar();

            Assert.That(count, Is.Null);
        }
Пример #3
0
        public void Execute_Integer_ScalarReturned()
        {
            SqlClient           session       = new SqlClientFactory().Instantiate(ConnectionStringReader.GetLocaleSql()) as SqlClient;
            var                 statement     = Mock.Of <IQuery>(x => x.Statement == "SELECT VALUE count(1) FROM FoF f WHERE f.label='person'");
            SqlCommandOperation cosmosdbQuery = new SqlCommandFactory().Instantiate(session, statement).Implementation as SqlCommandOperation;

            var engine = new SqlExecutionEngine(session.CreateClientOperation(), cosmosdbQuery);

            var age = engine.ExecuteScalar();

            Assert.That(age, Is.EqualTo(4));
        }
Пример #4
0
        public void Execute_WaitFor3SecondsTimeoutSetTo0_NoTimeOut()
        {
            var query = "WAITFOR DELAY '00:00:03';";
            var cmd   = new SqlCommand(query, new SqlConnection(ConnectionStringReader.GetSqlClient()))
            {
                CommandTimeout = 0
            };

            var qe = new SqlExecutionEngine(cmd.Connection, cmd);

            Assert.DoesNotThrow(delegate { qe.Execute(); });
        }
Пример #5
0
        public void ExecuteScalar_ValidQuery_DataSetFilled()
        {
            var query = "select top(1) CurrencyCode from [Sales].[Currency] where Name like '%Canad%'";
            var cmd   = new SqlCommand(query, new SqlConnection(ConnectionStringReader.GetSqlClient()))
            {
                CommandTimeout = 0
            };

            var qe    = new SqlExecutionEngine(cmd.Connection, cmd);
            var value = qe.ExecuteScalar();

            Assert.That(value, Is.EqualTo("CAD"));
        }
Пример #6
0
        public void Execute_ListOfString_ListReturned()
        {
            SqlClient           session       = new SqlClientFactory().Instantiate(ConnectionStringReader.GetLocaleSql()) as SqlClient;
            var                 statement     = Mock.Of <IQuery>(x => x.Statement == "SELECT VALUE p.lastName[0]._value FROM ROOT p WHERE p.label = 'person'");
            SqlCommandOperation cosmosdbQuery = new SqlCommandFactory().Instantiate(session, statement).Implementation as SqlCommandOperation;

            var engine = new SqlExecutionEngine(session.CreateClientOperation(), cosmosdbQuery);

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

            Assert.That(count, Has.Member("Andersen"));
            Assert.That(count, Has.Member("Miller"));
            Assert.That(count, Has.Member("Wakefield"));
        }
Пример #7
0
        public void ExecuteList_ValidQuery_DataSetFilled()
        {
            var query = "select top(10) CurrencyCode from [Sales].[Currency] where CurrencyCode like '%D' order by 1 asc";
            var cmd   = new SqlCommand(query, new SqlConnection(ConnectionStringReader.GetSqlClient()))
            {
                CommandTimeout = 0
            };

            var qe     = new SqlExecutionEngine(cmd.Connection, cmd);
            var values = qe.ExecuteList <string>();

            Assert.That(values, Has.Count.EqualTo(10));
            Assert.That(values, Has.Member("CAD"));
        }
Пример #8
0
        public void Execute_ValidQuery_DataSetFilled()
        {
            var query = "select * from [Sales].[Currency];";
            var cmd   = new SqlCommand(query, new SqlConnection(ConnectionStringReader.GetSqlClient()))
            {
                CommandTimeout = 0
            };

            var qe = new SqlExecutionEngine(cmd.Connection, cmd);
            var ds = qe.Execute();

            Assert.That(ds.Tables, Has.Count.EqualTo(1));
            Assert.That(ds.Tables[0].Columns, Has.Count.EqualTo(3));
            Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(105));
        }
Пример #9
0
        public void Execute_ProjectionOfObjects_DataSetFilled()
        {
            SqlClient           session          = new SqlClientFactory().Instantiate(ConnectionStringReader.GetLocaleSql()) as SqlClient;
            var                 statement        = Mock.Of <IQuery>(x => x.Statement == "SELECT p.firstName[0]._value as FirstName, p.age[0]._value as Age FROM ROOT p WHERE p.label = 'person'");
            SqlCommandOperation commandOperation = new SqlCommandFactory().Instantiate(session, statement).Implementation as SqlCommandOperation;

            var engine = new SqlExecutionEngine(session.CreateClientOperation(), commandOperation);

            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("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, 39 })
            {
                Assert.That(ages, Has.Member(expectedAge));
            }
        }
Пример #10
0
        public void Execute_Vertex_DataSetFilled()
        {
            SqlClient           client           = new SqlClientFactory().Instantiate(ConnectionStringReader.GetLocaleSql()) as SqlClient;
            var                 statement        = Mock.Of <IQuery>(x => x.Statement == "SELECT * FROM FoF f WHERE f.label='person'");
            SqlCommandOperation commandOperation = new SqlCommandFactory().Instantiate(client, statement).Implementation as SqlCommandOperation;

            var engine = new SqlExecutionEngine(client.CreateClientOperation(), commandOperation);

            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("firstName"));
            Assert.That(ds.Tables[0].Columns.Cast <DataColumn>().Select(x => x.ColumnName), Has.Member("age"));
        }