Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4784ce5
commit 68d4f60
Showing
19 changed files
with
144 additions
and
403 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -15,3 +15,5 @@ Downloads/ | |
/TestResult.xml | ||
_ReShaper.*/ | ||
*.nupkg | ||
_TeamCity.*/ | ||
packages/ |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="FS" version="0.0.3" targetFramework="net40" /> | ||
</packages> |
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Bounce.Framework.Tests { | ||
public class MockTask : ITask { | ||
public string FullName { get; set; } | ||
public IEnumerable<ITaskParameter> Parameters { get; set; } | ||
public TaskParameters WasInvokedWithTaskParameters { get; private set; } | ||
public bool WasInvoked { get; private set; } | ||
|
||
public void Invoke(TaskParameters taskParameters) { | ||
WasInvoked = true; | ||
WasInvokedWithTaskParameters = taskParameters; | ||
} | ||
} | ||
} |
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,61 @@ | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
|
||
namespace Bounce.Framework.Tests { | ||
[TestFixture] | ||
public class TaskRunnerTests { | ||
[Test] | ||
public void InvokesTaskByWholeName() { | ||
var task = new MockTask {FullName = "asdf"}; | ||
var runner = new TaskRunner(); | ||
var taskParameters = new TaskParameters(new Dictionary<string, string>()); | ||
runner.RunTask("asdf", taskParameters, new [] {task}); | ||
|
||
Assert.That(task.WasInvoked, Is.True); | ||
Assert.That(task.WasInvokedWithTaskParameters, Is.SameAs(taskParameters)); | ||
} | ||
|
||
[Test] | ||
public void CanInvokeTaskByPartialNames() { | ||
var task = new MockTask {FullName = "The.Full.Path.To.Task"}; | ||
var runner = new TaskRunner(); | ||
|
||
AssertTaskIsInvokedWithName("The.Full.Path.To.Task", runner, task); | ||
AssertTaskIsInvokedWithName("Full.Path.To.Task", runner, task); | ||
AssertTaskIsInvokedWithName("Path.To.Task", runner, task); | ||
AssertTaskIsInvokedWithName("To.Task", runner, task); | ||
AssertTaskIsInvokedWithName("Task", runner, task); | ||
} | ||
|
||
[Test] | ||
public void TaskCanBeInvokedWithNameInsensitiveOfCase() { | ||
var task = new MockTask {FullName = "The.Full.Path.To.Task"}; | ||
var runner = new TaskRunner(); | ||
|
||
AssertTaskIsInvokedWithName("the.full.path.to.task", runner, task); | ||
AssertTaskIsInvokedWithName("task", runner, task); | ||
} | ||
|
||
[Test] | ||
public void CannotBeInvokedTaskByPartialNameWithoutSpecificName() { | ||
var task = new MockTask {FullName = "The.Full.Path.To.Task"}; | ||
var runner = new TaskRunner(); | ||
|
||
AssertTaskIsNotInvokedWithName("The.Full.Path.To", runner, task); | ||
AssertTaskIsNotInvokedWithName("Full.Path.To", runner, task); | ||
AssertTaskIsNotInvokedWithName("Path.To", runner, task); | ||
AssertTaskIsNotInvokedWithName("To", runner, task); | ||
} | ||
|
||
private static void AssertTaskIsInvokedWithName(string taskName, TaskRunner runner, MockTask task) { | ||
runner.RunTask(taskName, new TaskParameters(new Dictionary<string, string>()), new[] {task}); | ||
Assert.That(task.WasInvoked, Is.True); | ||
} | ||
|
||
private static void AssertTaskIsNotInvokedWithName(string taskName, TaskRunner runner, MockTask task) { | ||
Assert.That( | ||
() => runner.RunTask(taskName, new TaskParameters(new Dictionary<string, string>()), new[] {task}), | ||
Throws.InstanceOf<NoMatchingTaskException>()); | ||
} | ||
} | ||
} |
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
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,7 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Bounce.Framework { | ||
public interface ITaskRunner { | ||
void RunTask(string taskName, TaskParameters taskParameters, IEnumerable<ITask> tasks); | ||
} | ||
} |
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,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Bounce.Framework { | ||
public class TaskRunner : ITaskRunner { | ||
public void RunTask(string taskName, TaskParameters taskParameters, IEnumerable<ITask> tasks) { | ||
var matchingTasks = tasks.Where(t => AllTaskNames(t).Contains(taskName.ToLower())).ToArray(); | ||
|
||
if (matchingTasks.Count() > 1) { | ||
throw new AmbiguousTaskNameException(taskName, matchingTasks); | ||
} else if (!matchingTasks.Any()) { | ||
throw new NoMatchingTaskException(taskName, tasks); | ||
} else { | ||
matchingTasks.Single().Invoke(taskParameters); | ||
} | ||
} | ||
|
||
public IEnumerable<string> AllTaskNames(ITask task) | ||
{ | ||
var fullName = task.FullName.ToLower(); | ||
|
||
yield return fullName; | ||
int index = fullName.IndexOf("."); | ||
while (index > 0) | ||
{ | ||
fullName = fullName.Substring(index + 1); | ||
yield return fullName; | ||
index = fullName.IndexOf("."); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.