Program.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.IO;
  7. using System.Diagnostics;
  8. namespace WCFServers
  9. {
  10. class Program
  11. {
  12. List<object> initialized = new List<object> ();
  13. object getInstance (Type type) {
  14. try {
  15. return Activator.CreateInstance (type);
  16. }
  17. catch (Exception e) {
  18. Console.WriteLine ("Failed to initialize object. Skipping");
  19. return null;
  20. } finally {
  21. Console.Write ("Initialized....");
  22. }
  23. }
  24. void runSetUp (object t) {
  25. Console.Write ("Attempting to start type " + t.GetType().FullName + " ....");
  26. var methods = from method in t.GetType ().GetMethods (BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
  27. where method.GetCustomAttributes (typeof (NUnit.Framework.SetUpAttribute), true).Length > 0
  28. select method;
  29. if (methods.Count () == 0) {
  30. Console.WriteLine ("No SetUp methods. Skipping");
  31. return;
  32. }
  33. bool good = false;
  34. foreach (var method in methods)
  35. try {
  36. method.Invoke (t, null);
  37. good = true;
  38. }
  39. catch (Exception e) {
  40. Console.Write ("Failed to call method " + method.Name);
  41. }
  42. if (good) {
  43. Console.WriteLine ("Success.");
  44. initialized.Add (t);
  45. }
  46. else {
  47. Console.WriteLine ("No setup methods successfully called. Skipping");
  48. }
  49. }
  50. void runInit (Type type) {
  51. object t = getInstance (type);
  52. if (t == null)
  53. return;
  54. runSetUp (t);
  55. }
  56. void runAllInits (Assembly assem) {
  57. var types = from type in assem.GetTypes ()
  58. where type.GetCustomAttributes (typeof (NUnit.Framework.TestFixtureAttribute), true).Length > 0
  59. select type;
  60. foreach (Type type in types) {
  61. runInit (type);
  62. }
  63. Console.WriteLine ("Successfully initialized " + initialized.Count + " types: ");
  64. {
  65. foreach (object o in initialized)
  66. Console.WriteLine (o.GetType ().FullName);
  67. }
  68. }
  69. static void Main (string [] args) {
  70. if (args.Count() > 0 && args [0] == "shutdown") {
  71. MonoTests.Features.Configuration.onlyClients = true;
  72. MonoTests.Features.Serialization.ExitProcessHelper exiter = new MonoTests.Features.Serialization.ExitProcessHelper ();
  73. exiter.Run (); // initialize the client
  74. exiter.Client.ExitProcess (0); // exit the server
  75. Environment.Exit (0); // exit this process
  76. }
  77. string assemblyName = "System.ServiceModel_test_net_3_0.dll";
  78. Assembly assem;
  79. try {
  80. System.IO.FileInfo fi = new FileInfo (Assembly.GetEntryAssembly ().Location);
  81. assem = Assembly.LoadFrom (Path.Combine (fi.Directory.FullName, assemblyName));
  82. }
  83. catch (Exception e) {
  84. Console.WriteLine ("Could not start server. Could not load: " + assemblyName);
  85. return;
  86. }
  87. // Run only the servers. No need to initialize the clients.
  88. MonoTests.Features.Configuration.onlyServers = true;
  89. Program p = new Program ();
  90. p.runAllInits (assem);
  91. Console.WriteLine ("Press any key to continue...");
  92. Console.ReadKey ();
  93. Console.WriteLine ("Bye bye");
  94. Environment.Exit (0);
  95. }
  96. }
  97. }