Permalink
Browse files

start fleshing out actionscheduler

  • Loading branch information...
1 parent 2b57288 commit 721d110a39d30aeef851ee24cee2715c24da3b20 Lucas Meijer committed Apr 15, 2012
Showing with 48 additions and 14 deletions.
  1. +11 −6 ActionScheduler.cs
  2. +33 −8 Tests/ActionSchedulerTest.cs
  3. +4 −0 Tests/SimpleAction.cs
View
@@ -1,18 +1,23 @@
-using System;
-using cake;
+using System.Collections.Generic;
+using System.Linq;
-namespace bs
+namespace cake
{
public class ActionScheduler
{
- public void Add(string target, TargetGenerateSettings tgs, string[] dependenciesRequiringRegeneration)
+ private Dictionary<TargetGenerateSettings, List<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, List<string>>();
+
+ public void Add(IEnumerable<string> dependenciesRequiringRegeneration, TargetGenerateSettings tgs)
{
- throw new NotImplementedException();
+ _scheduledActions.Add(tgs, new List<string>(dependenciesRequiringRegeneration));
}
public TargetGenerateSettings FindJobToRun()
{
- throw new NotImplementedException();
+ var findJobToRun = _scheduledActions.Where(kvp => kvp.Value.Count == 0).Select(kvp=>kvp.Key).FirstOrDefault();
+ if (findJobToRun!=null)
+ _scheduledActions.Remove(findJobToRun);
+ return findJobToRun;
}
}
}
@@ -5,23 +5,48 @@
using cake.Tests;
using NUnit.Framework;
-namespace bs.Tests
+namespace cake.Tests
{
[TestFixture]
public class ActionSchedulerTest
{
+ ActionScheduler _scheduler;
+ private SimpleAction _action;
+
+ [SetUp]
+ public void Setup()
+ {
+ _scheduler = new ActionScheduler();
+ _action = new SimpleAction();
+ }
+
[Test]
- [Ignore]
- public void Test()
+ public void SingleActionWithoutDependenciesRequiringGenerationCanBeRun()
{
- var scheduler = new ActionScheduler();
+ var tgs = new TargetGenerateSettings(_action, new[] {"input"}, "output");
+ _scheduler.Add(new string[0], tgs);
- var action = new SimpleAction(s => { });
- var tgs = new TargetGenerateSettings(action, new[] {"input"}, "output");
- scheduler.Add("output", tgs, new string[0]);
+ Assert.AreEqual(tgs,_scheduler.FindJobToRun());
+ }
- var jobToRun = scheduler.FindJobToRun();
+ [Test]
+ public void DoesNotProvideSameJobTwice()
+ {
+ var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
+ _scheduler.Add(new string[0], tgs);
+ Assert.AreEqual(tgs, _scheduler.FindJobToRun());
+ Assert.IsNull(_scheduler.FindJobToRun());
}
+
+ [Test]
+ public void SingleActionWithDependenciesRequiringGenerationCannotBeRun()
+ {
+ var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
+ _scheduler.Add(new[]{"input"}, tgs);
+
+ Assert.IsNull(_scheduler.FindJobToRun());
+ }
+
}
}
View
@@ -18,6 +18,10 @@ public SimpleAction(Action<TargetGenerateSettings> invoke, string actionHash)
_actionHash = actionHash;
}
+ public SimpleAction() : this(s=> { })
+ {
+ }
+
public void Invoke(TargetGenerateSettings settings)
{
_invoke(settings);

0 comments on commit 721d110

Please sign in to comment.