<commit_before>﻿/*
Edison is designed to be simpler and more performant unit/integration testing framework.

Copyright (c) 2015, <NAME> (Badgerati)
Company: Cadaeic Studios
License: MIT (see LICENSE for details)
 */

using Edison.Framework;
using Edison.Engine.Utilities.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Edison.Engine.Utilities.Helpers;
using System.Threading;
using Edison.Engine.Threading;
using Edison.Engine.Core.Enums;
using Edison.Engine.Utilities.Structures;
using System.Diagnostics;
using Edison.Engine.Core.Output;

namespace Edison.Engine.Contexts
{
    public class EdisonContext
    {

        #region Properties
        
        public List<string> AssemblyPaths { get; private set; }
        public List<string> IncludedCategories { get; private set; }
        public List<string> ExcludedCategories { get; private set; }
        public List<string> Fixtures { get; private set; }
        public int NumberOfThreads { get; set; }
        public string OutputFile { get; set; }
        public string OutputFolder { get; set; }
        public OutputType OutputType { get; set; }
        public bool CreateOutput { get; set; }
        public string TestResultURL { get; set; }
        public string TestRunId { get; set; }

        private Stopwatch Timer = default(Stopwatch);
        private TestResultDictionary ResultQueue = default(TestResultDictionary);

        private IList<EdisonTestThread> Threads = default(IList<EdisonTestThread>);
        private EdisonTestThread SingularThread = default(EdisonTestThread);

        #endregion

        #region Constructor

        public EdisonContext()
        {
            AssemblyPaths = new List<string>(1);
            IncludedCategories = new List<string>();
            ExcludedCategories = new List<string>();
            Fixtures = new List<string>();
            NumberOfThreads = 1;
            OutputType = OutputType.Txt;
            OutputFolder = Environment.CurrentDirectory;
            OutputFile = "ResultFile";
            CreateOutput = true;
            TestResultURL = string.Empty;
        }

        #endregion

        #region Public Methods

        public void Run()
        {
            //start timer
            Timer = new Stopwatch();
            Timer.Start();

            //create queue
            ResultQueue = new TestResultDictionary(this);
            
            foreach (var assemblyPath in AssemblyPaths)
            {
                var assembly = Assembly.LoadFile(Path.GetFullPath(assemblyPath));

                //global setup
                var globalSetupFixture = assembly.GetTypes<SetupFixtureAttribute>().SingleOrDefault();
                var globalActivator = Activator.CreateInstance(globalSetupFixture, null);
                var globalSetupEx = RunGlobalSetup(globalSetupFixture, globalActivator);

                //test fixtures an threads
                SetupThreads(assembly, globalSetupEx);

                //global teardown
                RunGlobalTeardown(globalSetupFixture, globalActivator);
            }

            Timer.Stop();
            
            //create result file and write
            if (CreateOutput)
            {
                Logger.WriteDoubleLine(Environment.NewLine);
                Logger.WriteMessage("Creating output file...");
                var file = Logger.CreateFile(OutputFolder, OutputFile, OutputType);
                WriteResultsToFile(file);
                Logger.WriteMessage("Output file created:\n" + file);
            }            
            else
            {
                Logger.WriteMessage("Output file creation disabled");
            }

            //write results and timer
            Logger.WriteDoubleLine(Environment.NewLine);
            Logger.WriteMessage(ResultQueue.ToTotalString());
            Logger.WriteMessage(string.Format("Total time: {0}", Timer.Elapsed));
            Logger.WriteDoubleLine(postcede: Environment.NewLine);
        }
        
        #endregion

        #region Private Methods
<commit_msg>Fixes for Assembly dependency loading, and having no GlobalSetupFixture<commit_after>﻿/*
Edison is designed to be simpler and more performant unit/integration testing framework.

Copyright (c) 2015, <NAME> (Badgerati)
Company: Cadaeic Studios
License: MIT (see LICENSE for details)
 */

using Edison.Framework;
using Edison.Engine.Utilities.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Edison.Engine.Utilities.Helpers;
using System.Threading;
using Edison.Engine.Threading;
using Edison.Engine.Core.Enums;
using Edison.Engine.Utilities.Structures;
using System.Diagnostics;
using Edison.Engine.Core.Output;

namespace Edison.Engine.Contexts
{
    public class EdisonContext
    {

