예제 #1
0
        public void SqlServer_CreateCommand_TranactionStarted_CommandTransactionIsNotNull()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            var sqlServer = new SqlServer();

            try
            {
                sqlServer.Connect(dbSource.ConnectionString);
                sqlServer.BeginTransaction();

                //------------Execute Test---------------------------
                var command = sqlServer.CreateCommand();

                //------------Assert Results-------------------------
                Assert.IsNotNull(command);
                Assert.IsNotNull(command.Transaction);
            }
            finally
            {
                sqlServer.RollbackTransaction();
                sqlServer.Dispose();
            }
        }
예제 #2
0
        public void SqlServer_Connect_UserIDInDomainFormat_ConnectionStringIsNotIntegratedSecurityEqualsSSPI()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            dbSource.UserID = "Dev2\\TestUser";

            var sqlServer = new SqlServer();

            try
            {
                //------------Execute Test---------------------------
                try
                {
                    // expect this call to throw a 'login failed' exception
                    sqlServer.Connect(dbSource.ConnectionString);
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                {
                }

                //------------Assert Results-------------------------
                Assert.IsFalse(sqlServer.ConnectionString.Contains("Integrated Security=SSPI"));
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
예제 #3
0
        public void SqlServer_FetchDataSet_CorrectDataReturned()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            var sqlServer = new SqlServer();

            try
            {
                sqlServer.Connect(dbSource.ConnectionString, CommandType.StoredProcedure, "Pr_CitiesGetCountries");

                //------------Execute Test---------------------------
                var actualDataSet = sqlServer.FetchDataSet(new SqlParameter("@Prefix", "a"));

                //------------Assert Results-------------------------
                Assert.AreEqual(1, actualDataSet.Tables.Count);

                var actual = actualDataSet.Tables[0];

                SqlServerTestUtils.Verify_DataTable_CountriesPrefixIsA(actual);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
예제 #4
0
        public void SqlServer_FetchDatabases_SortedListOfNames()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            var expected = new List <string>();

            using (var connection = new SqlConnection(dbSource.ConnectionString))
            {
                connection.Open();
                var databases = connection.GetSchema("Databases");
                connection.Close();

                var names = databases.Rows.Cast <DataRow>().Select(row => (row["database_name"] ?? string.Empty).ToString()).Distinct().OrderBy(s => s);
                expected.AddRange(names);
            }

            var sqlServer = new SqlServer();

            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                //------------Execute Test---------------------------
                var actual = sqlServer.FetchDatabases();

                //------------Assert Results-------------------------
                CollectionAssert.AreEqual(expected, actual);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
예제 #5
0
        public void SetupScenerio()
        {
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource, "");
            scenarioContext.Add("dbSource", dbSource);

            var sqlBulkInsert = new DsfSqlBulkInsertActivity();

            sqlBulkInsert.Database  = dbSource;
            sqlBulkInsert.TableName = "SqlBulkInsertSpecFlowTestTable_for_" + scenarioContext.ScenarioInfo.Title.Replace(' ', '_');
            if (scenarioContext.ScenarioInfo.Title.Replace(' ', '_') == "Import_data_into_Table_Batch_size_is_1")
            {
                var tableNameUniqueNameGuid = CommonSteps.GetGuid();
                CreateIsolatedSQLTable(tableNameUniqueNameGuid);
                scenarioContext.Add("tableNameUniqueNameGuid", tableNameUniqueNameGuid);
                sqlBulkInsert.TableName += "_" + tableNameUniqueNameGuid;
            }
            var dataColumnMappings = new List <DataColumnMapping>
            {
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col1]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col1",
                        DataType   = typeof(Int32),
                        MaxLength  = 100
                    },
                },
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col2]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col2",
                        DataType   = typeof(String),
                        MaxLength  = 100
                    }
                },
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col3]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col3",
                        DataType   = typeof(Guid),
                        MaxLength  = 100
                    }
                }
            };

            sqlBulkInsert.InputMappings = dataColumnMappings;
            TestStartNode = new FlowStep
            {
                Action = sqlBulkInsert
            };

            scenarioContext.Add("activity", sqlBulkInsert);
        }
