public void CleanUpSchema()
        {
            //Arrange
            string schemaName = "s" + TestHashHelper.RandomString(9);

            SqlTask.ExecuteNonQuery(Connection, "Create schema",
                                    $"CREATE SCHEMA {schemaName}");
            SqlTask.ExecuteNonQuery(Connection, "Create table",
                                    $"CREATE TABLE {schemaName}.Table1 ( Nothing INT NULL )");
            SqlTask.ExecuteNonQuery(Connection, "Create view",
                                    $"CREATE VIEW {schemaName}.View1 AS SELECT * FROM {schemaName}.Table1");
            SqlTask.ExecuteNonQuery(Connection, "Create procedure",
                                    $"CREATE PROCEDURE {schemaName}.Proc1 AS SELECT * FROM {schemaName}.Table1");
            var objCountSql = new SqlTask("Count object",
                                          $@"SELECT COUNT(*) FROM sys.objects obj 
 INNER JOIN sys.schemas sch  ON sch.schema_id = obj.schema_id
WHERE sch.name = '{schemaName}'")
            {
                ConnectionManager = Connection
            };

            Assert.Equal(3, objCountSql.ExecuteScalar <int>());

            //Act
            CleanUpSchemaTask.CleanUp(Connection, schemaName);

            //Assert
            Assert.Equal(0, objCountSql.ExecuteScalar <int>());
        }
Example #2
0
        public void CreateWithCollation(IConnectionManager connection)
        {
            //Arrange
            string dbName    = "ETLBox_" + TestHashHelper.RandomString(10);
            string collation = "Latin1_General_CS_AS";

            if (connection.GetType() == typeof(PostgresConnectionManager))
            {
                collation = "en_US.utf8";
            }
            if (connection.GetType() == typeof(MySqlConnectionManager))
            {
                collation = "latin1_swedish_ci";
            }
            //Act
            CreateDatabaseTask.Create(connection, dbName, collation);

            //Assert
            var dbList = GetDatabaseListTask.List(connection);

            Assert.Contains <string>(dbName, dbList);

            //Cleanup
            DropDatabaseTask.Drop(connection, dbName);
        }
 public void CreateSchema(IConnectionManager connection)
 {
     if (connection.GetType() != typeof(MySqlConnectionManager))
     {
         //Arrange
         string schemaName = "s" + TestHashHelper.RandomString(9);
         //Act
         CreateSchemaTask.Create(connection, schemaName);
         //Assert
         Assert.True(IfSchemaExistsTask.IsExisting(connection, schemaName));
     }
 }
        private static List <MyMergeRow> CreateTestData(int rowsInSource)
        {
            List <MyMergeRow> knownGuids = new List <MyMergeRow>();

            for (int i = 0; i < rowsInSource; i++)
            {
                knownGuids.Add(new MyMergeRow()
                {
                    Id          = Guid.NewGuid(),
                    LastUpdated = DateTime.Now,
                    Value       = TestHashHelper.RandomString(1)
                });
            }
            return(knownGuids);
        }
Example #5
0
        IEnumerable <CSVData> GenerateWithYield(int numberOfRows)
        {
            var i = 0;

            while (i < numberOfRows)
            {
                i++;
                yield return(new CSVData()
                {
                    Col1 = TestHashHelper.RandomString(255),
                    Col2 = TestHashHelper.RandomString(255),
                    Col3 = TestHashHelper.RandomString(255),
                    Col4 = TestHashHelper.RandomString(255)
                });
            }
        }
        private MemorySource <MyMergeRow> AddNewTestData(int rowsInDest, List <MyMergeRow> knownGuids)
        {
            MemorySource <MyMergeRow> source = new MemorySource <MyMergeRow>();

            source.DataAsList = knownGuids;
            for (int i = 0; i < rowsInDest; i++)
            {
                knownGuids.Add(new MyMergeRow()
                {
                    Id          = Guid.NewGuid(),
                    LastUpdated = DateTime.Now,
                    Value       = TestHashHelper.RandomString(1)
                });
            }
            return(source);
        }
        public void IfDatabaseExists(IConnectionManager connection)
        {
            //Arrange
            string dbName       = ("ETLBox_" + TestHashHelper.RandomString(10)).ToLower();
            var    existsBefore = IfDatabaseExistsTask.IsExisting(connection, dbName);

            //Act
            SqlTask.ExecuteNonQuery(connection, "Create DB", $"CREATE DATABASE {dbName}");
            var existsAfter = IfDatabaseExistsTask.IsExisting(connection, dbName);

            //Assert
            Assert.False(existsBefore);
            Assert.True(existsAfter);

            //Cleanup
            DropDatabaseTask.Drop(connection, dbName);
        }
Example #8
0
        public void Drop(IConnectionManager connection)
        {
            //Arrange
            string dbName = "ETLBox_" + TestHashHelper.RandomString(10);

            CreateDatabaseTask.Create(connection, dbName);
            bool existsBefore = IfDatabaseExistsTask.IsExisting(connection, dbName);

            //Act
            DropDatabaseTask.Drop(connection, dbName);

            //Assert
            bool existsAfter = IfDatabaseExistsTask.IsExisting(connection, dbName);

            Assert.True(existsBefore);
            Assert.False(existsAfter);
        }
Example #9
0
        public void CreateSimple(IConnectionManager connection)
        {
            //Arrange
            string dbName       = "ETLBox_" + TestHashHelper.RandomString(10);
            var    dbListBefore = GetDatabaseListTask.List(connection);

            Assert.DoesNotContain <string>(dbName, dbListBefore);

            //Act
            CreateDatabaseTask.Create(connection, dbName);

            //Assert
            var dbListAfter = GetDatabaseListTask.List(connection);

            Assert.Contains <string>(dbName, dbListAfter);

            //Cleanup
            DropDatabaseTask.Drop(connection, dbName);
        }
        public void WriteAsyncAndCheckLock(string filename, int noRecords)
        {
            //Arrange
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            MemorySource <string[]> source = new MemorySource <string[]>();

            for (int i = 0; i < noRecords; i++)
            {
                source.DataAsList.Add(new string[] { TestHashHelper.RandomString(100) });
            }
            CsvDestination <string[]> dest = new CsvDestination <string[]>(filename);
            bool onCompletionRun           = false;

            //Act
            source.LinkTo(dest);
            Task sT = source.ExecuteAsync();
            Task dt = dest.Completion;

            while (!File.Exists(filename))
            {
                Task.Delay(10).Wait();
            }

            //Assert
            dest.OnCompletion = () =>
            {
                Assert.False(IsFileLocked(filename), "StreamWriter should be disposed and file unlocked");
                onCompletionRun = true;
            };

            Assert.True(IsFileLocked(filename), "Right after  start the file should still be locked.");
            dt.Wait();
            Assert.True(onCompletionRun, "OnCompletion action and assertion did run");
        }