public void ShouldCallExecuteCreateDatabaseWhenBeforeExecuteScriptsActionIsCreateDatabase() { // arrange DatabaseReleaseTool databaseReleaseToolMock = MockRepository.GeneratePartialMock <DatabaseReleaseTool>( Environment.CurrentDirectory, new CreateDatabasePolicyComposite(), new FileStructurePolicyComposite(), new ConsoleOutputLogger(), new ConnectionStringFactory(), null); DatabaseConnectionParameters databaseConnectionParameters = new DatabaseConnectionParameters { BeforeExecuteScriptsAction = BeforeExecuteScriptsAction .CreateDatabase }; databaseReleaseToolMock.Expect(x => x.ExecuteCreateDatabase(databaseConnectionParameters, Encoding.ASCII)) .Repeat.Once() .Return(new ExcecutionResult()); // act databaseReleaseToolMock.Execute(string.Empty, string.Empty, databaseConnectionParameters, Encoding.ASCII); // assert databaseReleaseToolMock.VerifyAllExpectations(); }
ShouldCallExecuteCreateDatabaseAndExecuteAllScriptsForDatabaseWhenBeforeExecuteScriptsActionIsCreateDatabaseAndANdResultOfExecuteCreateDatabaseIsSucces() { // arrange DatabaseReleaseTool databaseReleaseToolMock = MockRepository.GeneratePartialMock <DatabaseReleaseTool>( Environment.CurrentDirectory, new CreateDatabasePolicyComposite(), new FileStructurePolicyComposite(), new ConsoleOutputLogger(), new ConnectionStringFactory(), null); DatabaseConnectionParameters databaseConnectionParameters = new DatabaseConnectionParameters { BeforeExecuteScriptsAction = BeforeExecuteScriptsAction .CreateDatabase }; databaseReleaseToolMock.Expect(x => x.ExecuteCreateDatabase(databaseConnectionParameters, Encoding.UTF7)) .Repeat.Once() .Return(new ExcecutionResult { Success = true }); databaseReleaseToolMock.Expect( x => x.ExecuteAllScriptsForDatabase("1.0.0", "2.0.0", databaseConnectionParameters, Encoding.UTF7)) .Repeat.Once() .Return(new ExcecutionResult()); // act databaseReleaseToolMock.Execute("1.0.0", "2.0.0", databaseConnectionParameters, Encoding.UTF7); // assert databaseReleaseToolMock.VerifyAllExpectations(); }
public void ExecuteAllScriptsForDatabaseToVersionInvalidVersion() { ExcecutionResult result = new DatabaseReleaseTool( Path.GetTempPath(), null, null, new ConsoleOutputLogger(), _connectionStringFactory, CreateMockDatabaseConnectionFactory()).ExecuteAllScriptsForDatabase("1.0", "invalidversion", null, null); Assert.IsFalse(result.Success); }
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 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); }
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); }