예제 #6
0
        public void SqlServer_FetchStoredProcedures_CorrectDataReturned()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            IDbCommand procedureCommand = null;
            List <IDbDataParameter> procedureCommandParameters = null;
            string procedureHelpText = null;

            IDbCommand functionCommand = null;
            List <IDbDataParameter> functionCommandParameters = null;
            string functionHelpText = null;

            var sqlServer = new SqlServer();

            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> procedureProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "dbo.Pr_CitiesGetCountries")
                    {
                        procedureCommand           = dbCommand;
                        procedureCommandParameters = list;
                        procedureHelpText          = helpText;
                    }
                    return(true);
                };
                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> functionProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "dbo.fn_Greeting")
                    {
                        functionCommand           = dbCommand;
                        functionCommandParameters = list;
                        functionHelpText          = helpText;
                    }
                    return(true);
                };

                //------------Execute Test---------------------------
                sqlServer.FetchStoredProcedures(procedureProcessor, functionProcessor, true);
            }
            finally
            {
                sqlServer.Dispose();
            }

            //------------Assert Results-------------------------
            SqlServerTestUtils.Verify_FetchStoredProcedures_Pr_CitiesGetCountries(procedureCommand, procedureCommandParameters, procedureHelpText);
            SqlServerTestUtils.Verify_FetchStoredProcedures_Fn_Greeting(functionCommand, functionCommandParameters, functionHelpText);
        }
예제 #7
0
        public void SetupScenerio()
        {
            var sqlBulkInsert = new DsfSqlBulkInsertActivity();
            var dbSource      = SqlServerTestUtils.CreateDev2TestingDbSource();

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource);
            ScenarioContext.Current.Add("dbSource", dbSource);
            sqlBulkInsert.Database  = dbSource;
            sqlBulkInsert.TableName = "SqlBulkInsertSpecFlowTestTable_for_" + ScenarioContext.Current.ScenarioInfo.Title.Replace(' ', '_');
            var dataColumnMappings = new List <DataColumnMapping>
            {
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col1]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col1",
                        DataType   = typeof(Int32),
                        MaxLength  = 100
                    },
                },
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col2]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col2",
                        DataType   = typeof(String),
                        MaxLength  = 100
                    }
                },
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col3]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col3",
                        DataType   = typeof(Guid),
                        MaxLength  = 100
                    }
                }
            };

            sqlBulkInsert.InputMappings = dataColumnMappings;
            TestStartNode = new FlowStep
            {
                Action = sqlBulkInsert
            };

            ScenarioContext.Current.Add("activity", sqlBulkInsert);
        }
예제 #8
0
        public void SqlServer_Connect_ValidLogin_IsConnectedIsTrue()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            var sqlServer = new SqlServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect(dbSource.ConnectionString);

                //------------Assert Results-------------------------
                Assert.IsTrue(sqlServer.IsConnected);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
예제 #9
0
        public void SqlServer_Connect_InvalidLogin_ThrowsSqlException()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            dbSource.Password = Guid.NewGuid().ToString(); // Random invalid password

            var sqlServer = new SqlServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect(dbSource.ConnectionString);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
예제 #10
0
        public void SqlServer_FetchTableValuedFunctions_AssertSelectTextIsDifferent()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            List <IDbDataParameter> procedureCommandParameters = null;
            string procedureHelpText = null;
            string select            = "";
            var    sqlServer         = new SqlServer();

            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> functionProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "dbo.bob")
                    {
                        procedureCommandParameters = list;
                        procedureHelpText          = helpText;
                        select = bob;
                    }
                    return(true);
                };
                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> procedureProcessor = (dbCommand, list, helpText, bob) => true;

                //------------Execute Test---------------------------
                sqlServer.FetchStoredProcedures(procedureProcessor, functionProcessor, true);
            }
            finally
            {
                sqlServer.Dispose();
            }

            //------------Assert Results-------------------------
            Assert.AreEqual("@country", procedureCommandParameters.First().ParameterName);
            Assert.IsTrue(procedureHelpText.Contains(@"insert into @Countries
	select CountryID from dbo.Country"    ));
            Assert.AreEqual("select * from dbo.bob(@country)", select);
        }
예제 #11
0
        public void SqlServer_FetchStoredProcedures_WithClrTypeStoredProcedure_CorrectDataReturned()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            List <IDbDataParameter> procedureCommandParameters = null;
            string procedureHelpText = null;

            var sqlServer = new SqlServer();

            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> procedureProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "Warewolf.RunWorkflowForSql")
                    {
                        procedureCommandParameters = list;
                        procedureHelpText          = helpText;
                    }
                    return(true);
                };
                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> functionProcessor = (dbCommand, list, helpText, bob) => true;

                //------------Execute Test---------------------------
                sqlServer.FetchStoredProcedures(procedureProcessor, functionProcessor, true);
            }
            finally
            {
                sqlServer.Dispose();
            }

            //------------Assert Results-------------------------
            SqlServerTestUtils.Verify_FetchStoredProcedures_WarewolfRunForSql(procedureCommandParameters, procedureHelpText);
        }