Ejemplo n.º 1
0
        /// <summary>
        /// Perform common initialization/finalization. Run test action.
        /// </summary>
        /// <param name="action">Test "body"</param>
        /// <param name="cleanUpAction">Clean-up </param>
        protected void RunTest(Action action, Action cleanUpAction)
        {
            if (allPassedModeOn())
            {
                return;
            }

            try
            {
                _halted = false;
                Exception exc = null;

                try
                {
                    System.Diagnostics.Debug.WriteLine("Begin test - inside 1");
                    BeginTest();

                    if (this is IBaseOnvifService)
                    {
                        (this as IBaseOnvifService).GeneralInitialize();
                    }

                    System.Diagnostics.Debug.WriteLine("Begin test - do action");
                    action();
                    System.Diagnostics.Debug.WriteLine("Begin test - action done");

                    if (cleanUpAction == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Begin test - to end test");
                        EndTest(TestStatus.Passed);
                        return;
                    }
                }
                catch (StopEventException)
                {
                    System.Diagnostics.Debug.WriteLine("HALT");

                    if (_videoForm != null)
                    {
                        _videoForm.CloseWindow();
                    }
                    if (NewGenVideo != null)
                    {
                        NewGenVideo.CloseWindow();
                    }

                    Release();
                    _halted = true;

                    LogStepEvent("Halted");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Begin test - Exception in action");
                    StepFailed(ex);
                    System.Diagnostics.Debug.WriteLine("Begin test - fail reported");

                    if (InternalLog)
                    {
                        InternalLogger.GetInstance().SwitchOnForCurrentThread();
                    }
                    else
                    {
                        InternalLogger.GetInstance().SwitchOffForCurrentThread();
                    }

                    InternalLogger.GetInstance().LogMessage("Uncaught exception is thrown during the test!");
                    InternalLogger.GetInstance().LogException(ex);

                    if (cleanUpAction == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Begin test - doing Release");
                        Release();
                        TestFailed(ex);
                        return;
                    }
                    else
                    {
                        exc = ex;
                    }
                }

                if (cleanUpAction != null && !_halted)
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("Clean up");
                        cleanUpAction();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception when trying to restore settings");
                        StepFailed(ex);
                        exc = ex;
                    }

                    if (exc == null)
                    {
                        System.Diagnostics.Debug.WriteLine("End test - passed");
                        EndTest(TestStatus.Passed);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Test failed");
                        try
                        {
                            Release();
                        }
                        catch (Exception)
                        {
                        }
                        TestFailed(exc);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("new catch - Test failed");
                TestFailed(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Perform common initialization/finalization. Run test action.
        /// </summary>
        /// <param name="action">Test "body"</param>
        /// <param name="cleanUpAction">Clean-up </param>
        protected void RunTest(Action action, Action cleanUpAction)
        {
            if (allPassedModeOn())
            {
                return;
            }

            try
            {
                _halted = false;
                Exception exc = null;

                try
                {
                    System.Diagnostics.Debug.WriteLine("Begin test - inside 1");
                    BeginTest();

                    System.Diagnostics.Debug.WriteLine("Begin test - do action");
                    action();
                    System.Diagnostics.Debug.WriteLine("Begin test - action done");

                    if (cleanUpAction == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Begin test - to end test");
                        EndTest(TestStatus.Passed);
                        return;
                    }
                }
                catch (StopEventException)
                {
                    System.Diagnostics.Debug.WriteLine("HALT");

                    if (_videoForm != null)
                    {
                        _videoForm.CloseWindow();
                    }

                    Release();
                    _halted = true;

                    LogStepEvent("Halted");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Begin test - Exception in action");
                    StepFailed(ex);
                    System.Diagnostics.Debug.WriteLine("Begin test - fail reported");

                    if (InternalLog)
                    {
                        InternalLogger.GetInstance().SwitchOnForCurrentThread();
                    }
                    else
                    {
                        InternalLogger.GetInstance().SwitchOffForCurrentThread();
                    }

                    InternalLogger.GetInstance().LogMessage("Uncaught exception is thrown during the test!");
                    InternalLogger.GetInstance().LogMessage("Exception stack below:");
                    var prefix = "    ";
                    for (var e = ex; null != e; e = e.InnerException)
                    {
                        InternalLogger.GetInstance().LogMessage(string.Format("{0}{1}: {2}", prefix, e.GetType().Name, e.Message));
                    }
                    InternalLogger.GetInstance().LogMessage(ex.StackTrace);

                    if (cleanUpAction == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Begin test - doing Release");
                        Release();
                        TestFailed(ex);
                        return;
                    }
                    else
                    {
                        exc = ex;
                    }
                }

                if (cleanUpAction != null && !_halted)
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("Clean up");
                        cleanUpAction();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception when trying to restore settings");
                        StepFailed(ex);
                        exc = ex;
                    }

                    if (exc == null)
                    {
                        System.Diagnostics.Debug.WriteLine("End test - passed");
                        EndTest(TestStatus.Passed);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Test failed");
                        try
                        {
                            Release();
                        }
                        catch (Exception)
                        {
                        }
                        TestFailed(exc);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("new catch - Test failed");
                TestFailed(ex);
            }
        }