Skip to content

Commit

Permalink
Adding Project Root as third command line parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
codereflection committed Feb 10, 2011
1 parent 4c3f4f0 commit d774584
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
5 changes: 5 additions & 0 deletions src/Giles.Core/Configuration/GilesConfig.cs
Expand Up @@ -6,8 +6,13 @@ namespace Giles.Core.Configuration
public class GilesConfig : INotifyPropertyChanged
{
public IDictionary<string, RunnerAssembly> TestRunners = new Dictionary<string, RunnerAssembly>();

public string TestAssemblyPath { get; set; }

public string SolutionPath { get; set; }

public string ProjectRoot { get; set; }

long buildDelay = 500;

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
27 changes: 14 additions & 13 deletions src/Giles.Core/Configuration/GilesConfigFactory.cs
Expand Up @@ -11,16 +11,17 @@ public class GilesConfigFactory
readonly IFileSystem fileSystem;
readonly string solutionPath;
readonly string testAssemblyPath;
readonly string solutionFolder;
readonly string projectRoot;
readonly string[] supportedRunners;

public GilesConfigFactory(GilesConfig config, IFileSystem fileSystem, string solutionPath, string testAssemblyPath)
public GilesConfigFactory(GilesConfig config, IFileSystem fileSystem, string solutionPath, string testAssemblyPath, string projectRoot)
{
this.config = config;
this.fileSystem = fileSystem;
this.solutionPath = solutionPath;
this.testAssemblyPath = testAssemblyPath;
solutionFolder = fileSystem.GetDirectoryName(solutionPath);
this.projectRoot = projectRoot;

supportedRunners = new[] {"mspec.exe", "nunit-console.exe"};
}

Expand All @@ -35,17 +36,17 @@ public GilesConfig Build()
void LocateTestRunners()
{
supportedRunners.Each(x =>
{
var files = fileSystem.GetFiles(solutionFolder, x,
SearchOption.AllDirectories);
{
var files = fileSystem.GetFiles(projectRoot, x,
SearchOption.AllDirectories);
config.TestRunners.Add(x,
new RunnerAssembly
{
Path = files.FirstOrDefault(),
Enabled = !string.IsNullOrWhiteSpace(files.FirstOrDefault())
});
});
config.TestRunners.Add(x,
new RunnerAssembly
{
Path = files.FirstOrDefault(),
Enabled = !string.IsNullOrWhiteSpace(files.FirstOrDefault())
});
});
}
}
}
17 changes: 8 additions & 9 deletions src/Giles.Specs/Core/Configuration/GilesConfigFactorySpecs.cs
Expand Up @@ -17,20 +17,22 @@ public class a_giles_config
protected static string solutionFolder;
protected static string testRunnerExe;
protected static string testAssemblyPath;
protected static string projectRoot;

Establish context = () =>
{
solutionFolder = @"c:\solutionFolder";
solutionPath = @"c:\solutionFolder\mySolution.sln";
testAssemblyPath = @"c:\solutionFolder\tests\bin\debug\tests.dll";
solutionFolder = @"c:\solutionRoot\solution";
solutionPath = @"c:\solutionRoot\solution\mySolution.sln";
testAssemblyPath = @"c:\solutionRoot\solution\tests\bin\debug\tests.dll";
fileSystem = Substitute.For<IFileSystem>();
testRunnerExe = @"c:\testAssembly.exe";
fileSystem.GetFiles(Arg.Any<string>(), Arg.Any<string>(), SearchOption.AllDirectories)
.Returns(new[] { testRunnerExe });
fileSystem.GetDirectoryName(solutionPath).Returns(solutionFolder);
projectRoot = @"c:\solutionRoot";
config = new GilesConfig();
factory = new GilesConfigFactory(config, fileSystem, solutionPath, testAssemblyPath);
factory = new GilesConfigFactory(config, fileSystem, solutionPath, testAssemblyPath, projectRoot);
};

}
Expand All @@ -40,14 +42,11 @@ public class when_building : a_giles_config
Because of = () =>
factory.Build();

It gets_the_solution_folder = () =>
fileSystem.Received().GetDirectoryName(solutionPath);

It locates_the_mspec_test_runner = () =>
fileSystem.Received().GetFiles(solutionFolder, "mspec.exe", SearchOption.AllDirectories);
fileSystem.Received().GetFiles(projectRoot, "mspec.exe", SearchOption.AllDirectories);

It locates_the_nunit_test_runner = () =>
fileSystem.Received().GetFiles(solutionFolder, "nunit-console.exe", SearchOption.AllDirectories);
fileSystem.Received().GetFiles(projectRoot, "nunit-console.exe", SearchOption.AllDirectories);

It built_the_correct_config_test_runners = () =>
config.TestRunners.All(x => x.Value.Path == testRunnerExe).ShouldBeTrue();
Expand Down
4 changes: 3 additions & 1 deletion src/Giles/Program.cs
Expand Up @@ -18,10 +18,11 @@ static void Main(string[] args)

var solutionPath = args[0];
var testAssemblyPath = args[1];
var projectRoot = args[2];
//solutionPath = @"D:\Dev\Prototypes\TestableTestStuff\TestableTestStuff.sln";
//testAssemblyPath = @"D:\Dev\Prototypes\TestableTestStuff\ClassThatDoesShit.Tests\bin\Debug\Teh.Tests.dll";

var kernel = new StandardKernel(new SlayerModule(solutionPath, testAssemblyPath));
var kernel = new StandardKernel(new SlayerModule(solutionPath, testAssemblyPath, projectRoot));

var configFactory = kernel.Get<GilesConfigFactory>();
config = configFactory.Build();
Expand Down Expand Up @@ -89,6 +90,7 @@ static void DisplayConfig()
Console.WriteLine("\nCurrent Configuration");
Console.WriteLine(" Build Delay: " + config.BuildDelay);
Console.WriteLine(" Solution: " + config.SolutionPath);
Console.WriteLine(" Project Root: " + config.ProjectRoot);
Console.WriteLine(" Test Assembly: " + config.TestAssemblyPath);
Console.WriteLine();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Giles/SlayerModule.cs
Expand Up @@ -10,11 +10,13 @@ public class SlayerModule : NinjectModule
{
readonly string solutionPath;
readonly string testAssemblyPath;
readonly string projectRoot;

public SlayerModule(string solutionPath, string testAssemblyPath)
public SlayerModule(string solutionPath, string testAssemblyPath, string projectRoot)
{
this.solutionPath = solutionPath;
this.testAssemblyPath = testAssemblyPath;
this.projectRoot = projectRoot;
}

public override void Load()
Expand All @@ -27,7 +29,8 @@ public override void Load()
Bind<GilesConfig>().ToSelf().InSingletonScope();
Bind<GilesConfigFactory>().ToSelf()
.WithConstructorArgument("solutionPath", solutionPath)
.WithConstructorArgument("testAssemblyPath", testAssemblyPath);
.WithConstructorArgument("testAssemblyPath", testAssemblyPath)
.WithConstructorArgument("projectRoot", projectRoot);
}
}
}

0 comments on commit d774584

Please sign in to comment.