Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. [TestFixture]
  2. public class RouteTestFixture
  3. {
  4. [Test]
  5. public void Routes_should_not_change()
  6. {
  7.  
  8. const string good = @"all existing routes go here (hint run the test first then copy output to here)";
  9.  
  10. var goodRoutes = good.Split(Convert.ToChar(";"));
  11. var notFound = new List<string>();
  12.  
  13. var ass = Assembly.GetAssembly(typeof (EventStatisticsController));
  14. var sb = new StringBuilder();
  15. foreach (var type in ass.GetTypes())
  16. {
  17. try
  18. {
  19. var members = type.GetMembers();
  20.  
  21.  
  22. for (int i = 0; i < members.Length; i++)
  23. {
  24. // Display the attribute if it is of type MyAttribute.
  25. if (members[i].IsDefined(typeof (RouteAttribute), false))
  26. {
  27. Object[] atts = members[i].GetCustomAttributes(typeof (RouteAttribute), false);
  28.  
  29. for (int j = 0; j < atts.Length; j++)
  30. {
  31. var routeAttribute = (RouteAttribute)atts[j];
  32. string route = routeAttribute.Template + @"/" + routeAttribute.Name;
  33. Console.WriteLine(route);
  34. sb.Append(route + ";");
  35.  
  36. if (!goodRoutes.Contains(route))
  37. {
  38. notFound.Add(route);
  39. }
  40. }
  41. }
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Console.WriteLine(@"An exception occurred: {0}", e.Message);
  47. }
  48. }
  49.  
  50. if (notFound.Any())
  51. {
  52. Console.WriteLine(@"-- MISSING ROUTES --");
  53. foreach (var nf in notFound)
  54. {
  55. Console.WriteLine(nf);
  56. }
  57.  
  58. Assert.Fail("Missing Routes: " + notFound.Count);
  59. }
  60. else
  61. {
  62. Assert.True(true, "All routes matched");
  63. }
  64.  
  65. Console.WriteLine(@"------------------------------------------------");
  66. Console.WriteLine(@"Match the following string for future tests");
  67. Console.WriteLine(sb.ToString());
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement