Ejemplo n.º 1
0
        public void AdvancedRecordsetActivityWorker_ExecuteSql_ProcessComplexStatement_REPLACE()
        {
            const string sqlQuery = "REPLACE INTO person(name, age) VALUES('Robocop', 1000);";

            var advancedRecordsetActivity = CreateAdvancedRecordsetActivity();

            advancedRecordsetActivity.DeclareVariables.Add(new NameValue {
                Name = "", Value = ""
            });
            advancedRecordsetActivity.SqlQuery = sqlQuery;
            advancedRecordsetActivity.Outputs  = new List <IServiceOutputMapping>
            {
                new ServiceOutputMapping {
                    MappedFrom = "records_affected", RecordSetName = "person"
                }
            };

            const string tableName = "tableName";

            var dataTable = new DataTable("myTable")
            {
                TableName = "table"
            };

            dataTable.Rows.Add();

            var dataSet = new DataSet();

            dataSet.Tables.Add(dataTable);

            var started = false;

            var hashedRecSetsList = new List <(string hashCode, string recSet)>
            {
                ("person", "person")
            };

            var mockAdvancedRecordset = new Mock <IAdvancedRecordset>();

            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.HashedRecSets).Returns(hashedRecSetsList);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.LoadRecordsetAsTable(tableName));
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ExecuteQuery("SELECT * FROM person")).Returns(dataSet);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ApplyResultToEnvironment(It.IsAny <string>(), It.IsAny <ICollection <IServiceOutputMapping> >(), It.IsAny <List <DataRow> >(), It.IsAny <bool>(), It.IsAny <int>(), ref started));
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.UpdateSqlWithHashCodes(It.IsAny <TSQLUnknownStatement>())).Returns(sqlQuery);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ApplyScalarResultToEnvironment(It.IsAny <string>(), It.IsAny <int>()));

            using (var viewModel = new AdvancedRecordsetActivityWorker(advancedRecordsetActivity, mockAdvancedRecordset.Object))
            {
                viewModel.ExecuteSql(0, ref started);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.LoadRecordsetAsTable("person"), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.UpdateSqlWithHashCodes(It.IsAny <TSQLUnknownStatement>()), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ApplyResultToEnvironment(It.IsAny <string>(), It.IsAny <ICollection <IServiceOutputMapping> >(), It.IsAny <List <DataRow> >(), It.IsAny <bool>(), It.IsAny <int>(), ref started), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ExecuteQuery("SELECT * FROM person"), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ApplyScalarResultToEnvironment(It.IsAny <string>(), It.IsAny <int>()), Times.Once);
            }
        }
Ejemplo n.º 2
0
        public void AdvancedRecordsetActivityWorker_ExecuteSql_ProcessComplexStatement_CREATE()
        {
            const string sqlQuery = "CREATE TABLE IF NOT EXISTS Variables (Name TEXT PRIMARY KEY, Value BLOB)";

            var advancedRecordsetActivity = CreateAdvancedRecordsetActivity();

            advancedRecordsetActivity.DeclareVariables.Add(new NameValue {
                Name = "", Value = ""
            });
            advancedRecordsetActivity.SqlQuery = sqlQuery;
            advancedRecordsetActivity.Outputs  = new List <IServiceOutputMapping>
            {
                new ServiceOutputMapping {
                    MappedFrom = "records_affected", RecordSetName = "person"
                }
            };

            var dataTable = new DataTable("myTable")
            {
                TableName = "table"
            };

            dataTable.Rows.Add();

            var dataSet = new DataSet();

            dataSet.Tables.Add(dataTable);

            var started = false;

            var hashedRecSetsList = new List <(string hashCode, string recSet)>
            {
                ("person", "person")
            };

            var mockAdvancedRecordset = new Mock <IAdvancedRecordset>();

            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.HashedRecSets).Returns(hashedRecSetsList);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ReturnSql(It.IsAny <List <TSQLToken> >()));
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ApplyScalarResultToEnvironment(It.IsAny <string>(), It.IsAny <int>()));

            using (var viewModel = new AdvancedRecordsetActivityWorker(advancedRecordsetActivity, mockAdvancedRecordset.Object))
            {
                viewModel.ExecuteSql(0, ref started);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ReturnSql(It.IsAny <List <TSQLToken> >()), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ApplyScalarResultToEnvironment(It.IsAny <string>(), It.IsAny <int>()), Times.Once);
            }
        }
Ejemplo n.º 3
0
        public void AdvancedRecordsetActivityWorker_ExecuteSql_ProcessComplexStatement_UNION()
        {
            const string sqlQuery = "SELECT * from person UNION ALL SELECT * from person;";

            var advancedRecordsetActivity = CreateAdvancedRecordsetActivity();

            advancedRecordsetActivity.DeclareVariables.Add(new NameValue {
                Name = "", Value = ""
            });
            advancedRecordsetActivity.SqlQuery = sqlQuery;

            const string tableName = "tableName";

            var dataTable = new DataTable("myTable")
            {
                TableName = "table"
            };

            dataTable.Rows.Add();

            var dataSet = new DataSet();

            dataSet.Tables.Add(dataTable);

            var started = false;

            var hashedRecSetsList = new List <(string hashCode, string recSet)>();

            var mockAdvancedRecordset = new Mock <IAdvancedRecordset>();

            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.HashedRecSets).Returns(hashedRecSetsList);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.LoadRecordsetAsTable(tableName));
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ExecuteQuery(sqlQuery)).Returns(dataSet);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ApplyResultToEnvironment(It.IsAny <string>(), It.IsAny <ICollection <IServiceOutputMapping> >(), It.IsAny <List <DataRow> >(), It.IsAny <bool>(), It.IsAny <int>(), ref started));

            using (var viewModel = new AdvancedRecordsetActivityWorker(advancedRecordsetActivity, mockAdvancedRecordset.Object))
            {
                viewModel.ExecuteSql(0, ref started);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ExecuteQuery(sqlQuery), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ApplyResultToEnvironment(It.IsAny <string>(), It.IsAny <ICollection <IServiceOutputMapping> >(), It.IsAny <List <DataRow> >(), It.IsAny <bool>(), It.IsAny <int>(), ref started), Times.Once);
            }
        }
Ejemplo n.º 4
0
        public void AdvancedRecordsetActivityWorker_ExecuteSql_TSQLStatementType_Select()
        {
            var advancedRecordsetActivity = CreateAdvancedRecordsetActivity();

            advancedRecordsetActivity.DeclareVariables.Add(new NameValue {
                Name = "", Value = ""
            });
            advancedRecordsetActivity.SqlQuery = "Select * from person";

            const string tableName = "tableName";
            const string sqlQuery  = "sqlQuery";

            var dataTable = new DataTable("myTable")
            {
                TableName = "table"
            };

            dataTable.Rows.Add();

            var dataSet = new DataSet();

            dataSet.Tables.Add(dataTable);

            var started = false;

            var mockAdvancedRecordset = new Mock <IAdvancedRecordset>();

            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.LoadRecordsetAsTable(tableName));
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.UpdateSqlWithHashCodes(It.IsAny <TSQLSelectStatement>())).Returns(sqlQuery);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ExecuteQuery(sqlQuery)).Returns(dataSet);
            mockAdvancedRecordset.Setup(advancedRecordset => advancedRecordset.ApplyResultToEnvironment(It.IsAny <string>(), It.IsAny <ICollection <IServiceOutputMapping> >(), It.IsAny <List <DataRow> >(), It.IsAny <bool>(), It.IsAny <int>(), ref started));

            using (var viewModel = new AdvancedRecordsetActivityWorker(advancedRecordsetActivity, mockAdvancedRecordset.Object))
            {
                viewModel.ExecuteSql(0, ref started);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.UpdateSqlWithHashCodes(It.IsAny <TSQLSelectStatement>()), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ExecuteQuery(sqlQuery), Times.Once);
                mockAdvancedRecordset.Verify(advancedRecordset => advancedRecordset.ApplyResultToEnvironment(It.IsAny <string>(), It.IsAny <ICollection <IServiceOutputMapping> >(), It.IsAny <List <DataRow> >(), It.IsAny <bool>(), It.IsAny <int>(), ref started), Times.Once);
            }
        }