public void InitializeThrowsBadImageExceptionOnInvalidInputImage() { CecilAnalyzerConfiguration configuration = CecilAnalyzerConfiguration.CreateDefaultConfiguration(string.Empty); ILanguageModelAccessor langModelAccessor = new LanguageModelAccessorMock(); AssemblyElement ae = ((IILAnalyzer) new CecilILAnalyzer(configuration, langModelAccessor)).ExtractAllTypes(CreateFullPath("InvalidImage.exe")); }
public void AnalyzerThrowsExceptionIfFileDoesntExists() { CecilAnalyzerConfiguration configuration = CecilAnalyzerConfiguration.CreateDefaultConfiguration(string.Empty); ILanguageModelAccessor langModelAccessor = new LanguageModelAccessorMock(); AssemblyElement ae = ((IILAnalyzer) new CecilILAnalyzer(configuration, langModelAccessor)).ExtractAllTypes("c:\\this_file_doesnt_exist"); }
public void TestTargetMustReturnCorrectAssembly() { // set up model LanguageModelAccessorMock model = new LanguageModelAccessorMock(); // create configuration CecilAnalyzerConfiguration configuration = CecilAnalyzerConfiguration.CreateDefaultConfiguration(string.Empty); // do weaving IILAnalyzer analyzer = DIHelper.CreateObject <CecilILAnalyzer>(CreateTestContainer(model, configuration)); AssemblyElement ae = analyzer.ExtractAllTypes(CreateFullPath("TestTarget.exe")); Assert.IsNotNull(ae, "Could not create an AssemblyElement."); Assert.IsFalse(string.IsNullOrEmpty(ae.FileName), "Filename is not set."); Assert.IsFalse(string.IsNullOrEmpty(ae.Name), "Assembly name is not set."); Assert.IsFalse(ae.Timestamp == 0, "Timestamp is not set."); Assert.IsTrue(ae.TypeElements.Length > 0, "TypeElements were not retrieved."); Assert.IsTrue(ae.TypeElements.Length == 1, "Found {0} TypeElements, expecting 1.", ae.TypeElements.Length); TypeElement te = ae.TypeElements[0]; Assert.IsNotNull(te, "Could not set the TypeElement."); Assert.IsFalse(string.IsNullOrEmpty(te.BaseType), "BaseType has not been stored."); Assert.IsFalse(string.IsNullOrEmpty(te.FullName), "FullName has not been stored."); Assert.IsFalse(string.IsNullOrEmpty(te.Name), "Name has not been stored."); Assert.IsFalse(string.IsNullOrEmpty(te.Namespace), "Namespace has not been stored."); Assert.IsTrue(te.MethodElements.Length == 2, "Methods not stored in the TypeElement. {0} methods found", te.MethodElements.Length); MethodElement me = te.MethodElements[0]; Assert.IsNotNull(me, "Could not set the methodElement"); Assert.IsFalse(string.IsNullOrEmpty(me.Name), "Name has not been stored."); Assert.IsFalse(string.IsNullOrEmpty(me.ReturnType), "Returntype has not been stored."); Assert.IsFalse(string.IsNullOrEmpty(me.Signature), "Signature has not been stored."); } // TestTargetMustReturnAssembly()
/// <summary> /// Creates the test container. /// </summary> /// <param name="languageModel">The language model.</param> /// <param name="configuration">The configuration.</param> /// <returns></returns> internal IServiceProvider CreateTestContainer(LanguageModelAccessorMock languageModel, CecilAnalyzerConfiguration configuration) { ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(IEntitiesAccessor), languageModel == null ? new LanguageModelAccessorMock() : languageModel); serviceContainer.AddService(typeof(CecilAnalyzerConfiguration), configuration == null ? CecilAnalyzerConfiguration.CreateDefaultConfiguration(CreateFullPath("test.yap")) : configuration); serviceContainer.AddService(typeof(IBuilderConfigurator <BuilderStage>), new ILAnalyzerTestBuilderConfigurator()); return(serviceContainer); }
public void TestInitialize() { svcContainer.AddService(typeof(IBuilderConfigurator <BuilderStage>), new ILAnalyzerTestBuilderConfigurator()); svcContainer.AddService(typeof(CecilAnalyzerConfiguration), CecilAnalyzerConfiguration.CreateDefaultConfiguration(CreateFullPath("TestTarget.exe"))); svcContainer.AddService(typeof(ILanguageModelAccessor), new LanguageModelAccessorMock()); }
public virtual void GlobalSetUp() { config = CecilAnalyzerConfiguration.CreateDefaultConfiguration("test.yap"); }