public void PackageNotOpen_NewRequestsSaveDestination()
        {
            ViewModel.BrowsingSave = args => TestCompleted.Set();

            ViewModel.NewCommand.Execute(null);

            WaitForCompletion();
        }
Beispiel #2
0
        /// <summary>
        /// Notifies event handlers that the test is completed.
        /// </summary>
        private void ReportTestCompleted()
        {
            TestCompleted testCompleted = OnTestCompleted;

            if (testCompleted != null)
            {
                testCompleted(_currentLog);
            }
        }
Beispiel #3
0
        private void OnTestCompleted(TestMethod test, TestResult result)
        {
            _lastRun.Add(test);
            _knownOutcomes.Add(test, result.Outcome);

            TestCompleted?.Invoke(this, new TestCompletedEventArgs(test, result));
            // This call is safe - OnTestCompleted cannot be called from outside RD's context.
            _uiDispatcher.FlushMessageQueue();
        }
 private void TestEngineTestCompleted(object sender, TestCompletedEventArgs e)
 {
     // Propagate the event
     TestCompleted?.Invoke(sender, e);
 }
Beispiel #5
0
        private async Task <TestResultInfo> TestExecutionAsync(Test test, bool onlyFocused)
        {
            if (_cancellationTokenSource.Token.IsCancellationRequested)
            {
                return(null);
            }

            Stopwatch     stopwatch = new Stopwatch();
            StringBuilder output    = new StringBuilder();
            Exception     exception = null;
            TestResult    testResult;

            await _testSynchroniser.WaitAsync();

            if (test.IsExcluded)
            {
                testResult = TestResult.Skipped;
                output.Append("Test skipped due to having been defined with xDescribe or xIt.");
            }
            else if (onlyFocused && !test.IsFocused)
            {
                testResult = TestResult.Skipped;
                output.Append("Test skipped due to other tests being defined with fDescribe or fIt.");
            }
            else
            {
                try
                {
                    stopwatch.Start();

                    foreach (var method in test.Execution.GetDelegates())
                    {
                        switch (method)
                        {
                        case Action normal:
                            normal.Invoke();
                            break;

                        case Action <StringBuilder> normalWithOutput:
                            normalWithOutput.Invoke(output);
                            break;

                        case Func <Task> task:
                            await task.Invoke();

                            break;

                        case Func <StringBuilder, Task> taskWithOutput:
                            await taskWithOutput.Invoke(output);

                            break;
                        }
                    }

                    stopwatch.Stop();
                    output.Append(Environment.NewLine).Append("Test completed successfully.");
                    testResult = TestResult.Passed;
                }
                catch (Exception ex)
                {
                    var innermostException = ex;

                    while (innermostException.InnerException != null)
                    {
                        innermostException = innermostException.InnerException;
                    }

                    output.Append(Environment.NewLine).Append(innermostException.Message);
                    exception  = ex;
                    testResult = TestResult.Failed;
                }
            }

            _clearSpiesMethod.Invoke(null, new object[0]);
            _testSynchroniser.Release();

            var result = new TestResultInfo(test, testResult, output.ToString().Trim(), exception, stopwatch.Elapsed);

            try
            {
                TestCompleted?.Invoke(result);
            }
            catch
            {
            }

            return(result);
        }
        private void StartReadThread()
        {
            if (readThread != null)
            {
                System.Windows.Forms.MessageBox.Show("PAC read thread already assigned!");
            }
            readThread = new Thread(() =>
            {
                while (keepReadThreadAlive)
                {
                    pac.Write32BitIntegerVariable("bVisionRunning", false, 1);
                    var eMethodResponse = pac.ReadGroupItems(tagReadArray, 0, tagReadArray.Length);
                    tagReadArray[0].GetData(out bPressurize);
                    tagReadArray[1].GetData(out bAirFill);
                    tagReadArray[2].GetData(out iHeadDown);
                    tagReadArray[3].GetData(out bTesting);
                    tagReadArray[4].GetData(out fPressure);
                    tagReadArray[5].GetData(out bTareVisionSystem);
                    tagReadArray[6].GetData(out fPercTargetPressure);
                    tagReadArray[7].GetData(out bTestComplete);
                    tagReadArray[8].GetData(out bFail1);
                    tagReadArray[9].GetData(out bFail2);
                    tagReadArray[10].GetData(out bFail3);
                    tagReadArray[11].GetData(out bFail4);
                    tagReadArray[12].GetData(out bFail5);
                    tagReadArray[13].GetData(out bFail6);
                    tagReadArray[14].GetData(out bFail7);
                    tagReadArray[15].GetData(out bFail8);


                    if (bTesting == 1 && bTestingLast == 0)
                    {
                        eMethodResponse = pac.ReadGroupItems(stringReadArray, 0, stringReadArray.Length);
                        string[] s      = Enumerable.Repeat <string>("null", stringReadArray.Length).ToArray();
                        for (int i = 0; i < stringReadArray.Length; i++)
                        {
                            stringReadArray[i].GetData(out s[i]);
                        }
                        StartTest?.Invoke(s, new EventArgs());
                    }
                    bTestingLast = bTesting;

                    if (iHeadDown == 1 && iHeadDownLast == 0)
                    {
                        HeadDown?.Invoke(this, new EventArgs());
                    }
                    iHeadDownLast = iHeadDown;

                    if (bTareVisionSystem == 1 && bTareVisionSystemLast == 0)
                    {
                        StartTakeThreshold?.Invoke(this, new EventArgs());
                    }
                    if (bTareVisionSystem == 0 && bTareVisionSystemLast == 1 && bTesting == 1)
                    {
                        StopTakeThreshold?.Invoke(this, new EventArgs());
                    }
                    bTareVisionSystemLast = bTareVisionSystem;

                    if (bPressurize == 0 && bPressurizeLast == 1)
                    {
                        StopTest?.Invoke(this, new EventArgs());
                    }
                    bPressurizeLast = bPressurize;

                    if (bTestComplete == 1 && bTestCompleteLast == 0)
                    {
                        TestCompleted?.Invoke(this, new EventArgs());
                    }
                    bTestCompleteLast = bTestComplete;

                    Thread.Sleep(250);
                }
            });
            keepReadThreadAlive = true;
            readThread.Start();
        }
