コード例 #1
0
        public void Transforms_All_NoCtorsAvailable()
        {
            _checker.Stub(mock => mock.CanBeMixed(Arg <string> .Is.Anything)).Return(true);
            _tracker.Expect(tracker => tracker.GetAssemblies()).Return(new[] { _assemblyDefinition1 });
            _codeGenerator.Expect(generator => generator.CreateNewObjectMethod
                                      (_assemblyDefinition1, _assemblyDefinition1.MainModule.Types[1].Methods[0], _tracker));
            _codeGenerator.Expect(generator => generator.CreateNewObjectMethod
                                      (_assemblyDefinition1, _assemblyDefinition1.Modules[1].Types[1].Methods[0], _tracker));
            _tracker.Expect(tracker => tracker.GetAssemblies()).Return(new[] { _assemblyDefinition1 });
            _codeGenerator.Expect(generator => generator.ReplaceNewStatements
                                      (_assemblyDefinition1, _assemblyDefinition1.MainModule.Types[1], _assemblyDefinition1.MainModule.Types[1].Methods[0], _tracker)).Return(true);
            _tracker.Expect(tracker => tracker.MarkModified(_assemblyDefinition1));
            _codeGenerator.Expect(generator => generator.ReplaceNewStatements
                                      (_assemblyDefinition1, _assemblyDefinition1.Modules[1].Types[1], _assemblyDefinition1.Modules[1].Types[1].Methods[0], _tracker)).Return(true);
            _tracker.Expect(tracker => tracker.MarkModified(_assemblyDefinition1));

            _generator.Transform(_tracker);

            _tracker.VerifyAllExpectations();
        }
コード例 #2
0
        public void CodeGenerator_ReplacesNew()
        {
            var method = _assemblyDefinition1.MainModule.Types[1].Methods[2];
            var ctor   = _assemblyDefinition1.MainModule.Types[1].Methods[1];

            _checker.Stub(mock => mock.CanBeMixed(Arg <string> .Is.Anything)).Return(true);
            _checker.Stub(mock => mock.IsCached(Arg <string> .Is.Anything)).Return(true);
            _referenceGenerator.Expect(r => r.GetCallableParamListCreateMethod(_assemblyDefinition1, _assemblyDefinition1.MainModule.Types[1].Methods[1], _tracker)).IgnoreArguments().Return(
                MethodReferenceObjectMother.GetParamListMethodRef(_assemblyDefinition1));
            _referenceGenerator.Expect(r => r.GetCallableObjectFactoryCreateMethod(_assemblyDefinition1, _assemblyDefinition1.MainModule, _assemblyDefinition1.MainModule.Types[1], _tracker)).Return(
                MethodReferenceObjectMother.GetObjectFactoryMethodRef(_assemblyDefinition1));

            var result = _codeGenerator.ReplaceNewStatements(_assemblyDefinition1, method.DeclaringType, method, _tracker);

            Assert.That(result, Is.True);
            Assert.That(method.Body.Instructions[0] != (Instruction.Create(OpCodes.Newobj, ctor)));
            Assert.That(method.Body.Instructions[1] != (Instruction.Create(OpCodes.Newobj, ctor)));
            Assert.That(method.Body.Instructions[1].OpCode == OpCodes.Call);
            Assert.That(((MethodReference)method.Body.Instructions[1].Operand).Name == "ParamList");
        }
コード例 #3
0
        public void SetUp()
        {
            AssemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "IntegrationTestFiles");
            TempPath     = Path.Combine(AssemblyPath, "temp");

            if (Directory.Exists(TempPath))
            {
                Directory.Delete(TempPath, true);
            }
            Directory.CreateDirectory(TempPath);

            Thread.Sleep(500);

            var assemblyFileNames = new[] { "DummyTarget.dll" };

            foreach (var assemblyFileName in assemblyFileNames)
            {
                File.Copy(Path.Combine(AssemblyPath, assemblyFileName), GetTempPath(assemblyFileName));
            }

            _verifier = PEVerifier.CreateDefault();

            AssemblyDefinition[] assemblies = assemblyFileNames.Select(fileName => AssemblyDefinition.ReadAssembly(GetTempPath(fileName))).ToArray();
            _tracker = new AssemblyTracker(assemblies, new TypeDefinitionCache());

            _checker = MockRepository.GenerateStub <IMixinChecker> ();
            _checker.Stub(x => x.CanBeMixed(null)).Return(true).IgnoreArguments();

            _transformator = new ConstructorGenerator.ConstructorGenerator(_checker,
                                                                           new ILCodeGenerator(
                                                                               new MethodReferenceGenerator("Remotion.Interfaces, Version=1.13.73.1026, Culture=neutral, PublicKeyToken=fee00910d6e5f53b",
                                                                                                            "Remotion.Mixins.ObjectFactory",
                                                                                                            "Remotion.Reflection.ParamList"),
                                                                               _checker)
                                                                           );

            _signer = new AssemblySigner(new ModuleDefinitionWriter(new FileSystem(), null, new List <StrongNameKeyPair> ()));

            _fileSystem = new FileSystem();
        }
コード例 #4
0
        public void SetUp()
        {
            AssemblyPath = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "IntegrationTestFiles");
              TempPath = Path.Combine (AssemblyPath, "temp");

              if (Directory.Exists (TempPath))
            Directory.Delete (TempPath, true);
              Directory.CreateDirectory (TempPath);

              Thread.Sleep (500);

              var assemblyFileNames = new[] { "DummyTarget.dll" };
              foreach (var assemblyFileName in assemblyFileNames)
            File.Copy (Path.Combine (AssemblyPath, assemblyFileName), GetTempPath (assemblyFileName));

              _verifier = PEVerifier.CreateDefault ();

              AssemblyDefinition[] assemblies = assemblyFileNames.Select (fileName => AssemblyDefinition.ReadAssembly (GetTempPath (fileName))).ToArray();
              _tracker = new AssemblyTracker (assemblies, new TypeDefinitionCache());

              _checker = MockRepository.GenerateStub<IMixinChecker> ();
              _checker.Stub (x => x.CanBeMixed (null)).Return (true).IgnoreArguments ();

              _transformator = new ConstructorGenerator.ConstructorGenerator (_checker,
            new ILCodeGenerator (
              new MethodReferenceGenerator ("Remotion.Interfaces, Version=1.13.73.1026, Culture=neutral, PublicKeyToken=fee00910d6e5f53b",
                                        "Remotion.Mixins.ObjectFactory",
                                        "Remotion.Reflection.ParamList"),
               _checker)
              );

              _signer = new AssemblySigner (new ModuleDefinitionWriter (new FileSystem (), null, new List<StrongNameKeyPair> ()));

              _fileSystem = new FileSystem();
        }