<commit_before>﻿// --------------------------------------------------------------------------------------------------
//  <copyright file="TestRunner.cs" company="DNS Technology Pty Ltd.">
//    Copyright (c) 2015 DNS Technology Pty Ltd. All rights reserved.
//  </copyright>
// --------------------------------------------------------------------------------------------------

namespace MsTestRunner
{
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Reflection;
    using System.Threading;
    using System.Threading.Tasks;

    public sealed class TestRunner
    {
        #region Fields

        private readonly HashSet<string> fileNames = new HashSet<string>();

        private readonly string path;

        private readonly List<Func<int>> testList = new List<Func<int>>();

        #endregion

        #region Constructors and Destructors

        public TestRunner(string path)
        {
            this.path = path;
            Directory.CreateDirectory(this.path);
        }

        #endregion

        #region Public Methods and Operators

        public void AddTestAssembly(string filePath)
        {
            var testClasses = new List<Type>();
            if (this.fileNames.Add(Path.GetFileName(filePath)))
            {
                try
                {
                    var allTypes = Assembly.LoadFrom(Path.GetFullPath(filePath)).GetTypes();
                    foreach (var type in allTypes)
                    {
                        if (type.GetCustomAttributes().Any(c => c.GetType().Name == "TestClassAttribute") && !type.GetCustomAttributes().Any(c => c.GetType().Name == "IgnoreAttribute"))
                        {
                            var deploymentItems = type.GetCustomAttributes().Where(c => c.GetType().Name == "DeploymentItemAttribute");
                            foreach (var deploymentItem in deploymentItems.Select(
                                d =>
                                    {
                                        dynamic item = d;
                                        return Tuple.Create((string)item.Path, (string)item.OutputDirectory);
                                    }))
                            {
                                var sourcePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileName(deploymentItem.Item1));
                                var destPath = Path.Combine(this.path, deploymentItem.Item2 ?? string.Empty, Path.GetFileName(deploymentItem.Item1));

                                if (File.Exists(destPath))
                                {
                                    Trace.TraceWarning(
                                        "The Deployment Item {0} on {1} has the same File Name as another Deployment Item, please add an output directory path to each of the deployment items",
                                        deploymentItem.Item1,
                                        type.FullName);
                                }
                                else
                                {
                                    File.Copy(sourcePath, destPath);    
                                }
                            }

                            testClasses.Add(type);
                        }<commit_msg>fixing issue with missing deployment item in the source folder<commit_after>﻿// --------------------------------------------------------------------------------------------------
//  <copyright file="TestRunner.cs" company="DNS Technology Pty Ltd.">
//    Copyright (c) 2015 DNS Technology Pty Ltd. All rights reserved.
//  </copyright>
// --------------------------------------------------------------------------------------------------

namespace MsTestRunner
{
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Reflection;
    using System.Threading;
    using System.Threading.Tasks;

    public sealed class TestRunner
    {
        #region Fields

        private readonly HashSet<string> fileNames = new HashSet<string>();

        private readonly string path;

        private readonly List<Func<int>> testList = new List<Func<int>>();

        #endregion

        #region Constructors and Destructors

        public TestRunner(string path)
        {
            this.path = path;
            Directory.CreateDirectory(this.path);
        }

        #endregion

        #region Public Methods and Operators

        public void AddTestAssembly(string filePath)
        {
            var testClasses = new List<Type>();
            if (this.fileNames.Add(Path.GetFileName(filePath)))
            {
                try
                {
                    var allTypes = Assembly.LoadFrom(Path.GetFullPath(filePath)).GetTypes();
                    foreach (var type in allTypes)
                    {
                        if (type.GetCustomAttributes().Any(c => c.GetType().Name == "TestClassAttribute") && !type.GetCustomAttributes().Any(c => c.GetType().Name == "IgnoreAttribute"))
                        {
                            var deploymentItems = type.GetCustomAttributes().Where(c => c.GetType().Name == "DeploymentItemAttribute");
                            foreach (var deploymentItem in deploymentItems.Select(
                                d =>
                                    {
                                        dynamic item = d;
                                        return Tuple.Create((string)item.Path, (string)item.OutputDirectory);
                                    }))
                            {
                                var sourcePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileName(deploymentItem.Item1));
                                var destPath = Path.Combine(this.path, deploymentItem.Item2 ?? string.Empty, Path.GetFileName(deploymentItem.Item1));

                                if (File.Exists(destPath))
                                {
                                    Trace.TraceWarning(
                                        "The Deployment Item {0} on {1} has the same File Name as another Deployment Item, please add an output directory path to each of the deployment items",
                                        deploymentItem.Item1,
                                        type.FullName);
                                }
                                else
                                {
                                    if (!File.Exists(sourcePath))
                                    {
                                        Trace.TraceWarning(
                                            "The Deployment File {0} for {1} was not found",
                                            sourcePath,
                                            type.FullName);
                                    } 
                                    else 
                                    {
                                        File.Copy(sourcePath, destPath);        
                                    }
                                    
                                }
                            }

                            testClasses.Add(type);
                        }
{'fraction_non_alphanumeric': 0.12732836615220863, 'fraction_numerical': 0.002927088877062267, 'mean_word_length': 1.0018641810918776, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3189021', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1469, 'n_words': 360}