Skip to content

Commit

Permalink
Merge pull request #252 from macfarmw/trim-version-text
Browse files Browse the repository at this point in the history
(GH-240) Trim version file contents
  • Loading branch information
ferventcoder committed May 25, 2016
2 parents d2ca49a + c5ad14a commit b8923e8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
57 changes: 57 additions & 0 deletions product/roundhouse.tests/resolvers/TextVersionResolverSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace roundhouse.tests.resolvers
{
using System;
using bdddoc.core;
using developwithpassion.bdd.contexts;
using developwithpassion.bdd.mbunit;
using developwithpassion.bdd.mbunit.standard;
using developwithpassion.bdd.mbunit.standard.observations;
using roundhouse.infrastructure.filesystem;
using roundhouse.resolvers;
using Rhino.Mocks;

public class TextVersionResolverSpecs
{
public abstract class concern_for_textversion_resolver : observations_for_a_sut_with_a_contract<VersionResolver, TextVersionResolver>
{
[CLSCompliant(false)]
protected static VersionResolver the_resolver;
}

public abstract class concerns_using_a_fake_filesystem : concern_for_textversion_resolver
{
protected static FileSystemAccess the_filesystem;
protected static string the_versionfile;
private context c = () =>
{
the_filesystem = an<FileSystemAccess>();
the_versionfile = string.Format(@"{0}.txt", Guid.NewGuid());
provide_a_basic_sut_constructor_argument(the_filesystem);
provide_a_basic_sut_constructor_argument(the_versionfile);
};
}

[Concern(typeof(TextVersionResolver))]
public class when_asking_the_resolver_for_the_version_the_version_text_is_trimmed : concerns_using_a_fake_filesystem
{
private const string untrimmed = " 1.3.837.1342 \r\n";
private const string trimmed = "1.3.837.1342";
private static string result;
private context c =
() =>
{
the_filesystem.Stub(x => x.file_exists(the_versionfile)).Return(true);
the_filesystem.Stub(x => x.read_file_text(the_versionfile)).Return(untrimmed);
the_filesystem.Stub(x => x.get_full_path(the_versionfile)).Return(the_versionfile);
};

private because b = () => { result = sut.resolve_version(); };

[Observation]
public void untrimmed_version_from_file_is_trimmed_when_resolved()
{
result.should_be_equal_to(trimmed);
}
}
}
}
1 change: 1 addition & 0 deletions product/roundhouse.tests/roundhouse.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<Compile Include="migrators\DefaultDatabaseMigratorSpecs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="infrastructure\filesystem\DotNetFileSystemAccessSpecs.cs" />
<Compile Include="resolvers\TextVersionResolverSpecs.cs" />
<Compile Include="sqlsplitters\SplitterContext.cs" />
<Compile Include="sqlsplitters\StatementSplitterSpecs.cs" />
<Compile Include="TestExtensions.cs" />
Expand Down
2 changes: 1 addition & 1 deletion product/roundhouse/resolvers/TextVersionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string resolve_version()
{
try
{
version = file_system.read_file_text(version_file);
version = file_system.read_file_text(version_file).Trim();
Log.bound_to(this).log_an_info_event_containing(" Found version {0} from {1}.", version, version_file);
}
catch (Exception e)
Expand Down

0 comments on commit b8923e8

Please sign in to comment.