        #region Properties
        
        public List<string> AssemblyPaths { get; private set; }
        public List<string> IncludedCategories { get; private set; }
        public List<string> ExcludedCategories { get; private set; }
        public List<string> Fixtures { get; private set; }
        public int NumberOfThreads { get; set; }
        public string OutputFile { get; set; }
        public string OutputFolder { get; set; }
        public OutputType OutputType { get; set; }
        public bool CreateOutput { get; set; }
        public string TestResultURL { get; set; }
        public string TestRunId { get; set; }

        private Stopwatch Timer = default(Stopwatch);
        private TestResultDictionary ResultQueue = default(TestResultDictionary);

        private IList<EdisonTestThread> Threads = default(IList<EdisonTestThread>);
        private EdisonTestThread SingularThread = default(EdisonTestThread);

        #endregion

        #region Constructor

        public EdisonContext()
        {
            AssemblyPaths = new List<string>(1);
            IncludedCategories = new List<string>();
            ExcludedCategories = new List<string>();
            Fixtures = new List<string>();
            NumberOfThreads = 1;
            OutputType = OutputType.Txt;
            OutputFolder = Environment.CurrentDirectory;
            OutputFile = "ResultFile";
            CreateOutput = true;
            TestResultURL = string.Empty;
        }

        #endregion

        #region Public Methods

        public void Run()
        {
            //start timer
            Timer = new Stopwatch();
            Timer.Start();

            //create queue
            ResultQueue = new TestResultDictionary(this);
            AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

            foreach (var assemblyPath in AssemblyPaths)
            {
                var assembly = Assembly.LoadFile(Path.GetFullPath(assemblyPath));

                //global setup
                var globalSetupFixture = assembly.GetTypes<SetupFixtureAttribute>().SingleOrDefault();
                var globalActivator = default(object);
                var globalSetupEx = default(Exception);

                if (globalSetupFixture != default(Type))
                {
                    globalActivator = Activator.CreateInstance(globalSetupFixture, null);
                    globalSetupEx = RunGlobalSetup(globalSetupFixture, globalActivator);
                }

                //test fixtures an threads
                SetupThreads(assembly, globalSetupEx);

                //global teardown
                if (globalSetupFixture != default(Type))
                {
                    RunGlobalTeardown(globalSetupFixture, globalActivator);
                }
            }

            Timer.Stop();
            
            //create result file and write
            if (CreateOutput)
            {
                Logger.WriteDoubleLine(Environment.NewLine);
                Logger.WriteMessage("Creating output file...");
                var file = Logger.CreateFile(OutputFolder, OutputFile, OutputType);
                WriteResultsToFile(file);
                Logger.WriteMessage("Output file created:\n" + file);
            }            
            else
            {
                Logger.WriteMessage("Output file creation disabled");
            }

            //write results and timer
            Logger.WriteDoubleLine(Environment.NewLine);
            Logger.WriteMessage(ResultQueue.ToTotalString());
            Logger.WriteMessage(string.Format("Total time: {0}", Timer.Elapsed));
            Logger.WriteDoubleLine(postcede: Environment.NewLine);
        }
        
        #endregion

        #region Private Methods

        private Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            var name = new AssemblyName(args.Name).Name;
            var path = Path.GetDirectoryName(args.RequestingAssembly.Location);
            return Assembly.LoadFrom(path + "\\" + name + ".dll");
        }

{'fraction_non_alphanumeric': 0.0830755634114008, 'fraction_numerical': 0.0015466195315952276, 'mean_word_length': 2.1217241379310345, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '2634850', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2129, 'n_words': 561}