public void Execute_Batch_TablesAreCreated()
        {
            //Create table
            CleanTemporaryTable("TablexxxOne", ConnectionStringReader.GetLocalSqlClient());
            CleanTemporaryTable("TablexxxTwo", ConnectionStringReader.GetLocalSqlClient());

            //Build the fullpath for the file to read
            var fileName = FileOnDisk.CreatePhysicalFile(BATCH_FILE, $"{GetType().Namespace}.Resources.{BATCH_FILE}");

            //Apply the test
            var runner = new BatchRunnerSmo(fileName, ConnectionStringReader.GetLocalSqlClient());

            runner.Execute();

            var countTable = 0;

            using (var conn = new SqlConnection(ConnectionStringReader.GetLocalSqlClient()))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.CommandText = "select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'dbo' and TABLE_NAME like 'Tablexxx%'";
                    countTable      = (int)cmd.ExecuteScalar();
                }
            }
            Assert.That(countTable, Is.EqualTo(2));
        }
Esempio n. 2
0
        public void Execute_Batch_TablesAreCreated()
        {
            //Create table
            CleanTemporaryTable("TablexxxOne", ConnectionStringReader.GetLocalSqlClient());
            CleanTemporaryTable("TablexxxTwo", ConnectionStringReader.GetLocalSqlClient());

            //Build the fullpath for the file to read
            FileName = DiskOnFile.CreatePhysicalFile(BATCH_FILE, "NBi.Testing.Integration.Core.Batch." + BATCH_FILE);

            //Mock the commandXml
            var info = Mock.Of <IBatchRunCommand>
                       (
                c => c.FullPath == BATCH_FILE &&
                c.ConnectionString == ConnectionStringReader.GetLocalSqlClient() &&
                c.Version == "SqlServer2014"
                       );

            //Apply the test
            var runCommand = new BatchRunCommand(info, new SqlConnection(ConnectionStringReader.GetLocalSqlClient()));

            runCommand.Execute();

            var countTable = 0;

            using (var conn = new SqlConnection(ConnectionStringReader.GetLocalSqlClient()))
            {
                var cmd = new SqlCommand();
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = "select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'dbo' and TABLE_NAME like 'Tablexxx%'";
                countTable      = (int)cmd.ExecuteScalar();
            }
            Assert.That(countTable, Is.EqualTo(2));
        }
Esempio n. 3
0
        public void Execute_LoadTemporaryTableBasedOnCSV_TableHasMoreData()
        {
            //Create table
            CreateTemporaryTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            //Check how many elements are available in the table
            var before = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            //Mock the commandXml
            var info = Mock.Of <ILoadCommand>(
                command => command.ConnectionString == ConnectionStringReader.GetLocalSqlClient() &&
                command.TableName == "Temporary" &&
                command.FileName == FileName
                );

            //Apply the test
            var cmd = new BulkLoadCommand(info, new SqlConnection(ConnectionStringReader.GetLocalSqlClient()));

            cmd.Execute();

            //Execute Query on temporary table to knwo the new count of elements
            var after = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            Assert.That(after, Is.GreaterThan(before));
        }
Esempio n. 4
0
        public void CleanCache_Any_DoesNotThrow()
        {
            var query = "select 1;";
            var cmd   = new SqlCommand(query, new SqlConnection(ConnectionStringReader.GetLocalSqlClient()));

            var qp = new SqlPerformanceEngine(cmd.Connection, cmd);

            Assert.DoesNotThrow(() => qp.CleanCache());
        }
Esempio n. 5
0
        public void EnsureLocalSqlServerRunning()
        {
            var startTag    = @"(local)\";
            var start       = ConnectionStringReader.GetLocalSqlClient().IndexOf(startTag) + startTag.Length;
            var end         = ConnectionStringReader.GetLocalSqlClient().IndexOf(';', start);
            var serviceName = "MSSQL$" + ConnectionStringReader.GetLocalSqlClient().Substring(start, end - start);

            var service = new ServiceController(serviceName);

            if (service.Status != ServiceControllerStatus.Running)
            {
                Assert.Ignore("Local SQL Server not started.");
            }
        }
Esempio n. 6
0
        public void Execute_TruncateTemporaryTable_TableIsEmpty()
        {
            //Create table
            CreateTemporaryTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            //Mock the commandXml
            var resetArgs = Mock.Of <IResetCommandArgs>(
                args => args.ConnectionString == ConnectionStringReader.GetLocalSqlClient() &&
                args.TableName == new LiteralScalarResolver <string>("Temporary")
                );

            var factory = new DataEngineeringFactory();
            var command = factory.Instantiate(resetArgs);

            command.Execute();

            //Execute Query on temporary table to knwo the new count of elements
            var after = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            Assert.That(after, Is.EqualTo(0));
        }
Esempio n. 7
0
        public void Execute_TruncateTemporaryTable_TableIsEmpty()
        {
            //Create table
            CreateTemporaryTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            //Mock the commandXml
            var info = Mock.Of <IResetCommand>(
                command => command.ConnectionString == ConnectionStringReader.GetLocalSqlClient() &&
                command.TableName == "Temporary"
                );

            //Apply the test
            var cmd = new TruncateCommand(info);

            cmd.Execute();

            //Execute Query on temporary table to knwo the new count of elements
            var after = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            Assert.That(after, Is.EqualTo(0));
        }
Esempio n. 8
0
        public void Execute_LoadTemporaryTableBasedOnCSV_TableHasMoreData()
        {
            //Create table
            CreateTemporaryTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            //Check how many elements are available in the table
            var before = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            //Mock the commandXml
            var loadArgs = Mock.Of <ILoadCommandArgs>(
                args => args.ConnectionString == ConnectionStringReader.GetLocalSqlClient() &&
                args.TableName == new LiteralScalarResolver <string>("Temporary") &&
                args.FileName == new LiteralScalarResolver <string>(FileName)
                );

            var command = new BulkLoadCommand(loadArgs);

            command.Execute();

            //Execute Query on temporary table to knwo the new count of elements
            var after = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());

            Assert.That(after, Is.GreaterThan(before));
        }