protected override void Arrange() { _options = new DeployDatabase { Engine = EngineType.PostgreSql, DatabaseType = DatabaseType.ODS, ConnectionString = "Valid Connection String" }; _databaseCommand = Stub <IDatabaseCommand>(); A.CallTo(() => _databaseCommand.Execute(A <IOptions> ._)) .Throws(new Exception()); _databaseCommandFactory = Stub <IDatabaseCommandFactory>(); A.CallTo(() => _databaseCommandFactory.CreateDatabaseCommands(A <EngineType> ._)) .Returns(new List <IDatabaseCommand> { _databaseCommand }); _compositeSpecification = Stub <ICompositeSpecification>(); A.CallTo(() => _compositeSpecification.IsSatisfiedBy(A <object> ._)) .Returns(true); var compositeSpecifications = new List <ICompositeSpecification> { _compositeSpecification }; _result = -99; _sut = new ApplicationRunner(_options, _databaseCommandFactory, compositeSpecifications); }
public int Run() { try { // need to validate we have a valid setup of options if (!_specifications.Any(x => x.IsSatisfiedBy(_options))) { _logger.Error("Unable to process options passed into the application"); _logger.Error("Errors found:"); foreach (var specification in _specifications) { _logger.Error(string.Join(Environment.NewLine, specification.ErrorMessages)); } return(ApplicationStatus.Failure); } var commands = _databaseCommandFactory.CreateDatabaseCommands(_options.Engine) .ToList(); foreach (IDatabaseCommand command in commands) { var commandName = command.GetType() .Name; _logger.Debug($"Executing command {commandName}"); var commandResult = command.Execute(_options); if (!commandResult.IsSuccessful) { if (commandResult.Exception == null) { return(ApplicationStatus.Failure); } throw commandResult.Exception; } if (!commandResult.RequiresUpgrade) { continue; } _logger.Debug($"Upgrade is required for command {commandName}"); return(ApplicationStatus.UpgradeIsRequired); } return(ApplicationStatus.Success); } catch (Exception e) { _logger.Error(e); return(ApplicationStatus.Failure); } }
protected override void Arrange() { _options = new WhatIfExecution { Engine = EngineType.SqlServer, DatabaseType = DatabaseType.ODS, ConnectionString = "Valid Connection String", Features = new List <string> { "Changes", "Sample" } }; _databaseCommand = Stub <IDatabaseCommand>(); _databaseCommandFactory = Stub <IDatabaseCommandFactory>(); A.CallTo(() => _databaseCommandFactory.CreateDatabaseCommands(A <EngineType> ._)) .Returns(new List <IDatabaseCommand> { _databaseCommand }); _compositeSpecification = Stub <ICompositeSpecification>(); A.CallTo(() => _compositeSpecification.IsSatisfiedBy(A <object> ._)) .Returns(true); A.CallTo(() => _databaseCommand.Execute(A <IOptions> ._)) .Returns( new DatabaseCommandResult { IsSuccessful = true, RequiresUpgrade = false }); var compositeSpecifications = new List <ICompositeSpecification> { _compositeSpecification }; _result = -99; _sut = new ApplicationRunner(_options, _databaseCommandFactory, compositeSpecifications); }
public void Should_create_the_database_commands() => A.CallTo( () => _databaseCommandFactory.CreateDatabaseCommands( A <EngineType> .That.Matches(x => x == EngineType.PostgreSql))) .MustHaveHappened();