public void AllFilesMustAdhereToPrefixPolicy()
        {
            string databaseScriptsPathName = "AllFilesMustAdhereToPrefixPolicyTest";

            // Setup
            DirectoryInfo databaseScriptsRoot = DirectoryStructureHelper.CreateValidDatabaseDirStructure(databaseScriptsPathName);

            FilenamePrefixPolicy policy = new FilenamePrefixPolicy();

            string validFilename   = "1.0.0.0_0001_CreateTables.sql";
            string invalidFilename = "CreateTables.sql";

            string validFilenameFullname   = databaseScriptsRoot.GetDirectories()[2].FullName + "\\" + validFilename;
            string invalidFilenameFullname = databaseScriptsRoot.GetDirectories()[2].FullName + "\\" + invalidFilename;

            // Create valid filename
            DirectoryStructureHelper.CreateEmptyFile(validFilenameFullname);

            PolicyResult result = policy.Check(databaseScriptsRoot);

            Assert.IsTrue(result.Success);
            Assert.IsEmpty(result.Messages);

            // Create invalid filename
            DirectoryStructureHelper.CreateEmptyFile(invalidFilenameFullname);

            result = policy.Check(databaseScriptsRoot);

            Assert.IsFalse(result.Success);
            Assert.That(result.Messages.Count, Is.EqualTo(1));
        }
        public void DirectoryStructurePolicyCheckMustSucceedWithValidStructure()
        {
            // Setup
            DirectoryInfo databaseScriptsRoot =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("DirectoryStructureMustBeCorrectTest");

            DirectoryStructurePolicy directoryStructurePolicy = new DirectoryStructurePolicy();
            PolicyResult             result = directoryStructurePolicy.Check(databaseScriptsRoot);

            Assert.IsTrue(result.Success, string.Join(Environment.NewLine, result.Messages.ToArray()));
            Assert.IsEmpty(result.Messages);
        }
        public void ShouldSucceedWhenNoCreateDatabaseScriptExists()
        {
            // Setup
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("ShouldSucceedWhenNoCreateDatabaseScriptExists");
            IFileStructurePolicy policy = new MustContainCreateDatabaseSqlFilePolicy();

            PolicyResult result = policy.Check(directoryInfo);

            // Assert
            Assert.That(result.Success, Is.True);
        }
        public void AtLeastOneDirectoryMustContainSqlFilesFailsOnEmptyDirs()
        {
            // Setup
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("AtLeastOneDirectoryMustContainSqlFilesTest");
            IFileStructurePolicy policy = new MustContainSqlFilePolicy();

            PolicyResult result = policy.Check(directoryInfo);

            // Empty directory. Policy should fail.
            Assert.IsFalse(result.Success);
            Assert.That(result.Messages.Count, Is.EqualTo(1));
        }
