コード例 #1
0
        private void CheckScreenshotWithPattern(Screenshot screenshot)
        {
            if (screenshot == null)
            {
                throw new ArgumentNullException(nameof(screenshot));
            }

            byte[]             image = screenshot.Data;
            ScreenshotIdentity screenshotIdentity = screenshot.Identity;

            try
            {
                Action finishNotification;
                using (var transaction = PersistanceEngine.GetSession().BeginTransaction())
                {
                    var project       = this.GetProject(screenshotIdentity.ProjectName);
                    var testCase      = GetTestCase(project, screenshotIdentity);
                    var activePattern = testCase.GetActivePatternForBrowser(screenshotIdentity.BrowserName);

                    var newPattern = activePattern == null?testCase.AddNewPattern(image, screenshotIdentity.BrowserName) : null;

                    var testResult = GetTestResult(image, screenshotIdentity, activePattern, newPattern);

                    var testSession = GetCurrentTestSession(project);
                    testSession.AddTestResult(testResult);
                    finishNotification = () =>
                    {
                        switch (testResult.Status)
                        {
                        case TestResultStatus.Failed:
                            testRunnerAdapter.NotifyAboutTestFail(screenshotIdentity.FullName, testSession, activePattern, testResult.TestResultMessage);
                            break;

                        case TestResultStatus.Passed:
                            testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, activePattern, testResult.TestResultMessage);
                            break;

                        case TestResultStatus.NewPattern:
                            testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, newPattern, testResult.TestResultMessage);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    };

                    transaction.Commit();
                }
                finishNotification.Invoke();
            }
            catch (Exception ex)
            {
                testRunnerAdapter.NotifyAboutError(ex);
            }
        }
コード例 #2
0
        private void CheckScreenshotWithPattern(byte[] image, ScreenshotIdentity screenshotIdentity)
        {
            try
            {
                Action finishNotification;
                using (var tx = PersistanceEngine.GetSession().BeginTransaction())
                {
                    var project        = this.GetProject(screenshotIdentity.ProjectName);
                    var testCase       = GetTestCase(project, screenshotIdentity);
                    var browserPattern = testCase.GetActivePatternForBrowser(screenshotIdentity.BrowserName);
                    var testSession    = GetCurrentTestSession(project);

                    if (browserPattern == null)
                    {
                        var newPattern = testCase.AddNewPattern(image, screenshotIdentity.BrowserName);
                        finishNotification = () => testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, newPattern);
                    }
                    else
                    {
                        var testResult = GetTestResult(image, screenshotIdentity, browserPattern);
                        testSession.AddTestResult(testResult);
                        finishNotification = () =>
                        {
                            if (testResult.TestPassed)
                            {
                                testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, browserPattern);
                            }
                            else
                            {
                                testRunnerAdapter.NotifyAboutTestFail(screenshotIdentity.FullName, testSession, browserPattern);
                            }
                        };
                    }
                    tx.Commit();
                }
                finishNotification.Invoke();
            }
            catch (Exception ex)
            {
                testRunnerAdapter.NotifyAboutError(ex);
            }
        }