Beispiel #7
0
 protected void WaitForCompletion(int timeout = 2000)
 {
     TestCompleted.Wait(timeout);
 }
Beispiel #8
0
 private void OnTestCompleted(TestMethod test, TestResult result)
 {
     resultsByOutcome[result.Outcome].Add(test);
     LastRun.Add(test);
     _uiDispatcher.InvokeAsync(() => TestCompleted?.Invoke(this, new TestCompletedEventArgs(test, result)));
 }
Beispiel #9
0
        private async Task <TestResultInfo> TestExecutionAsync(Test test, bool onlyFocused)
        {
            if (_cancellationTokenSource.Token.IsCancellationRequested)
            {
                return(null);
            }

            Stopwatch     stopwatch = new Stopwatch();
            StringBuilder output    = new StringBuilder();
            Exception     exception = null;
            TestResult    testResult;

            await Jaz.CurrentTestSemaphore.WaitAsync();

            _setupTestExecutionContextMethod.Invoke(null, new object[] { test.FullName, output });

            if (test.IsExcluded)
            {
                testResult = TestResult.Skipped;
                output.Append("Test skipped due to having been defined with xDescribe or xIt.");
            }
            else if (onlyFocused && !test.IsFocused)
            {
                testResult = TestResult.Skipped;
                output.Append("Test skipped due to other tests being defined with fDescribe or fIt.");
            }
            else
            {
                try
                {
                    stopwatch.Start();

                    foreach (var method in test.Execution.GetDelegates())
                    {
                        if (method is Action action)
                        {
                            action.Invoke();
                        }
                        else
                        {
                            await((Func <Task>)method).Invoke();
                        }
                    }

                    stopwatch.Stop();
                    output.Append(Environment.NewLine).Append("Test completed successfully.");
                    testResult = TestResult.Passed;
                }
                catch (Exception ex)
                {
                    var innermostException = ex;

                    while (innermostException.InnerException != null)
                    {
                        innermostException = innermostException.InnerException;
                    }

                    output.Append(Environment.NewLine).Append(innermostException.Message);
                    exception  = ex;
                    testResult = TestResult.Failed;
                }
            }

            _clearTestExecutionContextMethod.Invoke(null, new object[0]);
            Jaz.CurrentTestSemaphore.Release();

            var result = new TestResultInfo(test, testResult, output.ToString().Trim(), exception, stopwatch.Elapsed);

            try
            {
                TestCompleted?.Invoke(result);
            }
            catch
            {
            }

            return(result);
        }