Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Pondidum/commandline-di
CommandLine DI
- Loading branch information
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/FubuCore.Testing/CommandLine/ActivatorCommandCreatorTests.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,51 @@ | ||
using System; | ||
using FubuCore.CommandLine; | ||
using FubuTestingSupport; | ||
using NUnit.Framework; | ||
|
||
namespace FubuCore.Testing.CommandLine | ||
{ | ||
public class ActivatorCommandCreatorTests | ||
{ | ||
[Test] | ||
public void builds_an_instance_with_no_ctor_parameters() | ||
{ | ||
var creator = new ActivatorCommandCreator(); | ||
var instance = creator.Create(typeof (NoParamsCommand)); | ||
|
||
instance.ShouldBeOfType<NoParamsCommand>(); | ||
} | ||
|
||
[Test] | ||
public void throws_if_the_ctor_has_parameters() | ||
{ | ||
var creator = new ActivatorCommandCreator(); | ||
|
||
Assert.Throws<MissingMethodException>(() => creator.Create(typeof (ParamsCommand))); | ||
} | ||
|
||
public class FakeModel | ||
{ | ||
} | ||
|
||
private class NoParamsCommand : FubuCommand<FakeModel> | ||
{ | ||
public override bool Execute(FakeModel input) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
|
||
private class ParamsCommand : FubuCommand<FakeModel> | ||
{ | ||
public ParamsCommand(string testArgument) | ||
{ | ||
} | ||
|
||
public override bool Execute(FakeModel input) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} | ||
} |
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; | ||
|
||
namespace FubuCore.CommandLine | ||
{ | ||
public class ActivatorCommandCreator : ICommandCreator | ||
{ | ||
public IFubuCommand Create(Type commandType) | ||
{ | ||
return Activator.CreateInstance(commandType).As<IFubuCommand>(); | ||
} | ||
} | ||
} |
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,9 @@ | ||
using System; | ||
|
||
namespace FubuCore.CommandLine | ||
{ | ||
public interface ICommandCreator | ||
{ | ||
IFubuCommand Create(Type commandType); | ||
} | ||
} |
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