Exemplo n.º 5
0
        public void ShouldUseDbConnectionToMasterWhenBeforeExecuteScriptsActionIsCreateDatabase()
        {
            // Arrange
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure(
                    "ShouldUseDbConnectionToMasterWhenBeforeExecuteScriptsActionIsCreateDatabase");

            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[1].FullName, "CreateDatabase.sql"));

            IDatabaseConnectionFactory databaseConnectionFactory = MockRepository.GenerateMock <IDatabaseConnectionFactory>();
            IDbConnection  connection  = MockRepository.GenerateStub <IDbConnection>();
            IDbTransaction transaction = MockRepository.GenerateStub <IDbTransaction>();
            IDbCommand     command     = MockRepository.GenerateStub <IDbCommand>();

            databaseConnectionFactory.Expect(
                c => c.CreateDatabaseConnection("Data Source=.;Initial Catalog=master;User ID=testUser;Password=testPassword", DatabaseType.MsSql))
            .Repeat.Once()
            .Return(connection);
            connection.Expect(method => method.BeginTransaction()).Return(transaction);
            connection.Expect(method => method.CreateCommand()).Return(command);

            DatabaseReleaseTool dbreleaseTool = new DatabaseReleaseTool(
                directoryInfo.FullName,
                new CreateDatabasePolicyComposite(),
                null,
                new ConsoleOutputLogger(),
                new ConnectionStringFactory(),
                databaseConnectionFactory);

            DatabaseConnectionParameters parameters = new DatabaseConnectionParameters
            {
                BeforeExecuteScriptsAction =
                    BeforeExecuteScriptsAction.CreateDatabase,
                DatabaseType = DatabaseType.MsSql,
                CreationType =
                    ConnectionStringCreationType.FromArguments,
                Arguments =
                {
                    Hostname = ".",
                    Username = "******",
                    Password = "******",
                    Database = "FruitDB"
                }
            };

            // Act
            dbreleaseTool.ExecuteCreateDatabase(parameters, Encoding.Default);

            // Assert
            databaseConnectionFactory.VerifyAllExpectations();
        }
        public void ShouldSucceedWhenOnlyOneCreateDatabaseScriptExists()
        {
            // Setup
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("ShouldSucceedWhenOnlyOneCreateDatabaseScriptExists");
            IFileStructurePolicy policy = new MustContainCreateDatabaseSqlFilePolicy();

            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[1].FullName, "CreateDatabase.sql"));

            PolicyResult result = policy.Check(directoryInfo);

            // Assert
            Assert.That(result.Success, Is.True);
        }
        public void AtLeastOneDirectoryMustContainSqlFiles()
        {
            // Setup
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("AtLeastOneDirectoryMustContainSqlFilesTest");
            IFileStructurePolicy policy = new MustContainSqlFilePolicy();

            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[1].FullName, "1.0_TestScript.sql"));

            PolicyResult result = policy.Check(directoryInfo);

            // Empty directory. Policy should fail.
            Assert.IsTrue(result.Success);
            Assert.IsEmpty(result.Messages);
        }
        public void ShouldFailWhenMoreThanOneCreateDatabaseScriptExists()
        {
            // Setup
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("ShouldFailWhenMoreThanOneCreateDatabaseScriptExists");
            IFileStructurePolicy policy = new MustContainCreateDatabaseSqlFilePolicy();

            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[1].FullName, "CreateDatabase.sql"));
            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[2].FullName, "CreateDatabase.sql"));

            PolicyResult result = policy.Check(directoryInfo);

            // Assert
            Assert.That(result.Success, Is.False);
            Assert.That(result.Messages, Has.Count.EqualTo(1));
        }
Exemplo n.º 9
0
        public void SmokeTest()
        {
            // Setup
            DirectoryInfo directoryInfo = DirectoryStructureHelper.CreateValidDatabaseDirStructure("SmokeTest");

            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[1].FullName, "CreateDatabase.sql"));

            IDatabaseConnectionFactory databaseConnectionFactory = MockRepository.GenerateMock <IDatabaseConnectionFactory>();
            IDbConnection  connection  = MockRepository.GenerateStub <IDbConnection>();
            IDbTransaction transaction = MockRepository.GenerateStub <IDbTransaction>();
            IDbCommand     command     = MockRepository.GenerateStub <IDbCommand>();

            databaseConnectionFactory.Expect(
                c => c.CreateDatabaseConnection("Data Source=.;Initial Catalog=master;User ID=testUser;Password=testPassword", DatabaseType.MsSql))
            .Repeat.Once()
            .Return(connection);
            connection.Expect(method => method.BeginTransaction()).Return(transaction);
            connection.Expect(method => method.CreateCommand()).Return(command);

            DatabaseReleaseTool dbreleaseTool = new DatabaseReleaseTool(
                directoryInfo.FullName,
                new CreateDatabasePolicyComposite(),
                null,
                new ConsoleOutputLogger(),
                new ConnectionStringFactory(),
                databaseConnectionFactory);

            DatabaseConnectionParameters parameters = new DatabaseConnectionParameters();

            parameters.BeforeExecuteScriptsAction = BeforeExecuteScriptsAction.CreateDatabase;
            parameters.DatabaseType       = DatabaseType.MsSql;
            parameters.CreationType       = ConnectionStringCreationType.FromArguments;
            parameters.Arguments.Hostname = ".";
            parameters.Arguments.Username = "******";
            parameters.Arguments.Password = "******";
            parameters.Arguments.Database = "testdb";

            // Act
            ExcecutionResult result = dbreleaseTool.ExecuteCreateDatabase(parameters, Encoding.Default);

            // Assert
            Assert.That(result.Success, Is.True, "error: {0} ", result.Errors);
        }
