public static string Weave(string assemblyPath) { var newAssembly = assemblyPath.Replace(".dll", "2.dll"); var oldPdb = assemblyPath.Replace(".dll", ".pdb"); var newPdb = assemblyPath.Replace(".dll", "2.pdb"); File.Copy(assemblyPath, newAssembly, true); File.Copy(oldPdb, newPdb, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(assemblyPath) }; using (var symbolStream = File.OpenRead(newPdb)) { var readerParameters = new ReaderParameters { ReadSymbols = true, SymbolStream = symbolStream, SymbolReaderProvider = new PdbReaderProvider() }; var moduleDefinition = ModuleDefinition.ReadModule(newAssembly, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver }; weavingTask.Execute(); moduleDefinition.Write(newAssembly); return newAssembly; } }
static AssemblyWeaver() { BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); BeforeAssemblyPathSymbols = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); BeforeAssemblyPathSymbols = BeforeAssemblyPathSymbols.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); AfterAssemblyPathSymbols = Path.ChangeExtension(AfterAssemblyPath, "pdb"); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); File.Copy(BeforeAssemblyPathSymbols, AfterAssemblyPathSymbols, true); var assemblyResolver = new MockAssemblyResolver(); var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, new ReaderParameters { ReadSymbols = true }); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, LogInfo = LogInfo, DefineConstants = new[] { "DEBUG" }, // Always testing the debug weaver }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath, new WriterParameters { WriteSymbols = true }); Assembly = Assembly.LoadFile(AfterAssemblyPath); }
static InnerWeaver BuildInnerWeaver(ModuleDefinition moduleDefinition, MockAssemblyResolver resolver) { #pragma warning disable 618 return(new InnerWeaver { Logger = new Mock <ILogger>().Object, AssemblyFilePath = "AssemblyFilePath", ProjectDirectoryPath = "ProjectDirectoryPath", SolutionDirectoryPath = "SolutionDirectoryPath", DocumentationFilePath = "DocumentationFilePath", ReferenceCopyLocalPaths = new List <string> { "CopyRef1", "CopyRef2" }, References = "Ref1;Ref2", ModuleDefinition = moduleDefinition, DefineConstants = new List <string> { "Debug", "Release" }, assemblyResolver = resolver, TypeCache = new TypeCache(resolver.Resolve) }); }
public void VerifyAssembly(string assemblyPath) { Debug.WriteLine("Verifying " + assemblyPath); var cleanAssembly = assemblyPath.Replace(".dll", "2.dll"); var newAssembly = assemblyPath.Replace(".dll", "3.dll"); File.Copy(assemblyPath, cleanAssembly, true); File.Copy(assemblyPath, newAssembly, true); var assemblyResolver = new MockAssemblyResolver(); var moduleDefinition = ModuleDefinition.ReadModule(cleanAssembly); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, }; moduleDefinition.Write(cleanAssembly); moduleDefinition = ModuleDefinition.ReadModule(newAssembly); weavingTask.ModuleDefinition = moduleDefinition; weavingTask.Execute(); moduleDefinition.Write(newAssembly); Verifier.Verify(cleanAssembly, newAssembly); }
public AssemblyWeaver(string assemblyPath, List<string> referenceAssemblyPaths = null) { if (referenceAssemblyPaths == null) { referenceAssemblyPaths = new List<string>(); } assemblyPath = FixAssemblyPath(assemblyPath); var newAssembly = assemblyPath.Replace(".dll", "2.dll"); File.Copy(assemblyPath, newAssembly, true); var assemblyResolver = new MockAssemblyResolver(); foreach (var referenceAssemblyPath in referenceAssemblyPaths) { var directoryName = Path.GetDirectoryName(referenceAssemblyPath); assemblyResolver.AddSearchDirectory(directoryName); } var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver }; var moduleDefinition = ModuleDefinition.ReadModule(newAssembly, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, ReferenceCopyLocalPaths = referenceAssemblyPaths }; weavingTask.Execute(); moduleDefinition.Write(newAssembly); Assembly = Assembly.LoadFrom(newAssembly); }
public Task ValidPropsFromBase() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var resolver = new MockAssemblyResolver(); var innerWeaver = BuildInnerWeaver(moduleDefinition, resolver); innerWeaver.SplitUpReferences(); var weaverEntry = new WeaverEntry { Element = "<foo/>", AssemblyPath = @"c:\FakePath\Assembly.dll" }; var moduleWeaver = new ValidFromBaseModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver); var verifySettings = new VerifySettings(); verifySettings.ModifySerialization(settings => { settings.IgnoreMembersWithType <ModuleDefinition>(); settings.IncludeObsoletes(); }); verifySettings.UniqueForRuntime(); return(VerifyXunit.Verifier.Verify(moduleWeaver, verifySettings)); }
public WithIncludesTests() { beforeAssemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory,@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll")); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "3.dll"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath,new ReaderParameters { AssemblyResolver = assemblyResolver }); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, IncludeNamespaces = new List<string>{"MyNameSpace"}, LogWarning =s => warnings.Add(s) }; weavingTask.Execute(); moduleDefinition.Write(afterAssemblyPath); assembly = Assembly.LoadFile(afterAssemblyPath); }
public void ShouldRegisterTheOverriddenAssemblyResolverInstance() { var mock = new MockAssemblyResolver(); _overrides[typeof(IAssemblyResolver)] = mock; _runtimeServices.Container.Resolve <IAssemblyResolver>().ShouldEqual(mock); }
public IntegrationTests() { beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, new ReaderParameters { AssemblyResolver = assemblyResolver }); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, }; weavingTask.Execute(); moduleDefinition.Write(afterAssemblyPath); assembly = Assembly.LoadFile(afterAssemblyPath); }
public WithIncludesTests() { beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "3.dll"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, new ReaderParameters { AssemblyResolver = assemblyResolver }); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, IncludeNamespaces = new List <string> { "MyNameSpace" }, LogWarning = s => warnings.Add(s) }; weavingTask.Execute(); moduleDefinition.Write(afterAssemblyPath); assembly = Assembly.LoadFile(afterAssemblyPath); }
public void ValidProps() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var resolver = new MockAssemblyResolver(); var innerWeaver = new InnerWeaver { Logger = new Mock <ILogger>().Object, AssemblyFilePath = "AssemblyFilePath", ProjectDirectoryPath = "ProjectDirectoryPath", SolutionDirectoryPath = "SolutionDirectoryPath", ReferenceDictionary = new Dictionary <string, string> { { "Ref1;Ref2", "Path1" } }, ReferenceCopyLocalPaths = new List <string> { "CopyRef1", "CopyRef2" }, References = "Ref1;Ref2", ModuleDefinition = moduleDefinition, DefineConstants = new List <string> { "Debug", "Release" }, assemblyResolver = resolver }; var weaverEntry = new WeaverEntry { Element = "<foo/>", AssemblyPath = @"c:\FakePath\Assembly.dll" }; var moduleWeaver = new ValidModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver, typeof(ValidModuleWeaver).BuildDelegateHolder()); Assert.IsNotNull(moduleWeaver.LogDebug); Assert.IsNotNull(moduleWeaver.LogInfo); Assert.IsNotNull(moduleWeaver.LogWarning); Assert.IsNotNull(moduleWeaver.LogWarningPoint); Assert.IsNotNull(moduleWeaver.LogError); Assert.IsNotNull(moduleWeaver.LogErrorPoint); Assert.IsNotNull(moduleWeaver.LogMessage); Assert.AreEqual("Ref1;Ref2", moduleWeaver.References); Assert.AreEqual("CopyRef1", moduleWeaver.ReferenceCopyLocalPaths[0]); Assert.AreEqual("CopyRef2", moduleWeaver.ReferenceCopyLocalPaths[1]); Assert.AreEqual("Debug", moduleWeaver.DefineConstants[0]); Assert.AreEqual("Release", moduleWeaver.DefineConstants[1]); // Assert.IsNotEmpty(moduleWeaver.References); Assert.AreEqual(moduleDefinition, moduleWeaver.ModuleDefinition); Assert.AreEqual(resolver, moduleWeaver.AssemblyResolver); Assert.AreEqual(@"c:\FakePath", moduleWeaver.AddinDirectoryPath); Assert.AreEqual("AssemblyFilePath", moduleWeaver.AssemblyFilePath); Assert.AreEqual("ProjectDirectoryPath", moduleWeaver.ProjectDirectoryPath); Assert.AreEqual("SolutionDirectoryPath", moduleWeaver.SolutionDirectoryPath); }
public IntegrationTests() { beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath,new ReaderParameters { AssemblyResolver = assemblyResolver }); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, }; weavingTask.Execute(); moduleDefinition.Write(afterAssemblyPath); assembly = Assembly.LoadFile(afterAssemblyPath); }
public static string Weave(string assemblyPath) { var newAssembly = assemblyPath.Replace(".dll", "2.dll"); var oldPdb = assemblyPath.Replace(".dll", ".pdb"); var newPdb = assemblyPath.Replace(".dll", "2.pdb"); File.Copy(assemblyPath, newAssembly, true); File.Copy(oldPdb, newPdb, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(assemblyPath) }; using (var symbolStream = File.OpenRead(newPdb)) { var readerParameters = new ReaderParameters { ReadSymbols = true, SymbolStream = symbolStream, SymbolReaderProvider = new PdbReaderProvider(), AssemblyResolver = assemblyResolver }; var moduleDefinition = ModuleDefinition.ReadModule(newAssembly, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver }; weavingTask.Execute(); moduleDefinition.Write(newAssembly); return(newAssembly); } }
public void VerifyAssembly(string assemblyPath) { Debug.WriteLine("Verifying " + assemblyPath); var cleanAssembly = assemblyPath.Replace(".dll", "2.dll"); var newAssembly = assemblyPath.Replace(".dll", "3.dll"); File.Copy(assemblyPath, cleanAssembly, true); File.Copy(assemblyPath, newAssembly, true); var assemblyResolver = new MockAssemblyResolver(); var moduleDefinition = ModuleDefinition.ReadModule(cleanAssembly); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, }; moduleDefinition.Write(cleanAssembly); moduleDefinition = ModuleDefinition.ReadModule(newAssembly); weavingTask.ModuleDefinition = moduleDefinition; weavingTask.Execute(); moduleDefinition.Write(newAssembly); Verifier.Verify(cleanAssembly, newAssembly); }
static AssemblyWeaver() { TestListener = new TestTraceListener(); Debug.Listeners.Clear(); Debug.Listeners.Add(TestListener); BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); beforePdbPath = beforePdbPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb"); AfterAssembly2Path = BeforeAssemblyPath.Replace(".dll", "3.dll"); var afterPdb2Path = beforePdbPath.Replace(".pdb", "3.pdb"); Assembly = WeaveAssembly(AfterAssemblyPath, beforePdbPath, afterPdbPath, moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, DefineConstants = new List<string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); Assembly2 = WeaveAssembly(AfterAssembly2Path, beforePdbPath, afterPdb2Path, moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { Config = new XElement("NullGuard", new XAttribute("IncludeDebugAssert", false), new XAttribute("ExcludeRegex", "^ClassToExclude$")), ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, DefineConstants = new List<string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); }
static AssemblyWeaver() { TestListener = new TestTraceListener(); Debug.Listeners.Clear(); Debug.Listeners.Add(TestListener); BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); beforePdbPath = beforePdbPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb"); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); if (File.Exists(beforePdbPath)) { File.Copy(beforePdbPath, afterPdbPath, true); } var assemblyResolver = new MockAssemblyResolver(); var readerParameters = new ReaderParameters(); var writerParameters = new WriterParameters(); if (File.Exists(afterPdbPath)) { readerParameters.ReadSymbols = true; writerParameters.WriteSymbols = true; } var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, DefineConstants = new List <string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath, writerParameters); Assembly = Assembly.LoadFile(AfterAssemblyPath); }
private static Assembly WeaveAssembly(string testDataAssemblyPath) { var outputDirectory = Path.GetDirectoryName(testDataAssemblyPath); IAssemblyResolver assemblyResolver; if (testDataAssemblyPath.IndexOf("NoRef", StringComparison.OrdinalIgnoreCase) > -1) { assemblyResolver = new MockAssemblyResolver(); } else { assemblyResolver = new JetBrains.ReSharper.Checker.Tests.MockAssemblyResolver(outputDirectory); } var targetAssemblyPath = Path.ChangeExtension(testDataAssemblyPath, "weaved.dll"); File.Copy(testDataAssemblyPath, targetAssemblyPath, overwrite: true); var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver }; var writerParameters = new WriterParameters(); var testDataSymbolsPath = Path.ChangeExtension(testDataAssemblyPath, "pdb"); if (File.Exists(testDataSymbolsPath)) { readerParameters.SymbolReaderProvider = new PdbReaderProvider(); readerParameters.ReadSymbols = true; writerParameters.SymbolWriterProvider = new PdbWriterProvider(); writerParameters.WriteSymbols = true; File.Copy(testDataSymbolsPath, Path.ChangeExtension(testDataSymbolsPath, "weaved.pdb"), overwrite: true); } var moduleDefinition = ModuleDefinition.ReadModule(targetAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver }; weavingTask.Execute(); moduleDefinition.Write(targetAssemblyPath, writerParameters); return(Assembly.LoadFile(targetAssemblyPath)); }
static AssemblyWeaver() { TestListener = new TestTraceListener(); Debug.Listeners.Clear(); Debug.Listeners.Add(TestListener); BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); beforePdbPath = beforePdbPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb"); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); if (File.Exists(beforePdbPath)) File.Copy(beforePdbPath, afterPdbPath, true); var assemblyResolver = new MockAssemblyResolver(); var readerParameters = new ReaderParameters(); var writerParameters = new WriterParameters(); if (File.Exists(afterPdbPath)) { readerParameters.ReadSymbols = true; writerParameters.WriteSymbols = true; } var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, DefineConstants = new List<string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath, writerParameters); Assembly = Assembly.LoadFile(AfterAssemblyPath); }
static AssemblyWeaver() { BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); beforePdbPath = beforePdbPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb"); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); if (File.Exists(beforePdbPath)) { File.Copy(beforePdbPath, afterPdbPath, true); } var assemblyResolver = new MockAssemblyResolver(); var readerParameters = new ReaderParameters(); var writerParameters = new WriterParameters(); if (File.Exists(afterPdbPath)) { readerParameters.ReadSymbols = true; writerParameters.WriteSymbols = true; } var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarning = LogWarning, LogError = LogError, DefineConstants = new[] { "DEBUG" }, // Always testing the debug weaver Config = XElement.Parse("<Disguise EncryptStrings=\"Xor\" RenameMethod=\"Readable\" />") }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath, writerParameters); Assembly = Assembly.LoadFile(AfterAssemblyPath); }
public AssemblyWeaver(string assemblyPath, List <string> referenceAssemblyPaths = null) { if (referenceAssemblyPaths == null) { referenceAssemblyPaths = new List <string>(); } assemblyPath = FixAssemblyPath(assemblyPath); AfterAssemblyPath = assemblyPath.Replace(".dll", "2.dll"); File.Copy(assemblyPath, AfterAssemblyPath, true); var oldPdb = Path.ChangeExtension(assemblyPath, "pdb"); var newPdb = Path.ChangeExtension(AfterAssemblyPath, "pdb"); File.Copy(oldPdb, newPdb, true); var assemblyResolver = new MockAssemblyResolver(); foreach (var referenceAssemblyPath in referenceAssemblyPaths) { var directoryName = Path.GetDirectoryName(referenceAssemblyPath); assemblyResolver.AddSearchDirectory(directoryName); } var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver, ReadSymbols = true, }; using (var moduleDefinition = ModuleDefinition.ReadModule(assemblyPath, readerParameters)) { var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, ReferenceCopyLocalPaths = referenceAssemblyPaths }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath); } Assembly = Assembly.LoadFrom(AfterAssemblyPath); }
static AssemblyWeaver() { //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"); Debug.WriteLine("Weaving assembly on-demand from '{0}' to '{1}'", BeforeAssemblyPath, AfterAssemblyPath); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); var assemblyResolver = new MockAssemblyResolver(); var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, }; 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); }
static AssemblyWeaver() { //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"); Debug.WriteLine("Weaving assembly on-demand from '{0}' to '{1}'", BeforeAssemblyPath, AfterAssemblyPath); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); var assemblyResolver = new MockAssemblyResolver(); var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = LogError, }; 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); }
public ModuleWeaverTestHelper(string inputAssembly) { BeforeAssemblyPath = Path.GetFullPath(inputAssembly); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); var oldPdb = BeforeAssemblyPath.Replace(".dll", ".pdb"); var newPdb = BeforeAssemblyPath.Replace(".dll", "2.pdb"); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); File.Copy(oldPdb, newPdb, true); Errors = new List <string>(); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(BeforeAssemblyPath) }; using (var symbolStream = File.OpenRead(newPdb)) { var readerParameters = new ReaderParameters { ReadSymbols = true, SymbolStream = symbolStream, SymbolReaderProvider = new PdbReaderProvider() }; var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = s => Errors.Add(s), }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath); } Assembly = Assembly.LoadFile(AfterAssemblyPath); }
public ModuleWeaverTestHelper(string inputAssembly) { BeforeAssemblyPath = Path.GetFullPath(inputAssembly); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); var oldPdb = BeforeAssemblyPath.Replace(".dll", ".pdb"); var newPdb = BeforeAssemblyPath.Replace(".dll", "2.pdb"); File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); File.Copy(oldPdb, newPdb, true); Errors = new List<string>(); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(BeforeAssemblyPath) }; using (var symbolStream = File.OpenRead(newPdb)) { var readerParameters = new ReaderParameters { ReadSymbols = true, SymbolStream = symbolStream, SymbolReaderProvider = new PdbReaderProvider() }; var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogError = s => Errors.Add(s), }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath); } Assembly = Assembly.LoadFile(AfterAssemblyPath); }
public void ValidPropsFromBase() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var resolver = new MockAssemblyResolver(); var innerWeaver = BuildInnerWeaver(moduleDefinition, resolver); innerWeaver.SplitUpReferences(); var weaverEntry = new WeaverEntry { Element = "<foo/>", AssemblyPath = @"c:\FakePath\Assembly.dll" }; var moduleWeaver = new ValidFromBaseModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver); SerializerBuilder.IgnoreMembersWithType <ModuleDefinition>(); ObjectApprover.VerifyWithJson(moduleWeaver); }
public void ValidProps() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var resolver = new MockAssemblyResolver(); var innerWeaver = BuildInnerWeaver(moduleDefinition, resolver); innerWeaver.SplitUpReferences(); var weaverEntry = new WeaverEntry { Element = "<foo/>", AssemblyPath = @"c:\FakePath\Assembly.dll" }; var moduleWeaver = new ValidModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver, typeof(ValidModuleWeaver).BuildDelegateHolder()); ValidateProps(moduleWeaver, moduleDefinition); Assert.Equal(resolver, moduleWeaver.AssemblyResolver); }
public ModuleWeaverTests() { var beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll"); var oldpdb = beforeAssemblyPath.Replace(".dll", ".pdb"); var newpdb = beforeAssemblyPath.Replace(".dll", "2.pdb"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); File.Copy(oldpdb, newpdb, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; using (var symbolStream = File.OpenRead(newpdb)) { var readerParameters = new ReaderParameters { ReadSymbols = true, SymbolStream = symbolStream, SymbolReaderProvider = new PdbReaderProvider() }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, ProjectDirectoryPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess") }; weavingTask.Execute(); moduleDefinition.Write(afterAssemblyPath); } assembly = Assembly.LoadFile(afterAssemblyPath); }
public ModuleWeaverTests() { var beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll"); var oldpdb = beforeAssemblyPath.Replace(".dll", ".pdb"); var newpdb = beforeAssemblyPath.Replace(".dll", "2.pdb"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); File.Copy(oldpdb, newpdb, true); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; using (var symbolStream = File.OpenRead(newpdb)) { var readerParameters = new ReaderParameters { ReadSymbols = true, SymbolStream = symbolStream, SymbolReaderProvider = new PdbReaderProvider() }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, ProjectDirectoryPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess") }; weavingTask.Execute(); moduleDefinition.Write(afterAssemblyPath); } assembly = Assembly.LoadFile(afterAssemblyPath); }
public void ValidPropsFromBase() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var resolver = new MockAssemblyResolver(); var innerWeaver = BuildInnerWeaver(moduleDefinition, resolver); innerWeaver.SplitUpReferences(); var weaverEntry = new WeaverEntry { Element = "<foo/>", AssemblyPath = @"c:\FakePath\Assembly.dll" }; var moduleWeaver = new ValidFromBaseModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver); ValidateProps(moduleWeaver, moduleDefinition); Assert.NotNull(moduleWeaver.FindType); Assert.NotNull(moduleWeaver.TryFindType); Assert.NotNull(moduleWeaver.ResolveAssembly); }
static AssemblyWeaver() { TestListener = new TestTraceListener(); Debug.Listeners.Clear(); Debug.Listeners.Add(TestListener); BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); MonoBeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcessMono\bin\Debug\AssemblyToProcessMono.dll"); var monoBeforeMdbPath = MonoBeforeAssemblyPath + ".mdb"; #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); beforePdbPath = beforePdbPath.Replace("Debug", "Release"); MonoBeforeAssemblyPath = MonoBeforeAssemblyPath.Replace("Debug", "Release"); monoBeforeMdbPath = monoBeforeMdbPath.Replace("Debug", "Release"); #endif AfterAssemblyPaths = new [] { BeforeAssemblyPath.Replace(".dll", "2.dll"), BeforeAssemblyPath.Replace(".dll", "3.dll"), MonoBeforeAssemblyPath.Replace(".dll", "2.dll") }; AfterAssemblySymbolPaths = new [] { beforePdbPath.Replace(".pdb", "2.pdb"), beforePdbPath.Replace(".pdb", "3.pdb"), monoBeforeMdbPath.Replace(".mdb", "2.mdb") }; Assemblies = new Assembly[3]; Assemblies[0] = WeaveAssembly(BeforeAssemblyPath, AfterAssemblyPaths[0], beforePdbPath, AfterAssemblySymbolPaths[0], moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List <string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); Assemblies[1] = WeaveAssembly(BeforeAssemblyPath, AfterAssemblyPaths[1], beforePdbPath, AfterAssemblySymbolPaths[1], moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { Config = new XElement("NullGuard", new XAttribute("IncludeDebugAssert", false), new XAttribute("ExcludeRegex", "^ClassToExclude$")), ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List <string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); Assemblies[2] = WeaveAssembly(MonoBeforeAssemblyPath, AfterAssemblyPaths[2], monoBeforeMdbPath, AfterAssemblySymbolPaths[2], moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List <string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); }
static AssemblyWeaver() { TestListener = new TestTraceListener(); Debug.Listeners.Clear(); Debug.Listeners.Add(TestListener); BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); MonoBeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcessMono\bin\Debug\AssemblyToProcessMono.dll"); var monoBeforeMdbPath = MonoBeforeAssemblyPath + ".mdb"; #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); beforePdbPath = beforePdbPath.Replace("Debug", "Release"); MonoBeforeAssemblyPath = MonoBeforeAssemblyPath.Replace("Debug", "Release"); monoBeforeMdbPath = monoBeforeMdbPath.Replace("Debug", "Release"); #endif AfterAssemblyPaths = new [] { BeforeAssemblyPath.Replace(".dll", "2.dll"), BeforeAssemblyPath.Replace(".dll", "3.dll"), MonoBeforeAssemblyPath.Replace(".dll", "2.dll") }; AfterAssemblySymbolPaths = new [] { beforePdbPath.Replace(".pdb", "2.pdb"), beforePdbPath.Replace(".pdb", "3.pdb"), monoBeforeMdbPath.Replace(".mdb", "2.mdb") }; Assemblies = new Assembly[3]; Assemblies[0] = WeaveAssembly(BeforeAssemblyPath, AfterAssemblyPaths[0], beforePdbPath, AfterAssemblySymbolPaths[0], moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List<string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); Assemblies[1] = WeaveAssembly(BeforeAssemblyPath, AfterAssemblyPaths[1], beforePdbPath, AfterAssemblySymbolPaths[1], moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { Config = new XElement("NullGuard", new XAttribute("IncludeDebugAssert", false), new XAttribute("ExcludeRegex", "^ClassToExclude$")), ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List<string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); Assemblies[2] = WeaveAssembly(MonoBeforeAssemblyPath, AfterAssemblyPaths[2], monoBeforeMdbPath, AfterAssemblySymbolPaths[2], moduleDefinition => { var assemblyResolver = new MockAssemblyResolver(); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List<string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); }); }
static AssemblyWeaver() { var testDirectory = TestContext.CurrentContext.TestDirectory; BeforeAssemblyPath = Path.GetFullPath(Path.Combine(testDirectory, @"..\..\..\..\AssemblyToProcess\bin\Debug\net452\AssemblyToProcess.dll")); BeforeSymbolPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); #if (!DEBUG) BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release"); BeforeSymbolPath = BeforeSymbolPath.Replace("Debug", "Release"); #endif AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); AfterSymbolPath = BeforeSymbolPath.Replace(".pdb", "2.pdb"); if (File.Exists(AfterAssemblyPath)) { File.Delete(AfterAssemblyPath); } if (File.Exists(AfterSymbolPath)) { File.Delete(AfterSymbolPath); } var assemblyResolver = new MockAssemblyResolver(); var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver }; var writerParameters = new WriterParameters(); if (File.Exists(BeforeSymbolPath)) { readerParameters.ReadSymbols = true; readerParameters.SymbolReaderProvider = new PdbReaderProvider(); readerParameters.SymbolStream = new FileStream(BeforeSymbolPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); writerParameters.WriteSymbols = true; writerParameters.SymbolWriterProvider = new PdbWriterProvider(); } var moduleDefinition = ModuleDefinition.ReadModule(BeforeAssemblyPath, readerParameters); var weavingTask = new ModuleWeaver { Config = new XElement("NullGuard", new XAttribute("IncludeDebugAssert", false), new XAttribute("ExcludeRegex", "^ClassToExclude$")), ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, LogInfo = LogInfo, LogWarn = LogWarn, LogError = LogError, DefineConstants = new List <string> { "DEBUG" } // Always testing the debug weaver }; weavingTask.Execute(); moduleDefinition.Write(AfterAssemblyPath, writerParameters); Assembly = Assembly.LoadFile(AfterAssemblyPath); }