<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Deployment.WindowsInstaller.Linq;
using Microsoft.Deployment.WindowsInstaller.Linq.Entities;
using System.Reflection;
using NUnit.Framework;
using System.IO;

namespace CprBroker.Tests.WixInstaller
{
    [TestFixture]
    public class IntegrityTests
    {
        static readonly string SolutionDir = new DirectoryInfo(@"..\..\..\").FullName;

        [Test]
        public void CustomActions_MethodAvailable()
        {
            System.Diagnostics.Debugger.Launch();
            var path = SolutionDir + @"WixInstaller\bin\Debug\en-US\CprBroker.msi";
            using (var database = new Database(path))
            {
                foreach (CustomAction_ ca in database.AsQueryable().CustomActions)
                {
                    if ((ca.Type & CustomActionTypes.Dll) > 0
                        && ca.Source.Contains("InstallersDll"))
                    {
                        Console.WriteLine("{0}: {1}.{2}", ca.Type.ToString().PadLeft(45), ca.Source, ca.Target);
                        var exists = Exists(ca);
                        Assert.True(exists);
                    }
                }
            }

        }

        public bool Exists(CustomAction_ ca)
        {
            var asm0 = Assembly.LoadFile(@"C:\MagentaWorkspace\broker.github\PART\Source\EventBroker\Output\CprBroker.Installers.dll");
            asm0 = Assembly.LoadFrom("CprBroker.Installers.dll");


            var path = ca.Source == "InstallersDll" ? SolutionDir + @"Output\CprBroker.CustomActions.dll" :
                ca.Source.EndsWith("InstallersDll") ?
                SolutionDir + @"..\EventBroker\Output\CprBroker.Installers.EventBrokerInstallers.dll" :
                "";

            if (string.IsNullOrEmpty(path))
                throw new Exception();

            var asm = Assembly.LoadFile(path);

            if (path.Contains("Event"))
            {
                var asm2 = Assembly.LoadFrom(asm.GetReferencedAssemblies()[2].Name + ".dll");
                var methods0 = asm0.GetTypes().SelectMany(t => t.GetMethods()).ToArray();
            }
            var methods = asm.GetTypes().SelectMany(t => t.GetMethods()).ToArray();
            foreach (var method in methods)
            {
                ParameterInfo[] pars = null;
                if (method.GetCustomAttribute(typeof(CustomActionAttribute)) != null)
                {
                    try
                    {
                        pars = method.GetParameters();
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                    if (method.Name == ca.Target &&
                            pars.Count() == 1 &&
                            pars.First().ParameterType == typeof(Session)
                            )
                        return true;
                }
            }
            return false;
        }
    }
}<commit_msg>Removed unnecessary code<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Deployment.WindowsInstaller.Linq;
using Microsoft.Deployment.WindowsInstaller.Linq.Entities;
using System.Reflection;
using NUnit.Framework;
using System.IO;

namespace CprBroker.Tests.WixInstaller
{
    [TestFixture]
    public class IntegrityTests
    {
        static readonly string SolutionDir = new DirectoryInfo(@"..\..\..\").FullName;

        [Test]
        public void CustomActions_MethodAvailable()
        {
            var path = SolutionDir + @"WixInstaller\bin\Debug\en-US\CprBroker.msi";
            using (var database = new Database(path))
            {
                foreach (CustomAction_ ca in database.AsQueryable().CustomActions)
                {
                    if ((ca.Type & CustomActionTypes.Dll) > 0
                        && ca.Source.Contains("InstallersDll"))
                    {
                        Console.WriteLine("{0}: {1}.{2}", ca.Type.ToString().PadLeft(45), ca.Source, ca.Target);
                        var exists = Exists(ca);
                        Assert.True(exists);
                    }
                }
            }
        }

        public bool Exists(CustomAction_ ca)
        {
            var path = ca.Source == "InstallersDll" ? SolutionDir + @"Output\CprBroker.CustomActions.dll" :
                ca.Source.EndsWith("InstallersDll") ?
                SolutionDir + @"..\EventBroker\Output\CprBroker.Installers.EventBrokerInstallers.dll" :
                "";

            if (string.IsNullOrEmpty(path))
                throw new Exception();

            var asm = Assembly.LoadFile(path);

            if (path.Contains("Event"))
            {
                var asm0 = Assembly.LoadFrom("CprBroker.Installers.dll");
                var methods0 = asm0.GetTypes().SelectMany(t => t.GetMethods()).ToArray();
            }
            var methods = asm.GetTypes().SelectMany(t => t.GetMethods()).ToArray();
            foreach (var method in methods)
            {
                ParameterInfo[] pars = null;
                if (method.GetCustomAttribute(typeof(CustomActionAttribute)) != null)
                {
                    try
                    {
                        pars = method.GetParameters();
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                    if (method.Name == ca.Target &&
                            pars.Count() == 1 &&
                            pars.First().ParameterType == typeof(Session)
                            )
                        return true;
                }
            }
            return false;
        }
    }
}
{'fraction_non_alphanumeric': 0.10818030050083473, 'fraction_numerical': 0.0038397328881469117, 'mean_word_length': 1.4353658536585365, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5214579', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1477, 'n_words': 267}