<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Qart.Testing
{
    public class TestSession : IDisposable
    {
        private readonly ITestSession _customTestSession;
        private readonly ITestCaseProcessorResolver _testCaseProcessorResolver;
        private readonly ITestCaseLoggerFactory _testCaseLoggerFactory;

        private readonly IList<TestCaseResult> _results;
        public IEnumerable<TestCaseResult> Results { get { return _results; } }

        public TestSession(ITestSession customTestSession, ITestCaseProcessorResolver resolver, ITestCaseLoggerFactory testCaseLoggerFactory)
        {
            _results = new List<TestCaseResult>();
            _customTestSession = customTestSession;
            _testCaseProcessorResolver = resolver;
            _testCaseLoggerFactory = testCaseLoggerFactory;
        }

        public void OnTestCase(TestCase testCase)
        {
            TestCaseResult testResult= new TestCaseResult(testCase);
            _results.Add(testResult);

            if (_customTestSession != null)
            {
                _customTestSession.OnBegin(testCase);
            }

            ITestCaseProcessor processor = null;
            try
            {
                processor = _testCaseProcessorResolver.Resolve(testCase);
                using(var logger = _testCaseLoggerFactory.GetLogger(testCase))
                {
                    processor.Process(testCase, logger);
                }
            }
            catch (Exception ex)
            {
                testResult.MarkAsFailed(ex);
            }

            if(processor != null)
            {
                try
                {
                    testResult.Description = processor.GetDescription(testCase);<commit_msg>Logg exceptions to testcase logs<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Qart.Testing
{
    public class TestSession : IDisposable
    {
        private readonly ITestSession _customTestSession;
        private readonly ITestCaseProcessorResolver _testCaseProcessorResolver;
        private readonly ITestCaseLoggerFactory _testCaseLoggerFactory;

        private readonly IList<TestCaseResult> _results;
        public IEnumerable<TestCaseResult> Results { get { return _results; } }

        public TestSession(ITestSession customTestSession, ITestCaseProcessorResolver resolver, ITestCaseLoggerFactory testCaseLoggerFactory)
        {
            _results = new List<TestCaseResult>();
            _customTestSession = customTestSession;
            _testCaseProcessorResolver = resolver;
            _testCaseLoggerFactory = testCaseLoggerFactory;
        }

        public void OnTestCase(TestCase testCase)
        {
            TestCaseResult testResult= new TestCaseResult(testCase);
            _results.Add(testResult);

            if (_customTestSession != null)
            {
                _customTestSession.OnBegin(testCase);
            }

            ITestCaseProcessor processor = null;
            try
            {
                processor = _testCaseProcessorResolver.Resolve(testCase);
                using(var logger = _testCaseLoggerFactory.GetLogger(testCase))
                {
                    try
                    {
                        processor.Process(testCase, logger);
                    }
                    catch(Exception ex)
                    {
                        logger.Error(ex);
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                testResult.MarkAsFailed(ex);
            }

            if(processor != null)
            {
                try
                {
                    testResult.Description = processor.GetDescription(testCase);
{'fraction_non_alphanumeric': 0.05996963562753036, 'fraction_numerical': 0.0, 'mean_word_length': 1.8095238095238095, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3927666', 'n_tokens_mistral': 901, 'n_tokens_neox': 864, 'n_words': 182}