Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implement Equals() for schedulableaction + simplify test.

  • Loading branch information...
commit 2d73babe3ce7256f5a0407fb0142b64a894d8a57 1 parent 3df1a20
Lucas Meijer authored
Showing with 27 additions and 5 deletions.
  1. +20 −0 SchedulableAction.cs
  2. +7 −5 Tests/SchedulableActionCollectorTest.cs
View
20 SchedulableAction.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
namespace cake
{
@@ -17,5 +18,24 @@ public SchedulableAction(TargetGenerateSettings generateSettings, IEnumerable<st
Settings = generateSettings;
InputFilesRequiringGeneration = inputFilesRequiringGeneration;
}
+
+ public override bool Equals(System.Object obj)
+ {
+ if (obj == null)
+ return false;
+
+ var other = obj as SchedulableAction;
+ if ((System.Object) other == null) //the cast here is required even if resharper thinks it isn't
+ return false;
+
+ bool equals1 = Equals(other.Settings, Settings);
+ bool equals2 = other.InputFilesRequiringGeneration.SequenceEqual(InputFilesRequiringGeneration);
+ return equals1 && equals2;
+ }
+
+ public override int GetHashCode()
+ {
+ return Settings.GetHashCode() ^ InputFilesRequiringGeneration.GetHashCode();
+ }
}
}
View
12 Tests/SchedulableActionCollectorTest.cs
@@ -40,11 +40,13 @@ public void CanCollectMultipleActions()
var result = _collector.CollectActionsToGenerate("file3").ToArray();
- Assert.AreEqual(2, result.Length);
-
- //HALP! how to do a more reasonable equivalenec test?
- CollectionAssert.AreEquivalent(result.Select(r=>r.Settings), new[] { settings1,settings2});
- CollectionAssert.AreEquivalent(result.Select(r => r.InputFilesRequiringGeneration), new[] { new string[0], new[]{"file2"}});
+ var expected = new[]
+ {
+ new SchedulableAction(settings1, new string[0] {}),
+ new SchedulableAction(settings2, new string[1] {"file2"})
+ };
+
+ CollectionAssert.AreEquivalent(result,expected);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.