Exemplo n.º 10
0
        public void SqlReaderShouldReturnAllFilesWhenNullVersionsArePassed()
        {
            // Arrange
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("SqlReaderShouldReturnAllFilesWhenNullVersionsArePassed");

            DirectoryInfo[] subdirs = directoryInfo.GetDirectories();
            DirectoryStructureHelper.CreateEmptyFile(subdirs[0], "1.3.0.0_DataSetup.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[1], "1.1.0.0_CreateDatabase.SQL");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[2], "1.2.0_CreateTables.sql");

            SqlFilesListReader reader = new SqlFilesListReader(directoryInfo);

            // Act
            Dictionary <string, FileInfo> sqlFilesToExecuteInProperOrder = reader.GetSpecificVersionedFilesToExecute(null, null as Version);

            // Assert
            Assert.AreEqual(3, sqlFilesToExecuteInProperOrder.Count);
        }
        public void ShouldSucceedWhenOnlyIgnoredDirectoriesHasCreateDatabaseScript()
        {
            // Arrange
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("ShouldFailWhenOnlyIgnoredDirectoriesHasCreateDatabaseScript");
            IFileStructurePolicy policy = new MustContainCreateDatabaseSqlFilePolicy();

            // Create sql files ONLY in the ignoredirlist
            foreach (string ignoreDir in Resources.DirectoryIgnoreListStructureTemplateList())
            {
                string fullPath = Path.Combine(directoryInfo.FullName, ignoreDir);
                DirectoryStructureHelper.CreateEmptyFile(Path.Combine(fullPath, "CreateDatabase.sql"));
            }

            // Act
            PolicyResult result = policy.Check(directoryInfo);

            // Assert
            Assert.That(result.Success, Is.True);
        }
        public void ExecuteAllScriptsForDatabaseSmokeTest()
        {
            // Setup
            string        pathName      = "ExecuteAllScriptsForDatabaseSmokeTest";
            DirectoryInfo directoryInfo = DirectoryStructureHelper.CreateValidDatabaseDirStructure(pathName);

            DirectoryStructureHelper.CreateEmptyFile(Path.Combine(directoryInfo.GetDirectories()[1].FullName, "1.0_TestScript.sql"));

            IFileStructurePolicy fileStucturePolicyComposite = new FileStructurePolicyComposite();

            IDatabaseConnectionFactory connectionFactory = CreateMockDatabaseConnectionFactory();

            IOutputLogger       outputLogger  = new ConsoleOutputLogger();
            DatabaseReleaseTool dbreleaseTool = new DatabaseReleaseTool(
                directoryInfo.FullName,
                null,
                fileStucturePolicyComposite,
                outputLogger,
                _connectionStringFactory,
                connectionFactory);

            string fromVersion = "1.0.0.0";
            string toVersion   = "2.0";

            DatabaseConnectionParameters parameters = new DatabaseConnectionParameters {
                DatabaseType = DatabaseType.MsSql
            };

            parameters.CreationType       = ConnectionStringCreationType.FromArguments;
            parameters.Arguments.Hostname = ".";
            parameters.Arguments.Username = "******";
            parameters.Arguments.Password = "******";
            parameters.Arguments.Database = "testdatabase";

            // Act
            ExcecutionResult result = dbreleaseTool.ExecuteAllScriptsForDatabase(fromVersion, toVersion, parameters, null);

            Assert.IsTrue(result.Success, string.Join("|", result.Errors.ToArray()));
            Assert.IsEmpty(result.Errors);
        }
        public void AtLeastOneDirectoryMustContainSqlFilesFailsWhenOnlyIgnoredDirectoriesHaveSqlFiles()
        {
            // Arrange
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("MustContainSqlFilesFailsWhenOnlyIgnoredDirectoriesHaveSqlFiles");
            IFileStructurePolicy policy = new MustContainSqlFilePolicy();

            // Create sql files ONLY in the ignoredirlist
            foreach (string ignoreDir in Resources.DirectoryIgnoreListStructureTemplateList())
            {
                string fullPath = Path.Combine(directoryInfo.FullName, ignoreDir);
                DirectoryStructureHelper.CreateEmptyFile(Path.Combine(fullPath, "1.0.0_IgnoreMe.sql"));
            }

            // Act
            PolicyResult result = policy.Check(directoryInfo);

            // Assert
            // Empty directory. Policy should fail.
            Assert.IsFalse(result.Success);
            Assert.That(result.Messages.Count, Is.EqualTo(1));
        }
Exemplo n.º 14
0
        public void SqlReaderShouldOrderSqlFilesInCorrectSequenceTest()
        {
            // Arrange
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("SqlReaderShouldOrderSqlFilesInCorrectSequenceTest");

            DirectoryInfo[] subdirs = directoryInfo.GetDirectories();
            DirectoryStructureHelper.CreateEmptyFile(subdirs[0], "1.1.0.0_DataSetup.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[0], "1.2.0_DataSetup.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[1], "1.7.0_StoredProc.sql");

            SqlFilesListReader reader = new SqlFilesListReader(directoryInfo);

            string fromVersion = "1.0";
            string toVersion   = "1.7";

            // Act
            Dictionary <string, FileInfo> sqlFilesToExecuteInProperOrder = reader.GetSpecificVersionedFilesToExecute(fromVersion, toVersion);

            // Assert
            Assert.AreEqual("1.1.0.0_DataSetup.sql", Path.GetFileName(sqlFilesToExecuteInProperOrder.ElementAt(0).Key));
            Assert.AreEqual("1.2.0_DataSetup.sql", Path.GetFileName(sqlFilesToExecuteInProperOrder.ElementAt(1).Key));
            Assert.AreEqual("1.7.0_StoredProc.sql", Path.GetFileName(sqlFilesToExecuteInProperOrder.ElementAt(2).Key));
        }
Exemplo n.º 15
0
        public void SqlReaderShouldFilterFilesBasedOnPassenFromAndToVersion()
        {
            // Arrange
            DirectoryInfo directoryInfo =
                DirectoryStructureHelper.CreateValidDatabaseDirStructure("SqlReaderShouldFilterFilesBasedOnPassenFromAndToVersion");

            DirectoryInfo[] subdirs = directoryInfo.GetDirectories();
            DirectoryStructureHelper.CreateEmptyFile(subdirs[0], "1.1.0.0_DataSetup.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[0], "1.11.0.0_DataSetup.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[0], "1.2.0_DataSetup.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[1], "1.8.0.0_StoredProc.sql");
            DirectoryStructureHelper.CreateEmptyFile(subdirs[1], "1.7.0_StoredProc.sql");

            SqlFilesListReader reader = new SqlFilesListReader(directoryInfo);

            string fromVersion = "1.0";
            string toVersion   = "1.7";

            // Act
            Dictionary <string, FileInfo> sqlFilesToExecuteInProperOrder = reader.GetSpecificVersionedFilesToExecute(fromVersion, toVersion);

            // Assert
            Assert.AreEqual(3, sqlFilesToExecuteInProperOrder.Count);
        }