Skip to content

Commit

Permalink
Merge branch 'erikbra-issue-182'
Browse files Browse the repository at this point in the history
  • Loading branch information
BiggerNoise committed Oct 12, 2017
2 parents 11a9c33 + 0f8ab2a commit c022634
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 39 deletions.
4 changes: 4 additions & 0 deletions product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
.Add("dc|dnc|donotcreatedatabase",
"DoNotCreateDatabase - This instructs RH to not create a database if it does not exists. Defaults to false.",
option => configuration.DoNotCreateDatabase = option != null)
//don't alter the database (e.g. to avoid needing master DB login)
.Add("da|dna|donotalterdatabase",
"DoNotAlterDatabase - This instructs RH to not alter the database. Defaults to false.",
option => configuration.DoNotAlterDatabase = option != null)
//output
.Add("o=|output=|outputpath=",
string.Format(
Expand Down
2 changes: 2 additions & 0 deletions product/roundhouse.tasks/Roundhouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ bool ITask.Execute()

public bool DoNotCreateDatabase { get; set; }

public bool DoNotAlterDatabase { get; set; }

public string OutputPath { get; set; }

public bool WarnOnOneTimeScriptChanges { get; set; }
Expand Down
12 changes: 12 additions & 0 deletions product/roundhouse.tests/DummyDatabase.cs
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
{
}
}
102 changes: 102 additions & 0 deletions product/roundhouse.tests/MockKnownFolders.cs
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; }
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void Context()

public override void Because()
{
result = Log.bound_to(typeof(StructureMapContainer));
result = Log.bound_to(new StructureMapContainer(null));
}

[Observation]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using roundhouse.consoles;
using roundhouse.databases;
using roundhouse.environments;
using roundhouse.migrators;
using Should;

namespace roundhouse.tests.infrastructure.containers
namespace roundhouse.tests.migrators
{
using consoles;

using environments;
using migrators;

public class DefaultDatabaseMigratorSpecs
{
public abstract class concern_for_database_migrator : TinySpec<DefaultDatabaseMigrator>
Expand Down
4 changes: 2 additions & 2 deletions product/roundhouse.tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Castle.Core" version="4.1.0" targetFramework="net45" />
Expand All @@ -7,5 +7,5 @@
<package id="NUnit.ConsoleRunner" version="3.6.1" targetFramework="net45" />
<package id="Should" version="1.1.12.0" targetFramework="net45" />
<package id="structuremap" version="2.6.3" />
<package id="TinySpec.NUnit" version="0.9.5" targetFramework="net45" />
<package id="TinySpec.NUnit" version="0.9.5" targetFramework="net35" />
</packages>
8 changes: 6 additions & 2 deletions product/roundhouse.tests/roundhouse.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -70,7 +71,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\..\packages\Castle.Core.4.1.0\lib\net45\Castle.Core.dll</HintPath>
<HintPath>..\..\packages\Castle.Core.4.1.0\lib\net35\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -80,7 +81,7 @@
<HintPath>..\..\packages\Moq.4.7.49\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
<HintPath>..\..\packages\NUnit.3.7.1\lib\net35\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Should, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Should.1.1.12.0\lib\Should.dll</HintPath>
Expand All @@ -107,6 +108,7 @@
<Link>Properties\SolutionVersion.cs</Link>
</Compile>
<Compile Include="databases\SqlServerDatabaseSpecs.cs" />
<Compile Include="DummyDatabase.cs" />
<Compile Include="EmptyTestContainer.cs" />
<Compile Include="cryptography\CryptographicServiceSpecs.cs" />
<Compile Include="infrastructure.app\tokens\TokenReplacerSpecs.cs" />
Expand All @@ -120,9 +122,11 @@
<Compile Include="infrastructure\logging\custom\Log4NetLoggerSpecs.cs" />
<Compile Include="infrastructure\logging\LogSpecs.cs" />
<Compile Include="migrators\DefaultDatabaseMigratorSpecs.cs" />
<Compile Include="MockKnownFolders.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="infrastructure\filesystem\DotNetFileSystemAccessSpecs.cs" />
<Compile Include="resolvers\TextVersionResolverSpecs.cs" />
<Compile Include="runners\RoundhouseMigratorRunnerSpecs.cs" />
<Compile Include="sqlsplitters\SplitterContext.cs" />
<Compile Include="sqlsplitters\StatementSplitterSpecs.cs" />
<Compile Include="TestExtensions.cs" />
Expand Down
149 changes: 149 additions & 0 deletions product/roundhouse.tests/runners/RoundhouseMigratorRunnerSpecs.cs
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);
}
}

}
}
1 change: 1 addition & 0 deletions product/roundhouse/consoles/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public string DatabaseType { get; set; }
public bool Drop { get; set; }
public bool DoNotCreateDatabase { get; set; }
public bool DoNotAlterDatabase { get; set; }
public bool WithTransaction { get; set; }
public RecoveryMode RecoveryMode { get; set; }
[Obsolete("Use RecoveryMode = Simple")]
Expand Down
Loading

0 comments on commit c022634

Please sign in to comment.