/// <summary>
        /// Cleans up the test suite.
        /// User must call this method in ClassCleanup method.
        /// </summary>
        public static void Cleanup()
        {
            classCount--;
            if (classCount == 0)
            {
                //************* Automatic network message capture.*************
                if (autoCapture != null)
                {
                    try
                    {
                        autoCapture.Cleanup();
                    }
                    catch (AutoCaptureException e)
                    {
                        baseTestSite.Log.Add(LogEntryKind.Warning, "Auto capture cleanup Error: " + e.Message);
                        if (e.StopRunning)
                        {
                            throw;
                        }
                    }
                    autoCapture = null;
                }

                /********************* Display expected runtime of the testsuite **************************
                * Calculates the actual time taken for the test suite execution and logs it in log file  *
                ******************************************************************************************/
                executionEndTime = DateTime.Now;
                double actualExecutionTime;
                actualExecutionTime = executionEndTime.Subtract(executionStartTime).TotalSeconds;

                baseTestSite.Log.Add(LogEntryKind.Comment, "Actual time taken for the test suite execution (in seconds) is: " + actualExecutionTime);

                ProtocolTestsManagerFactory.TestsManager.TestsRunCleanup();
            }
        }
        /// <summary>
        /// Initializes the test suite base class with explicitly given test suite name. 
        /// This method must be called by class initialize method in your test class.
        /// </summary>
        /// <param name="testContext">VSTS test context.</param>
        /// <param name="testSuiteName">The name of the test suite. The test site uses this name to find configuration files.</param>
        public static void Initialize(TestContext testContext, string testSuiteName)
        {
            Microsoft.Protocols.TestTools.ExtendedLogging.ExtendedLoggerConfig.TestSuiteName = testSuiteName;
            executionStartTime = DateTime.Now;
            if (testContext == null)
            {
                throw new InvalidOperationException("TestContext should not be null in UnitTestClassBase.");
            }
            classCount++;
            staticTestSuiteName = testSuiteName;
            IProtocolTestsManager manager = ProtocolTestsManagerFactory.TestsManager;

            if (null == manager.GetTestSite(staticTestSuiteName))
            {
                string testAssemblyName;
                IConfigurationData config = ConfigurationDataProvider.GetConfigurationData(
                    testContext.TestDeploymentDir, testSuiteName);
                if (isUseDefaultSuiteName)
                {
                    testAssemblyName = testSuiteName;
                    isUseDefaultSuiteName = false;
                }
                else
                {
                    testAssemblyName = Assembly.GetCallingAssembly().GetName().Name;
                }

                manager.Initialize(config, new VstsTestContext(testContext), testSuiteName, testAssemblyName);

                baseTestSite = manager.GetTestSite(testSuiteName);

                if (IsCommandlineConsoleRulePresent(config.Profiles))
                {
                    AllocConsole();
                    IntPtr hWnd = GetConsoleWindow();
                    bool visible = IsWindowVisible(hWnd);
                    if (!visible) ShowWindow(hWnd, 9); // 9 SW_RESTORE. Make the console visible.
                    Console.WriteLine("Test Results:");
                    Console.WriteLine("==============");
                    string consoleWidth = baseTestSite.Properties.Get("ConsoleWidth");
                    if (consoleWidth != null) Console.WindowWidth = Convert.ToInt32(consoleWidth);
                    string consoleHeight = baseTestSite.Properties.Get("ConsoleHeight");
                    if (consoleHeight != null) Console.WindowHeight = Convert.ToInt32(consoleHeight);
                    string consoleBufferHeight = baseTestSite.Properties.Get("ConsoleBufferHeight");
                    if (consoleBufferHeight != null) Console.BufferHeight = Convert.ToInt32(consoleBufferHeight);
                }
                ITestSite site = manager.GetTestSite(testSuiteName);

                //registry all checkers
                RegisterChecker(site);
            }
            else
            {
                baseTestSite = manager.GetTestSite(testSuiteName);
            }

            /********************* Display expected runtime of the testsuite **********************
             * Log expected execution time of the test suite in the log file                      *
             **************************************************************************************/
            baseTestSite.Log.Add(LogEntryKind.Comment, "Expected execution time of the test suite (in seconds) is: " + baseTestSite.Properties.Get("ExpectedExecutionTime"));

            //************* Automatic network message capture.*************
            if (Convert.ToBoolean(baseTestSite.Properties.Get("PTF.NetworkCapture.Enabled")))
            {
                string assemblyFile = baseTestSite.Properties.Get("PTF.NetworkCapture.Assembly");
                if (assemblyFile == null)
                {
                    // Use logman to capture by default.
                    autoCapture = new LogmanCapture();
                }
                else
                {
                    Assembly assembly = Assembly.LoadFrom(assemblyFile);
                    string className = baseTestSite.Properties.Get("PTF.NetworkCapture.Class");
                    if (className != null)
                    {
                        autoCapture = (IAutoCapture)assembly.CreateInstance(className);
                    }
                    else
                    {
                        foreach (Type type in assembly.GetTypes())
                        {
                            if (type.IsClass && typeof(IAutoCapture).IsAssignableFrom(type))
                            {
                                autoCapture = (IAutoCapture)Activator.CreateInstance(type);
                            }
                        }
                    }
                }
                try
                {
                    if (autoCapture != null) autoCapture.Initialize(baseTestSite.Properties, testSuiteName);
                }
                catch (AutoCaptureException e)
                {
                    baseTestSite.Log.Add(LogEntryKind.Warning, "Auto capture initialize Error: " + e.Message);
                    if (e.StopRunning) throw;
                }
            }
        }
        /// <summary>
        /// Initializes the test suite base class with explicitly given test suite name.
        /// This method must be called by class initialize method in your test class.
        /// </summary>
        /// <param name="testContext">VSTS test context.</param>
        /// <param name="testSuiteName">The name of the test suite. The test site uses this name to find configuration files.</param>
        public static void Initialize(TestContext testContext, string testSuiteName)
        {
            Microsoft.Protocols.TestTools.ExtendedLogging.ExtendedLoggerConfig.TestSuiteName = testSuiteName;
            executionStartTime = DateTime.Now;
            if (testContext == null)
            {
                throw new InvalidOperationException("TestContext should not be null in UnitTestClassBase.");
            }
            classCount++;
            staticTestSuiteName = testSuiteName;
            IProtocolTestsManager manager = ProtocolTestsManagerFactory.TestsManager;

            if (null == manager.GetTestSite(staticTestSuiteName))
            {
                string             testAssemblyName;
                IConfigurationData config = ConfigurationDataProvider.GetConfigurationData(
                    testContext.TestDeploymentDir, testSuiteName);
                if (isUseDefaultSuiteName)
                {
                    testAssemblyName      = testSuiteName;
                    isUseDefaultSuiteName = false;
                }
                else
                {
                    testAssemblyName = Assembly.GetCallingAssembly().GetName().Name;
                }

                manager.Initialize(config, new VstsTestContext(testContext), testSuiteName, testAssemblyName);

                baseTestSite = manager.GetTestSite(testSuiteName);

                if (IsCommandlineConsoleRulePresent(config.Profiles))
                {
                    AllocConsole();
                    IntPtr hWnd    = GetConsoleWindow();
                    bool   visible = IsWindowVisible(hWnd);
                    if (!visible)
                    {
                        ShowWindow(hWnd, 9);           // 9 SW_RESTORE. Make the console visible.
                    }
                    Console.WriteLine("Test Results:");
                    Console.WriteLine("==============");
                    string consoleWidth = baseTestSite.Properties.Get("ConsoleWidth");
                    if (consoleWidth != null)
                    {
                        Console.WindowWidth = Convert.ToInt32(consoleWidth);
                    }
                    string consoleHeight = baseTestSite.Properties.Get("ConsoleHeight");
                    if (consoleHeight != null)
                    {
                        Console.WindowHeight = Convert.ToInt32(consoleHeight);
                    }
                    string consoleBufferHeight = baseTestSite.Properties.Get("ConsoleBufferHeight");
                    if (consoleBufferHeight != null)
                    {
                        Console.BufferHeight = Convert.ToInt32(consoleBufferHeight);
                    }
                }
                ITestSite site = manager.GetTestSite(testSuiteName);

                //registry all checkers
                RegisterChecker(site);
            }
            else
            {
                baseTestSite = manager.GetTestSite(testSuiteName);
            }


            /********************* Display expected runtime of the testsuite **********************
            * Log expected execution time of the test suite in the log file                      *
            **************************************************************************************/
            baseTestSite.Log.Add(LogEntryKind.Comment, "Expected execution time of the test suite (in seconds) is: " + baseTestSite.Properties.Get("ExpectedExecutionTime"));

            //************* Automatic network message capture.*************
            if (Convert.ToBoolean(baseTestSite.Properties.Get("PTF.NetworkCapture.Enabled")))
            {
                string assemblyFile = baseTestSite.Properties.Get("PTF.NetworkCapture.Assembly");
                if (assemblyFile == null)
                {
                    // Use logman to capture by default.
                    autoCapture = new LogmanCapture();
                }
                else
                {
                    Assembly assembly  = Assembly.LoadFrom(assemblyFile);
                    string   className = baseTestSite.Properties.Get("PTF.NetworkCapture.Class");
                    if (className != null)
                    {
                        autoCapture = (IAutoCapture)assembly.CreateInstance(className);
                    }
                    else
                    {
                        foreach (Type type in assembly.GetTypes())
                        {
                            if (type.IsClass && typeof(IAutoCapture).IsAssignableFrom(type))
                            {
                                autoCapture = (IAutoCapture)Activator.CreateInstance(type);
                            }
                        }
                    }
                }
                try
                {
                    if (autoCapture != null)
                    {
                        autoCapture.Initialize(baseTestSite.Properties, testSuiteName);
                    }
                }
                catch (AutoCaptureException e)
                {
                    baseTestSite.Log.Add(LogEntryKind.Warning, "Auto capture initialize Error: " + e.Message);
                    if (e.StopRunning)
                    {
                        throw;
                    }
                }
            }
        }
        /// <summary>
        /// Cleans up the test suite. 
        /// User must call this method in ClassCleanup method.
        /// </summary>
        public static void Cleanup()
        {
            classCount--;
            if (classCount == 0)
            {
                //************* Automatic network message capture.*************
                if (autoCapture != null)
                {
                    try
                    {
                        autoCapture.Cleanup();
                    }
                    catch (AutoCaptureException e)
                    {
                        baseTestSite.Log.Add(LogEntryKind.Warning, "Auto capture cleanup Error: " + e.Message);
                        if (e.StopRunning) throw;
                    }
                    autoCapture = null;
                }

                /********************* Display expected runtime of the testsuite **************************
                 * Calculates the actual time taken for the test suite execution and logs it in log file  *
                 ******************************************************************************************/
                executionEndTime = DateTime.Now;
                double actualExecutionTime;
                actualExecutionTime = executionEndTime.Subtract(executionStartTime).TotalSeconds;

                baseTestSite.Log.Add(LogEntryKind.Comment, "Actual time taken for the test suite execution (in seconds) is: " + actualExecutionTime);

                ProtocolTestsManagerFactory.TestsManager.TestsRunCleanup();
            }
        }