private string GetExampleFileName(string relativeFileName)
            {
                var rootDirectory = AssemblyDirectoryHelper.GetCurrentDirectory();

                var path = Path.Combine(rootDirectory, "Models", relativeFileName);

                return(path);
            }
    public static TestResult CreateIsolatedAssemblyCopy(string assemblyPath, string config, string[] references, string assemblyName)
    {
        var currentDirectory = AssemblyDirectoryHelper.GetCurrentDirectory();

        var weavingTask = new ModuleWeaver
        {
            Config     = XElement.Parse(config),
            References = string.Join(";", references.Select(r => Path.Combine(currentDirectory, r))),
            ReferenceCopyLocalPaths = references.Select(r => Path.Combine(currentDirectory, r)).ToList(),
        };

        if (!Path.IsPathRooted(assemblyPath))
        {
            assemblyPath = Path.Combine(currentDirectory, assemblyPath);
        }

        return(weavingTask.ExecuteTestRun(assemblyPath,
                                          assemblyName: assemblyName,
                                          ignoreCodes: new [] { "0x80131869" },
                                          runPeVerify: false));
    }
    public AssemblyWeaver(List <string> referenceAssemblyPaths = null)
    {
        if (referenceAssemblyPaths is null)
        {
            referenceAssemblyPaths = new List <string>();
        }

        //Force ref since MSTest is a POS
        var type = typeof(ViewModelBaseTest);

        BeforeAssemblyPath = type.GetAssemblyEx().Location;
        //BeforeAssemblyPath =  Path.GetFullPath("Catel.Fody.TestAssembly.dll");
        AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");

        var oldPdb = Path.ChangeExtension(BeforeAssemblyPath, "pdb");
        var newPdb = Path.ChangeExtension(AfterAssemblyPath, "pdb");

        if (File.Exists(oldPdb))
        {
            File.Copy(oldPdb, newPdb, true);
        }

        Debug.WriteLine("Weaving assembly on-demand from '{0}' to '{1}'", BeforeAssemblyPath, AfterAssemblyPath);

        var assemblyResolver = new TestAssemblyResolver();
        //assemblyResolver.AddSearchDirectory(AssemblyDirectoryHelper.GetCurrentDirectory());
        //foreach (var referenceAssemblyPath in referenceAssemblyPaths)
        //{
        //    var directoryName = Path.GetDirectoryName(referenceAssemblyPath);
        //    assemblyResolver.AddSearchDirectory(directoryName);
        //}

        var metadataResolver = new MetadataResolver(assemblyResolver);

        var readerParameters = new ReaderParameters
        {
            AssemblyResolver = assemblyResolver,
            MetadataResolver = metadataResolver,
            ReadSymbols      = File.Exists(oldPdb),
        };

        using (var moduleDefinition = ModuleDefinition.ReadModule(BeforeAssemblyPath, readerParameters))
        {
            var weavingTask = new ModuleWeaver
            {
                ModuleDefinition   = moduleDefinition,
                AssemblyFilePath   = AfterAssemblyPath,
                AssemblyResolver   = assemblyResolver,
                Config             = XElement.Parse(@"<Weavers><Catel /></Weavers>"),
                AddinDirectoryPath = Path.Combine(AssemblyDirectoryHelper.GetCurrentDirectory(), "..", "..", "Catel.Fody")
            };

            weavingTask.Execute();
            moduleDefinition.Write(AfterAssemblyPath);
        }

//        if (Debugger.IsAttached)
//        {
//#if DEBUG
//            var output = "debug";
//#else
//            var output = "release";
//#endif

//            var targetFile = $@"C:\Source\Catel.Fody\output\{output}\Catel.Fody.Tests\Catel.Fody.TestAssembly2.dll";
//            var targetDirectory = Path.GetDirectoryName(targetFile);
//            Directory.CreateDirectory(targetDirectory);
//            File.Copy(AfterAssemblyPath, targetFile, true);
//        }

        Assembly = Assembly.LoadFile(AfterAssemblyPath);
    }