PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/TheOrderedJobs/FluentAssertions.cs

https://bitbucket.org/thomaseyde/the-ordered-jobs-kata
C# | 48 lines | 40 code | 8 blank | 0 comment | 1 complexity | 5dfe39d6b66ec1b2e34383d666524d57 MD5 | raw file
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using TheOrderedJobs.Code;
  5. namespace TheOrderedJobs
  6. {
  7. internal static class FluentAssertions
  8. {
  9. public static void ShouldContain(this IEnumerable<Job> jobs, string names)
  10. {
  11. Assert.IsTrue(jobs.All(job => names.Contains(job.Name)));
  12. }
  13. public static void ShouldBeFalse(this bool condition)
  14. {
  15. Assert.IsFalse(condition);
  16. }
  17. public static void ShouldEqual<T>(this T actual, T expected)
  18. {
  19. Assert.AreEqual(expected, actual);
  20. }
  21. public static void ShouldHaveFollowingOrder(this IEnumerable<Job> jobs, Job first, Job last)
  22. {
  23. jobs.ShouldHaveFollowingOrder(first.Name, last.Name);
  24. }
  25. public static void ShouldHaveFollowingOrder(this IEnumerable<Job> jobs, string first, string last)
  26. {
  27. Assert.IsTrue(jobs.HasFollowingOrder(first, last));
  28. }
  29. private static bool HasFollowingOrder(this IEnumerable<Job> jobs, string first, string last)
  30. {
  31. var firstIndex = jobs.OrderOf(first);
  32. var lastIndex = jobs.OrderOf(last);
  33. return firstIndex < lastIndex;
  34. }
  35. public static int OrderOf(this IEnumerable<Job> jobs, string name)
  36. {
  37. return jobs.TakeWhile(job => job.Name != name).Count();
  38. }
  39. }
  40. }