public void WeavedAssembly_ShouldContainWeavedInfo() { using (var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock <ILogger>().Object, AssemblyFilePath = tempFilePath, DefineConstants = new List <string> { "Debug", "Release" }, Weavers = new List <WeaverEntry> { new WeaverEntry { TypeName = "FakeModuleWeaver", AssemblyName = "FodyIsolated.Tests", AssemblyPath = $@"{AssemblyLocation.CurrentDirectory}\Tests.dll" } } }) { innerWeaver.Execute(); } using (var readModule = ModuleDefinition.ReadModule(tempFilePath)) { var type = readModule.Types .Single(_ => _.Name == "ProcessedByFody"); var condition = type.Fields.Any(f => f.Name == "FodyIsolatedTests"); Assert.True(condition); } }
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 void ValidProps() { var moduleWeaver = new ValidModuleWeaver(); var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var assemblyResolver = new Mock<IAssemblyResolver>().Object; var innerWeaver = new InnerWeaver { AssemblyPath = "AssemblyPath" }; var moduleWeaverRunner = new WeaverInitialiser { ModuleDefinition = moduleDefinition, Logger = new Mock<ILogger>().Object, AssemblyResolver = assemblyResolver, InnerWeaver = innerWeaver }; var weaverEntry = new WeaverEntry {Element = "<foo/>"}; moduleWeaverRunner.SetProperties(weaverEntry, moduleWeaver); Assert.IsNotNull(moduleWeaver.LogInfo); Assert.IsNotNull(moduleWeaver.LogWarning); Assert.IsNotNull(moduleWeaver.LogWarningPoint); Assert.IsNotNull(moduleWeaver.LogError); Assert.IsNotNull(moduleWeaver.LogErrorPoint); Assert.AreEqual(moduleDefinition, moduleWeaver.ModuleDefinition); Assert.AreEqual(assemblyResolver, moduleWeaver.AssemblyResolver); Assert.AreEqual("AssemblyPath", moduleWeaver.AssemblyPath); }
public void WeavedAssembly_ShouldContainWeavedInfo() { var moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock<ILogger>().Object, AssemblyFilePath = TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll", ModuleDefinition = moduleDefinition, DefineConstants = new List<string> { "Debug", "Release" }, Weavers = new List<WeaverEntry> { new WeaverEntry { TypeName = "ModuleWeaver", AssemblyName = "Sample.Fody", AssemblyPath = TestContext.CurrentContext.TestDirectory + "\\Sample.Fody.dll" } } }; innerWeaver.Execute(); moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); Assert.IsTrue(moduleDefinition.Types.Count(_ => _.Name == "FodyWeavingResults") >= 1); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").HasCustomAttributes); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").Fields.Any(f => f.Name == "SampleFody")); }
public void ValidProps() { var moduleWeaver = new ValidModuleWeaver(); var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var assemblyResolver = new Mock <IAssemblyResolver>().Object; var innerWeaver = new InnerWeaver { AssemblyPath = "AssemblyPath" }; var moduleWeaverRunner = new WeaverInitialiser { ModuleDefinition = moduleDefinition, Logger = new Mock <ILogger>().Object, AssemblyResolver = assemblyResolver, InnerWeaver = innerWeaver }; var weaverEntry = new WeaverEntry { Element = "<foo/>" }; moduleWeaverRunner.SetProperties(weaverEntry, moduleWeaver); Assert.IsNotNull(moduleWeaver.LogInfo); Assert.IsNotNull(moduleWeaver.LogWarning); Assert.IsNotNull(moduleWeaver.LogWarningPoint); Assert.IsNotNull(moduleWeaver.LogError); Assert.IsNotNull(moduleWeaver.LogErrorPoint); Assert.AreEqual(moduleDefinition, moduleWeaver.ModuleDefinition); Assert.AreEqual(assemblyResolver, moduleWeaver.AssemblyResolver); Assert.AreEqual("AssemblyPath", moduleWeaver.AssemblyPath); }
public void ValidProps() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); var innerWeaver = new InnerWeaver { AssemblyFilePath = "AssemblyFilePath", SolutionDirectoryPath = "SolutionDirectoryPath", ReferenceDictionary = new Dictionary<string, string> { { "Ref1;Ref2","Path1" } }, ModuleDefinition = moduleDefinition, }; var weaverEntry = new WeaverEntry { Element = "<foo/>", AssemblyPath = @"c:\FakePath\Assembly.dll" }; var moduleWeaver = new ValidModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver); Assert.IsNotNull(moduleWeaver.LogInfo); Assert.IsNotNull(moduleWeaver.LogWarning); Assert.IsNotNull(moduleWeaver.LogWarningPoint); Assert.IsNotNull(moduleWeaver.LogError); Assert.IsNotNull(moduleWeaver.LogErrorPoint); // Assert.IsNotEmpty(moduleWeaver.References); Assert.AreEqual(moduleDefinition, moduleWeaver.ModuleDefinition); Assert.AreEqual(innerWeaver, moduleWeaver.AssemblyResolver); Assert.AreEqual(@"c:\FakePath",moduleWeaver.AddinDirectoryPath); Assert.AreEqual("AssemblyFilePath", moduleWeaver.AssemblyFilePath); Assert.AreEqual("SolutionDirectoryPath", moduleWeaver.SolutionDirectoryPath); }
public void WeavedAssembly_ShouldContainWeavedInfo() { var moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock <ILogger>().Object, AssemblyFilePath = TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll", ModuleDefinition = moduleDefinition, DefineConstants = new List <string> { "Debug", "Release" }, Weavers = new List <WeaverEntry> { new WeaverEntry { TypeName = "ModuleWeaver", AssemblyName = "Sample.Fody", AssemblyPath = TestContext.CurrentContext.TestDirectory + "\\Sample.Fody.dll" } } }; innerWeaver.Execute(); moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); Assert.IsTrue(moduleDefinition.Types.Count(_ => _.Name == "FodyWeavingResults") >= 1); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").HasCustomAttributes); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").Fields.Any(f => f.Name == "SampleFody")); }
public void WithSymbols() { var assemblyPath = Path.Combine(Environment.CurrentDirectory, "DummyAssembly.dll"); var result = InnerWeaver.ReadModule(assemblyPath, new AssemblyResolver(new MockBuildLogger(), Enumerable.Empty <string>())); Assert.NotNull(result.module); Assert.True(result.hasSymbols); }
private void WeaveImpl(List <WeaverEntry> entries, string references) { var innerWeaver = new InnerWeaver() { Logger = new Logger(), AssemblyFilePath = _assemblyPath, Weavers = entries, References = references }; innerWeaver.Execute(); }
void Test(string?privateAssets, string?includeAssets, string expectedErrors) { var config = new WeaverEntry { AssemblyPath = "Weaver.Fody.dll", PrivateAssets = privateAssets, IncludeAssets = includeAssets }; var errors = InnerWeaver.GetPackageReferenceValidationErrors(config); Assert.Equal(expectedErrors, string.Join("|", errors)); }
public void ValidProps() { var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); 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"} }; 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(innerWeaver, moduleWeaver.AssemblyResolver); Assert.AreEqual(@"c:\FakePath", moduleWeaver.AddinDirectoryPath); Assert.AreEqual("AssemblyFilePath", moduleWeaver.AssemblyFilePath); Assert.AreEqual("ProjectDirectoryPath", moduleWeaver.ProjectDirectoryPath); Assert.AreEqual("SolutionDirectoryPath", moduleWeaver.SolutionDirectoryPath); }
static void Main(string[] args) { var logger = new ConsoleLogger(); CommandLineArguments clargs; try { clargs = args.As <CommandLineArguments>(); } catch (ArgumentException ex) { logger.LogException(ex); Console.WriteLine(); Console.WriteLine(AppArgs.HelpFor <CommandLineArguments>()); return; } var weavers = FindWeavers(clargs); using (IInnerWeaver innerWeaver = new InnerWeaver()) { // Default innerWeaver.KeyFilePath = ""; innerWeaver.SignAssembly = false; // Not from args innerWeaver.Logger = logger; innerWeaver.Weavers = weavers.ToList(); // From args innerWeaver.AssemblyFilePath = clargs.AssemblyFilePath; innerWeaver.References = clargs.References; innerWeaver.SolutionDirectoryPath = clargs.SolutionDirectory; innerWeaver.IntermediateDirectoryPath = Path.GetDirectoryName(clargs.AssemblyFilePath); innerWeaver.DefineConstants = clargs.DefineConstants.Split(';').ToList(); innerWeaver.ProjectDirectoryPath = clargs.ProjectDirectoryPath; innerWeaver.ReferenceCopyLocalPaths = clargs.ReferenceCopyLocalPaths?.Split(';').ToList(); innerWeaver.Execute(); } }
static void Main(string[] args) { var logger = new ConsoleLogger(); CommandLineArguments clargs; try { clargs = args.As<CommandLineArguments>(); } catch (ArgumentException ex) { logger.LogException(ex); Console.WriteLine(); Console.WriteLine(AppArgs.HelpFor<CommandLineArguments>()); return; } var weavers = FindWeavers(clargs); using (IInnerWeaver innerWeaver = new InnerWeaver()) { // Default innerWeaver.KeyFilePath = ""; innerWeaver.SignAssembly = false; // Not from args innerWeaver.Logger = logger; innerWeaver.Weavers = weavers.ToList(); // From args innerWeaver.AssemblyFilePath = clargs.AssemblyFilePath; innerWeaver.References = clargs.References; innerWeaver.SolutionDirectoryPath = clargs.SolutionDirectory; innerWeaver.IntermediateDirectoryPath = Path.GetDirectoryName(clargs.AssemblyFilePath); innerWeaver.DefineConstants = clargs.DefineConstants.Split(';').ToList(); innerWeaver.ProjectDirectoryPath = clargs.ProjectDirectoryPath; innerWeaver.ReferenceCopyLocalPaths = clargs.ReferenceCopyLocalPaths?.Split(';').ToList(); innerWeaver.Execute(); } }
public void WeavedAssembly_ShouldContainWeavedInfo() { var assemblyFilePath = $@"{TestContext.CurrentContext.TestDirectory}\DummyAssembly.dll"; var pdbFilePath = $@"{TestContext.CurrentContext.TestDirectory}\DummyAssembly.pdb"; var tempFilePath = $@"{TestContext.CurrentContext.TestDirectory}\Temp.dll"; var tempPdbFilePath = $@"{TestContext.CurrentContext.TestDirectory}\Temp.pdb"; File.Copy(assemblyFilePath, tempFilePath, true); File.Copy(pdbFilePath, tempPdbFilePath, true); var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock <ILogger>().Object, AssemblyFilePath = tempFilePath, DefineConstants = new List <string> { "Debug", "Release" }, Weavers = new List <WeaverEntry> { new WeaverEntry { TypeName = "FakeModuleWeaver", AssemblyName = "FodyIsolated.Tests", AssemblyPath = TestContext.CurrentContext.TestDirectory + "\\FodyIsolated.Tests.dll" } } }; innerWeaver.Execute(); using (var readModule = ModuleDefinition.ReadModule(tempFilePath)) { var type = readModule.Types .Single(_ => _.Name == "ProcessedByFody"); Assert.IsTrue(type.Fields.Any(f => f.Name == "FodyIsolatedTests")); } }
public Task <bool> RunAsync( string assemblyFilePath, IEnumerable <string> references, List <string> defineConstants, bool isDebugBuild, CancellationToken cancellationToken = default) { if (_weaverEntries == null) { throw new NotConfiguredException(); } return(Task.Run( () => { string assemblyFileName = Path.GetFileNameWithoutExtension(assemblyFilePath); if (assemblyFileName != null && _assemblyRegexes.TrueForAll(regex => !regex.IsMatch(assemblyFileName))) { _logForwarder.LogInfo( $"Not processing assembly '{assemblyFilePath}' because none of the configured" + " regular expressions match the assembly name."); return false; } if (!File.Exists(assemblyFilePath)) { _logForwarder.LogInfo( $"Not processing assembly '{assemblyFilePath}' because the file doesn't exist."); return false; } if (IsAssemblyProcessed(assemblyFilePath)) { _logForwarder.LogInfo( $"Not processing assembly '{assemblyFilePath}' because it has already been processed."); return false; } InnerWeaver innerWeaver = new InnerWeaver { AssemblyFilePath = assemblyFilePath, References = string.Join(";", references), ReferenceCopyLocalPaths = new List <string>(), DefineConstants = defineConstants, Logger = _logForwarder, Weavers = _weaverEntries, DebugSymbols = isDebugBuild ? DebugSymbolsType.External : DebugSymbolsType.None }; CancellationTokenRegistration cancellationTokenRegistration = // ReSharper disable once AccessToDisposedClosure cancellationToken.Register(() => innerWeaver.Cancel()); try { innerWeaver.Execute(); } finally { cancellationTokenRegistration.Dispose(); innerWeaver.Dispose(); } return true; }, cancellationToken)); }
public AssemblyReferenceFinder(InnerWeaver innerWeaver, ILogger logger) { this.innerWeaver = innerWeaver; this.logger = logger; }
public void NoExecute() { var moduleWeaverRunner = new InnerWeaver { Logger = new Mock<ILogger>().Object }; moduleWeaverRunner.RunWeaver("sdf"); }
public void Execute() { var moduleWeaver = new ValidModuleWeaver(); var moduleWeaverRunner = new InnerWeaver { Logger = new Mock<ILogger>().Object }; moduleWeaverRunner.RunWeaver(moduleWeaver); }
public void BadExecute() { var moduleWeaver = new BadExecuteWithParamsModuleWeaver(); var moduleWeaverRunner = new InnerWeaver { Logger = new Mock<ILogger>().Object }; moduleWeaverRunner.RunWeaver( moduleWeaver); }