-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
372 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace roundhouse.tests | ||
{ | ||
class DummyDatabase | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using roundhouse.folders; | ||
|
||
namespace roundhouse.tests | ||
{ | ||
class MockKnownFolders: KnownFolders | ||
{ | ||
public MigrationsFolder alter_database | ||
{ | ||
get { return get_migrationsfolder("alter_database"); } | ||
} | ||
|
||
public MigrationsFolder run_after_create_database | ||
{ | ||
get { return get_migrationsfolder("run_after_create_database"); } | ||
} | ||
public MigrationsFolder run_before_up | ||
{ | ||
get { return get_migrationsfolder("run_before_up"); } | ||
} | ||
public MigrationsFolder up | ||
{ | ||
get { return get_migrationsfolder("up"); } | ||
} | ||
public MigrationsFolder down | ||
{ | ||
get { return get_migrationsfolder("down"); } | ||
} | ||
public MigrationsFolder run_first_after_up | ||
{ | ||
get { return get_migrationsfolder("run_first_afte_up"); } | ||
} | ||
public MigrationsFolder functions | ||
{ | ||
get { return get_migrationsfolder("functions"); } | ||
} | ||
public MigrationsFolder views | ||
{ | ||
get { return get_migrationsfolder("views"); } | ||
} | ||
public MigrationsFolder sprocs | ||
{ | ||
get { return get_migrationsfolder("sprocs"); } | ||
} | ||
public MigrationsFolder triggers | ||
{ | ||
get { return get_migrationsfolder("triggers"); } | ||
} | ||
public MigrationsFolder indexes | ||
{ | ||
get { return get_migrationsfolder("indexes"); } | ||
} | ||
public MigrationsFolder run_after_other_any_time_scripts | ||
{ | ||
get { return get_migrationsfolder("run_after_other_any_time_scrips"); } | ||
} | ||
public MigrationsFolder permissions | ||
{ | ||
get { return get_migrationsfolder("permissions"); } | ||
} | ||
public MigrationsFolder before_migration | ||
{ | ||
get { return get_migrationsfolder("before_migration"); } | ||
} | ||
public MigrationsFolder after_migration | ||
{ | ||
get { return get_migrationsfolder("after_migration"); } | ||
} | ||
public Folder change_drop | ||
{ | ||
get { return get_migrationsfolder("change_drop"); } | ||
} | ||
|
||
private MigrationsFolder get_migrationsfolder(string name) | ||
{ | ||
return new MockMigrationsFolder(name); | ||
} | ||
|
||
public class MockMigrationsFolder: MigrationsFolder | ||
{ | ||
public MockMigrationsFolder(string folder_name) | ||
{ | ||
this.folder_name = folder_name; | ||
this.folder_path = "folder_prefix\\" + folder_name; | ||
this.folder_full_path = "drive_and_source_structure\\" + folder_path; | ||
this.friendly_name = "friendly " + folder_name; | ||
} | ||
|
||
public string folder_name { get; set; } | ||
|
||
public string folder_path { get; private set; } | ||
|
||
public string folder_full_path { get; private set; } | ||
|
||
public bool should_run_items_in_folder_once { get; private set; } | ||
|
||
public bool should_run_items_in_folder_every_time { get; private set; } | ||
|
||
public string friendly_name { get; private set; } | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
product/roundhouse.tests/migrators/DefaultDatabaseMigratorSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
product/roundhouse.tests/runners/RoundhouseMigratorRunnerSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using Moq; | ||
using roundhouse.consoles; | ||
using roundhouse.databases; | ||
using roundhouse.environments; | ||
using roundhouse.infrastructure.containers; | ||
using roundhouse.infrastructure.containers.custom; | ||
using roundhouse.infrastructure.filesystem; | ||
using roundhouse.infrastructure.logging; | ||
using roundhouse.infrastructure.logging.custom; | ||
using roundhouse.migrators; | ||
using roundhouse.resolvers; | ||
using roundhouse.runners; | ||
|
||
namespace roundhouse.tests.runners | ||
{ | ||
public class RoundhouseMigratorRunnerSpecs | ||
{ | ||
public abstract class concern_for_migrator_runner : TinySpec<RoundhouseMigrationRunner> | ||
{ | ||
protected object result; | ||
protected DefaultEnvironment environment; | ||
protected readonly DefaultConfiguration configuration; | ||
private RoundhouseMigrationRunner default_database_migrator; | ||
|
||
protected Mock<DatabaseMigrator> database_migrator_mock; | ||
|
||
protected concern_for_migrator_runner() | ||
{ | ||
configuration = new DefaultConfiguration | ||
{ | ||
EnvironmentName = "TEST", | ||
Drop = false , | ||
Silent = true | ||
}; | ||
|
||
var database_mock = new Mock<Database>(); | ||
var filesystem_mock = new Mock<FileSystemAccess>(); | ||
var version_resolver_mock = new Mock<VersionResolver>(); | ||
|
||
var known_folders_mock = new MockKnownFolders(); | ||
|
||
var environment_mock = Mock.Of<EnvironmentSet>(); | ||
|
||
database_migrator_mock = new Mock<DatabaseMigrator>(); | ||
database_migrator_mock.Setup(m => m.database).Returns(database_mock.Object); | ||
|
||
default_database_migrator = | ||
new RoundhouseMigrationRunner( | ||
configuration.RepositoryPath, | ||
environment_mock, | ||
known_folders_mock, | ||
filesystem_mock.Object, | ||
database_migrator_mock.Object, | ||
version_resolver_mock.Object, | ||
configuration.Silent, | ||
configuration.Drop, | ||
configuration.DoNotCreateDatabase, | ||
configuration.WithTransaction, | ||
configuration.RecoveryModeSimple, | ||
configuration); | ||
|
||
var container_mock = new Mock<InversionContainer>(); | ||
|
||
setup_logging(container_mock); | ||
|
||
var the_container = container_mock.Object; | ||
Container.initialize_with(the_container); | ||
} | ||
|
||
private static void setup_logging(Mock<InversionContainer> container_mock) | ||
{ | ||
var mock_log_factory = new Mock<LogFactory>(); | ||
var log_factory = mock_log_factory.Object; | ||
|
||
var logger = get_logger(); | ||
|
||
mock_log_factory.Setup(x => x.create_logger_bound_to(typeof(RoundhouseMigrationRunner))) | ||
.Returns(logger); | ||
|
||
container_mock.Setup(x => x.Resolve<LogFactory>()) | ||
.Returns(log_factory); | ||
} | ||
|
||
private static Logger get_logger() | ||
{ | ||
return new TraceLogger(true); | ||
} | ||
|
||
public override void AfterEachSpec() | ||
{ | ||
Container.initialize_with(null); | ||
} | ||
|
||
protected override RoundhouseMigrationRunner sut | ||
{ | ||
get { return default_database_migrator;} | ||
set { default_database_migrator = value; } | ||
} | ||
} | ||
|
||
[Concern(typeof(RoundhouseMigrationRunner))] | ||
public class when_setting_do_not_alter_database : concern_for_migrator_runner | ||
{ | ||
public when_setting_do_not_alter_database(): base() | ||
{ | ||
configuration.DoNotAlterDatabase = true; | ||
} | ||
|
||
public override void Context() | ||
{} | ||
|
||
public override void Because() | ||
{ | ||
sut.run(); | ||
} | ||
|
||
[Observation] | ||
public void no_connection_to_admin_connection_is_made() | ||
{ | ||
database_migrator_mock.Verify(m => m.open_admin_connection(), Times.Never); | ||
} | ||
} | ||
|
||
[Concern(typeof(RoundhouseMigrationRunner))] | ||
public class when_not_setting_do_not_alter_database : concern_for_migrator_runner | ||
{ | ||
|
||
public when_not_setting_do_not_alter_database(): base() | ||
{ | ||
configuration.DoNotAlterDatabase = false; | ||
sut.run(); | ||
} | ||
|
||
public override void Context() | ||
{} | ||
|
||
public override void Because() | ||
{ | ||
} | ||
|
||
[Observation] | ||
public void a_connection_to_admin_connection_is_made() | ||
{ | ||
database_migrator_mock.Verify(m => m.open_admin_connection(), Times.Once); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.