Skip to content

Commit

Permalink
pulled out filesystem for testability
Browse files Browse the repository at this point in the history
  • Loading branch information
csMACnz committed Jul 14, 2017
1 parent b488dac commit 0ebe710
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/csmacnz.Coveralls.Tests/CoverallsTestRunner.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using System.Collections.Generic;
using csmacnz.CLIArgsParser;
using csmacnz.Coveralls.Adapters;

namespace csmacnz.Coveralls.Tests
{
public static class CoverallsTestRunner
{
private const string CoverallsExe = "csmacnz.Coveralls.exe";

public static CoverallsRunResults RunCoveralls(string arguments)
{
var testConsole = new TestConsole();
var exitCode = new Program(testConsole, "1.0.0.0").Run(ArgsParser.Parse(arguments)) ?? 0;
var exitCode = new Program(testConsole, new FileSystem(), "1.0.0.0").Run(ArgsParser.Parse(arguments)) ?? 0;

var results = string.Join("\n", testConsole.StandardOut);
Console.WriteLine(results);
Expand Down
19 changes: 11 additions & 8 deletions src/csmacnz.Coveralls/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using csmacnz.Coveralls.Adapters;
using csmacnz.Coveralls.Data;
using csmacnz.Coveralls.GitDataResolvers;
using csmacnz.Coveralls.Ports;
using JetBrains.Annotations;
using Newtonsoft.Json;

Expand All @@ -18,23 +19,30 @@ public class Program
{
private readonly IConsole _console;
private readonly string _version;
private static IFileSystem _fileSystem;

public Program(IConsole console, string version)
public Program(IConsole console, IFileSystem fileSystem, string version)
{
_console = console;
_fileSystem = fileSystem;
_version = version;
}

public static void Main(string[] argv)
{
var console = new StandardConsole();
var result = new Program(console, GetDisplayVersion()).Run(argv);
var result = new Program(console, new FileSystem(), GetDisplayVersion()).Run(argv);
if (result.HasValue)
{
Environment.Exit(result.Value);
}
}

private static NotNull<string> GetDisplayVersion()
{
return FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductVersion;
}

public int? Run(string[] argv)
{
try
Expand Down Expand Up @@ -186,7 +194,7 @@ private static List<CoverageFile> LoadCoverageFiles(Option<CoverageMode> mode, P
{
ExitWithError("Unknown mode provided");
}
var coverageFiles = new CoverageLoader(new FileSystem()).LoadCoverageFiles((CoverageMode)mode,
var coverageFiles = new CoverageLoader(_fileSystem).LoadCoverageFiles((CoverageMode)mode,
pathProcessor, inputArgument, useRelativePaths);
if (coverageFiles.Successful)
{
Expand Down Expand Up @@ -271,11 +279,6 @@ private static Option<CoverageMode> GetMode(MainArgs args)
return Option<CoverageMode>.None; //Unreachable
}

private static NotNull<string> GetDisplayVersion()
{
return FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductVersion;
}

[ContractAnnotation("=>halt")]
private static void ExitWithError(string message)
{
Expand Down

0 comments on commit 0ebe710

Please sign in to comment.