示例#1
0
文件: Test.cs 项目: tmont/ntestify
        /// <summary>
        /// Runs the test, and sets the ExecutionContext's Result property
        /// with the result of the test
        /// </summary>
        /// <param name="executionContext">The current test execution context</param>
        public void Run(ExecutionContext executionContext)
        {
            Initialize(executionContext);
            OnBeforeRun.Invoke(executionContext);
            executionContext.Result.Status = TestStatus.Running;

            try {
                RunPreTestFilters(executionContext);
                RunTest(executionContext);
                Pass(executionContext);
            } catch (Exception exception) {
                executionContext.ThrownException = exception;
            }

            HandleThrownException(executionContext);

            try {
                RunPostTestFilters(executionContext);
            } catch (Exception filterException) {
                Error(executionContext, filterException);
            }

            if (executionContext.Result.Status == TestStatus.Running)
            {
                SetResultStatus(executionContext);
            }

            InvokeStatusEvent(executionContext);
            executionContext.Result.EndTime = DateTime.Now;
            OnAfterRun.Invoke(executionContext);
        }
示例#2
0
        /// <summary>
        /// The main process thread.
        /// Rises <see cref="OnRun"/> event every <see cref="Tick"/> time elapsed
        /// </summary>
        public void Run()
        {
            // Rise onbefore event
            OnBeforeRun?.Invoke(this);

            // Get the tick period in seconds
            Tick = IoC.Application.TaskRunnerTick;

            // Starts the new thread
            IoC.Task.Run(() =>
            {
                // Initialize the control variable
                var LastRun = DateTime.Now;

                // Run as long as the control flag is true
                while (IsRunning)
                {
                    // Ticks every previus defined second
                    if (DateTime.Now - LastRun >= TimeSpan.FromSeconds(Tick))
                    {
                        // Saves the time this run happens
                        LastRun = DateTime.Now;

                        // The time since last iteration
                        var IntervalTime = DateTime.Now - LastRun;

                        // Diagnostics tools to reveal the timestamp in code
                        var Watch = new Stopwatch();
                        Watch.Start();

                        // Increment time elapsed only with fullplay
                        if(Writings)
                            ElapsedTime += IntervalTime;

                        // Run the principal event
                        OnRun?.Invoke(this);

                        // Evaluate finish conditions only if we do not wanted to force stop
                        // Kill this thread if nobody is using
                        if (IsRunning)
                            IsRunning = IsReadings() || Writings;

                        // Stop watch time
                        Watch.Stop();
                        
                        // Log
                        IoC.Logger.Log($"Elapsed Time {ElapsedTime.ToString()}, and time in operations {Watch.ElapsedMilliseconds.ToString()}", LogLevel.Debug);
                    }
                }
            });
        }