PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/TestDomain.cs

#
C# | 126 lines | 91 code | 24 blank | 11 comment | 12 complexity | d30cef1ad04c65fe248d3f5c1f4208be MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You
  3. // may obtain a copy of the license as well as information regarding
  4. // copyright ownership at http://nunit.org
  5. // ****************************************************************
  6. using System;
  7. namespace NUnit.Util
  8. {
  9. using System.Diagnostics;
  10. using System.Security.Policy;
  11. using System.Reflection;
  12. using System.Collections;
  13. using System.Configuration;
  14. using System.IO;
  15. using NUnit.Core;
  16. public class TestDomain : ProxyTestRunner, TestRunner
  17. {
  18. static Logger log = InternalTrace.GetLogger(typeof(TestDomain));
  19. #region Instance Variables
  20. /// <summary>
  21. /// The appdomain used to load tests
  22. /// </summary>
  23. private AppDomain domain;
  24. /// <summary>
  25. /// The TestAgent in the domain
  26. /// </summary>
  27. private DomainAgent agent;
  28. #endregion
  29. #region Constructors
  30. public TestDomain() : base( 0 ) { }
  31. public TestDomain( int runnerID ) : base( runnerID ) { }
  32. #endregion
  33. #region Properties
  34. public AppDomain AppDomain
  35. {
  36. get { return domain; }
  37. }
  38. #endregion
  39. #region Loading and Unloading Tests
  40. public override bool Load( TestPackage package )
  41. {
  42. Unload();
  43. log.Info("Loading " + package.Name);
  44. try
  45. {
  46. if ( this.domain == null )
  47. this.domain = Services.DomainManager.CreateDomain( package );
  48. if (this.agent == null)
  49. {
  50. this.agent = DomainAgent.CreateInstance(domain);
  51. this.agent.Start();
  52. }
  53. if ( this.TestRunner == null )
  54. this.TestRunner = this.agent.CreateRunner( this.ID );
  55. log.Info("Loading tests in AppDomain, see {0}.log", domain.FriendlyName);
  56. return TestRunner.Load( package );
  57. }
  58. catch
  59. {
  60. log.Error("Load failure");
  61. Unload();
  62. throw;
  63. }
  64. }
  65. public override void Unload()
  66. {
  67. if (this.TestRunner != null)
  68. {
  69. log.Info("Unloading");
  70. this.TestRunner.Unload();
  71. this.TestRunner = null;
  72. }
  73. if (this.agent != null)
  74. {
  75. log.Info("Stopping DomainAgent");
  76. this.agent.Dispose();
  77. this.agent = null;
  78. }
  79. if(domain != null)
  80. {
  81. log.Info("Unloading AppDomain " + domain.FriendlyName);
  82. Services.DomainManager.Unload(domain);
  83. domain = null;
  84. }
  85. }
  86. #endregion
  87. #region Running Tests
  88. public override void BeginRun(EventListener listener, ITestFilter filter)
  89. {
  90. log.Info("BeginRun in AppDomain {0}", domain.FriendlyName);
  91. base.BeginRun(listener, filter);
  92. }
  93. #endregion
  94. #region IDisposable Members
  95. public override void Dispose()
  96. {
  97. base.Dispose();
  98. Unload();
  99. }
  100. #endregion
  101. }
  102. }