예제 #1
0
 public void SetUp()
 {
     _assemblyDefinition       = AssemblyDefinitionObjectMother.CreateMultiModuleAssemblyDefinition();
     _tracker                  = new AssemblyTracker(new [] { _assemblyDefinition }, new TypeDefinitionCache());
     _markingAttributeStrategy = MockRepository.GenerateStub <IMarkingAttributeStrategy> ();
     _codeGenerator            = MockRepository.GenerateStub <ICodeGenerator>();
     _selectionFactory         = new TargetSelectorFactory();
     _options                  = new OptionSet();
     _methodsVirtualizer       = new AssemblyMethodsVirtualizer(_markingAttributeStrategy, _selectionFactory, _codeGenerator);
 }
예제 #2
0
        public void OverrideMethods_DoesNotSetNonMatchingMethodVirtual()
        {
            _selectionFactory.AddOptions(_options);
            _options.Parse(new[] { "--regex=TestMethodDoesnotMatch" });
            _methodsVirtualizer = new AssemblyMethodsVirtualizer(_markingAttributeStrategy, _selectionFactory, _codeGenerator);
            Assert.That(_assemblyDefinition.MainModule.Types[1].Methods[0].IsVirtual, Is.False);

            _methodsVirtualizer.Transform(_tracker);

            Assert.That(_assemblyDefinition.MainModule.Types[1].Methods[0].IsVirtual, Is.False);
        }
        public void OverrideMethods_DoesNotSetNonMatchingMethodVirtual()
        {
            _selectionFactory.AddOptions (_options);
              _options.Parse (new[] { "--regex=TestMethodDoesnotMatch" });
              _methodsVirtualizer = new AssemblyMethodsVirtualizer (_markingAttributeStrategy, _selectionFactory, _codeGenerator);
              Assert.That (_assemblyDefinition.MainModule.Types[1].Methods[0].IsVirtual, Is.False);

              _methodsVirtualizer.Transform (_tracker);

              Assert.That (_assemblyDefinition.MainModule.Types[1].Methods[0].IsVirtual, Is.False);
        }
        public void OverrideMethods_DoesNotMarkAssemblyWithougMatchingMethodsModified()
        {
            _selectionFactory.AddOptions (_options);
              _options.Parse (new[] { "--regex=xxx" });
              var _methodsVirtualizerNoMatch = new AssemblyMethodsVirtualizer (_markingAttributeStrategy, _selectionFactory, _codeGenerator);
              Assert.That (_tracker.IsModified (_assemblyDefinition), Is.False);

              _methodsVirtualizerNoMatch.Transform (_tracker);

              Assert.That (_tracker.IsModified (_assemblyDefinition), Is.False);
        }
예제 #5
0
        public void OverrideMethods_DoesNotMarkAssemblyWithougMatchingMethodsModified()
        {
            _selectionFactory.AddOptions(_options);
            _options.Parse(new[] { "--regex=xxx" });
            var _methodsVirtualizerNoMatch = new AssemblyMethodsVirtualizer(_markingAttributeStrategy, _selectionFactory, _codeGenerator);

            Assert.That(_tracker.IsModified(_assemblyDefinition), Is.False);

            _methodsVirtualizerNoMatch.Transform(_tracker);

            Assert.That(_tracker.IsModified(_assemblyDefinition), Is.False);
        }
예제 #6
0
        public void OverrideMethods_SecondaryModule_MethodMarked()
        {
            _selectionFactory.AddOptions(_options);
            _options.Parse(new[] { "--regex=TestSecondMethod" });
            _methodsVirtualizer = new AssemblyMethodsVirtualizer(_markingAttributeStrategy, _selectionFactory, _codeGenerator);
            MethodDefinition methodModule = _assemblyDefinition.Modules[1].Types[1].Methods[0];

            Assert.That(_assemblyDefinition.MainModule.Types[1].CustomAttributes, Is.Empty);
            Assert.That(_assemblyDefinition.Modules.Count, Is.EqualTo(2));
            Assert.That(_assemblyDefinition.MainModule.Types.Count, Is.EqualTo(2));
            _codeGenerator.Expect(s => s.GenerateMethodAndMoveBody(methodModule)).
            Return(new MethodDefinition("GeneratedMethod", MethodAttributes.Public | MethodAttributes.Virtual, methodModule.ReturnType));

            _methodsVirtualizer.Transform(_tracker);

            _markingAttributeStrategy.AssertWasCalled(s => s.AddCustomAttribute(methodModule, _assemblyDefinition));
            _codeGenerator.AssertWasCalled(s => s.GenerateMethodAndMoveBody(methodModule));
        }
        public void OverrideMethods_MainModule_MethodMarked()
        {
            _selectionFactory.AddOptions (_options);
              _options.Parse (new[] { "--regex=TestMethod" });
              _methodsVirtualizer = new AssemblyMethodsVirtualizer (_markingAttributeStrategy, _selectionFactory, _codeGenerator);
              MethodDefinition methodMain = _assemblyDefinition.MainModule.Types[1].Methods[0];
              _codeGenerator.Expect (s => s.GenerateMethodAndMoveBody (methodMain)).
              Return (new MethodDefinition ("GeneratedMethod", MethodAttributes.Public | MethodAttributes.Virtual, methodMain.ReturnType));

              Assert.That (_assemblyDefinition.MainModule.Types[1].CustomAttributes, Is.Empty);
              Assert.That (_assemblyDefinition.Modules.Count, Is.EqualTo (2));
              Assert.That (_assemblyDefinition.MainModule.Types.Count, Is.EqualTo (2));

              _methodsVirtualizer.Transform (_tracker);

              _markingAttributeStrategy.AssertWasCalled (s => s.AddCustomAttribute (methodMain, _assemblyDefinition));
              _codeGenerator.AssertWasCalled (s => s.GenerateMethodAndMoveBody (methodMain));
        }
 public void SetUp()
 {
     _assemblyDefinition = AssemblyDefinitionObjectMother.CreateMultiModuleAssemblyDefinition();
       _tracker = new AssemblyTracker (new [] { _assemblyDefinition }, new TypeDefinitionCache());
       _markingAttributeStrategy = MockRepository.GenerateStub<IMarkingAttributeStrategy> ();
       _codeGenerator = MockRepository.GenerateStub<ICodeGenerator>();
       _selectionFactory = new TargetSelectorFactory ();
       _options = new OptionSet ();
       _methodsVirtualizer = new AssemblyMethodsVirtualizer (_markingAttributeStrategy, _selectionFactory, _codeGenerator);
 }