Exemplo n.º 1
0
        public void Presenter_NullTarget_ReturnsNull()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleStandardModule(inputCode, out component, selection);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            var view      = new Mock <IExtractInterfaceDialog>();
            var presenter = new ExtractInterfacePresenter(view.Object, model);

            Assert.AreEqual(null, presenter.Show());
        }
Exemplo n.º 2
0
        public void ExtractInterfaceRefactoring_NullModel_NoChanges()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 23, 1, 27);

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                //Specify Params to remove
                var model = new ExtractInterfaceModel(state, qualifiedSelection);

                var presenter = new Mock <IExtractInterfacePresenter>();
                presenter.Setup(p => p.Show()).Returns(value: null);

                //SetupFactory
                var factory = SetupFactory(model);
                factory.Setup(f => f.Create()).Returns(presenter.Object);

                var refactoring = new ExtractInterfaceRefactoring(vbe.Object, null, factory.Object);
                refactoring.Refactor();

                Assert.AreEqual(1, vbe.Object.ActiveVBProject.VBComponents.Count());
                Assert.AreEqual(inputCode, component.CodeModule.Content());
            }
        }
Exemplo n.º 3
0
        public void ExtractInterfaceRefactoring_IgnoresField()
        {
            //Input
            const string inputCode =
                @"Public Fizz As Boolean";

            var selection = new Selection(1, 23, 1, 27);

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, selection);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            //Specify Params to remove
            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            Assert.AreEqual(0, model.Members.Count());
        }
Exemplo n.º 4
0
        public void Presenter_Reject_ReturnsNull()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                var model = new ExtractInterfaceModel(state, qualifiedSelection);
                model.Members.ElementAt(0).IsSelected = true;

                var view = new Mock <IRefactoringDialog <ExtractInterfaceViewModel> >();
                view.Setup(v => v.ViewModel).Returns(new ExtractInterfaceViewModel());
                view.Setup(v => v.DialogResult).Returns(DialogResult.Cancel);

                var factory = new ExtractInterfacePresenterFactory(vbe.Object, state, view.Object);

                var presenter = factory.Create();

                Assert.AreEqual(null, presenter.Show());
            }
        }
Exemplo n.º 5
0
        public void ExtractInterfaceRefactoring_NullPresenter_NoChanges()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 23, 1, 27);

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object);
            using (state)
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                //Specify Params to remove
                var model = new ExtractInterfaceModel(state, qualifiedSelection);

                //SetupFactory
                var factory = new Mock <IRefactoringPresenterFactory>();
                factory.Setup(f => f.Create <IExtractInterfacePresenter, ExtractInterfaceModel>(It.IsAny <ExtractInterfaceModel>())).Returns(value: null);

                var refactoring = TestRefactoring(vbe.Object, rewritingManager, state, factory.Object);
                refactoring.Refactor();

                Assert.AreEqual(1, vbe.Object.ActiveVBProject.VBComponents.Count());
                Assert.AreEqual(inputCode, component.CodeModule.Content());
            }
        }
Exemplo n.º 6
0
        private static Mock <IRefactoringPresenterFactory> SetupFactory(ExtractInterfaceModel model)
        {
            var presenter = new Mock <IExtractInterfacePresenter>();

            var factory = new Mock <IRefactoringPresenterFactory>();

            factory.Setup(f => f.Create <IExtractInterfacePresenter, ExtractInterfaceModel>(It.IsAny <ExtractInterfaceModel>()))
            .Callback(() => presenter.Setup(p => p.Show()).Returns(model))
            .Returns(presenter.Object);
            return(factory);
        }
Exemplo n.º 7
0
        public void ExtractInterfaceRefactoring_ImplementProc()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 23, 1, 27);

            //Expectation
            const string expectedCode =
                @"Implements ITestModule1

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Private Sub ITestModule1_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
    Err.Raise 5 'TODO implement interface member
End Sub
";

            const string expectedInterfaceCode =
                @"Option Explicit

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

";

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                //Specify Params to remove
                var model = new ExtractInterfaceModel(state, qualifiedSelection);
                foreach (var member in model.Members)
                {
                    member.IsSelected = true;
                }

                //SetupFactory
                var factory = SetupFactory(model);

                var refactoring = new ExtractInterfaceRefactoring(vbe.Object, null, factory.Object);
                refactoring.Refactor(qualifiedSelection);

                Assert.AreEqual(expectedInterfaceCode, component.Collection[1].CodeModule.Content());
                Assert.AreEqual(expectedCode, component.CodeModule.Content());
            }
        }
Exemplo n.º 8
0
        public void ExtractInterfaceRefactoring_PassTargetIn()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 23, 1, 27);

            //Expectation
            const string expectedCode =
                @"Implements ITestModule1

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Private Sub ITestModule1_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
    Err.Raise 5 'TODO implement interface member
End Sub
";

            const string expectedInterfaceCode =
                @"Option Explicit

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

";

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object);
            using (state)
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                //Specify Params to remove
                var model = new ExtractInterfaceModel(state, qualifiedSelection);
                model.Members = new[] { model.Members.ElementAt(0) }.ToList();

                //SetupFactory
                var factory = SetupFactory(model);

                var refactoring = new ExtractInterfaceRefactoring(vbe.Object, null, factory.Object, rewritingManager);
                refactoring.Refactor(state.AllUserDeclarations.Single(s => s.DeclarationType == DeclarationType.ClassModule));

                Assert.AreEqual(expectedInterfaceCode, component.Collection[1].CodeModule.Content());
                Assert.AreEqual(expectedCode, component.CodeModule.Content());
            }
        }
        public ExtractInterfacePresenter Create()
        {
            var selection = _vbe.GetActiveSelection();

            if (selection == null)
            {
                return(null);
            }

            var model = new ExtractInterfaceModel(_state, selection.Value);

            // don't show the UI if there's no memeber to extract
            return(model.Members.Any() ? new ExtractInterfacePresenter(_view, model) : null);
        }
Exemplo n.º 10
0
        public void ExtractInterfaceRefactoring_NullModel_NoChanges()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 23, 1, 27);

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, selection);
            var         project  = vbe.Object.VBProjects.Item(0);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            //Specify Params to remove
            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            var presenter = new Mock <IExtractInterfacePresenter>();

            presenter.Setup(p => p.Show()).Returns(value: null);

            //SetupFactory
            var factory = SetupFactory(model);

            factory.Setup(f => f.Create()).Returns(presenter.Object);

            //Act
            var refactoring = new ExtractInterfaceRefactoring(vbe.Object, parser.State, null, factory.Object);

            refactoring.Refactor();

            //Assert
            Assert.AreEqual(1, project.VBComponents.Cast <VBComponent>().Count());   // somehow, the VBComponents Count mock isn't working
            Assert.AreEqual(inputCode, project.VBComponents.Item(0).CodeModule.Lines());
        }
Exemplo n.º 11
0
        public void ExtractInterfaceRefactoring_IgnoresField()
        {
            //Input
            const string inputCode =
                @"Public Fizz As Boolean";

            var selection = new Selection(1, 23, 1, 27);

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            //Specify Params to remove
            var model = new ExtractInterfaceModel(state, qualifiedSelection);

            Assert.AreEqual(0, model.Members.Count());
        }
Exemplo n.º 12
0
        public void Presenter_NullTarget_ReturnsNull()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            var model = new ExtractInterfaceModel(state, qualifiedSelection);

            var view      = new Mock <IExtractInterfaceDialog>();
            var presenter = new ExtractInterfacePresenter(view.Object, model);

            Assert.AreEqual(null, presenter.Show());
        }
Exemplo n.º 13
0
        public void Presenter_Accept_ReturnsUpdatedModel()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, selection);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            model.Members.ElementAt(0).IsSelected = true;

            var view = new Mock <IExtractInterfaceDialog>();

            view.Setup(v => v.ShowDialog()).Returns(DialogResult.OK);
            view.Setup(v => v.InterfaceName).Returns("Class1");

            var factory   = new ExtractInterfacePresenterFactory(vbe.Object, parser.State, view.Object);
            var presenter = factory.Create();

            Assert.AreEqual("Class1", presenter.Show().InterfaceName);
        }
Exemplo n.º 14
0
        private static Mock <IRefactoringPresenterFactory <IExtractInterfacePresenter> > SetupFactory(ExtractInterfaceModel model)
        {
            var presenter = new Mock <IExtractInterfacePresenter>();

            presenter.Setup(p => p.Show()).Returns(model);

            var factory = new Mock <IRefactoringPresenterFactory <IExtractInterfacePresenter> >();

            factory.Setup(f => f.Create()).Returns(presenter.Object);
            return(factory);
        }
 public ExtractInterfacePresenter(IRefactoringDialog <ExtractInterfaceViewModel> view, ExtractInterfaceModel model)
 {
     _view  = view;
     _model = model;
 }
 public ExtractInterfacePresenter(IExtractInterfaceView view, ExtractInterfaceModel model)
 {
     _view = view;
     _model = model;
 }
Exemplo n.º 17
0
        public void ExtractInterfaceRefactoring_ImplementProcAndFunc_IgnoreProperties()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(b) As Variant
End Function

Public Property Get Buzz()
End Property

Public Property Let Buzz(value)
End Property

Public Property Set Buzz(value)
End Property";

            var selection = new Selection(1, 23, 1, 27);

            //Expectation
            const string expectedCode =
                @"Implements ITestModule1

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(b) As Variant
End Function

Public Property Get Buzz()
End Property

Public Property Let Buzz(value)
End Property

Public Property Set Buzz(value)
End Property

Private Sub ITestModule1_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
    Err.Raise 5 'TODO implement interface member
End Sub

Private Function ITestModule1_Fizz(ByRef b As Variant) As Variant
    Err.Raise 5 'TODO implement interface member
End Function
";

            const string expectedInterfaceCode =
                @"Option Explicit

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(ByRef b As Variant) As Variant
End Function

";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            //Specify Params to remove
            var model = new ExtractInterfaceModel(state, qualifiedSelection);

            foreach (var member in model.Members)
            {
                if (!member.FullMemberSignature.Contains("Property"))
                {
                    member.IsSelected = true;
                }
            }

            //SetupFactory
            var factory = SetupFactory(model);

            var refactoring = new ExtractInterfaceRefactoring(vbe.Object, null, factory.Object);

            refactoring.Refactor(qualifiedSelection);

            Assert.AreEqual(expectedInterfaceCode, component.Collection[1].CodeModule.Content());
            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Exemplo n.º 18
0
        public void ExtractInterfaceRefactoring_ImplementProcAndFuncAndPropGetSetLet()
        {
            //Input
            const string inputCode = @"
Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(b) As Variant
End Function

Public Property Get Buzz()
End Property

Public Property Let Buzz(value)
End Property

Public Property Set Buzz(value)
End Property";

            var selection = new Selection(1, 23, 1, 27);

            //Expectation
            const string expectedCode = @"
Implements ITestModule1

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(b) As Variant
End Function

Public Property Get Buzz()
End Property

Public Property Let Buzz(value)
End Property

Public Property Set Buzz(value)
End Property

Private Sub ITestModule1_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
    Err.Raise 5 'TODO implement interface member
End Sub

Private Function ITestModule1_Fizz(ByRef b As Variant) As Variant
    Err.Raise 5 'TODO implement interface member
End Function

Private Property Get ITestModule1_Buzz() As Variant
    Err.Raise 5 'TODO implement interface member
End Property

Private Property Let ITestModule1_Buzz(ByRef value As Variant)
    Err.Raise 5 'TODO implement interface member
End Property

Private Property Set ITestModule1_Buzz(ByRef value As Variant)
    Err.Raise 5 'TODO implement interface member
End Property
";

            const string expectedInterfaceCode =
                @"Option Explicit

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(ByRef b As Variant) As Variant
End Function

Public Property Get Buzz() As Variant
End Property

Public Property Let Buzz(ByRef value As Variant)
End Property

Public Property Set Buzz(ByRef value As Variant)
End Property

";

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object);
            using (state)
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                //Specify Params to remove
                var model = new ExtractInterfaceModel(state, qualifiedSelection);

                //SetupFactory
                var factory = SetupFactory(model);

                var refactoring = new ExtractInterfaceRefactoring(vbe.Object, null, factory.Object, rewritingManager);
                refactoring.Refactor(qualifiedSelection);

                Assert.AreEqual(expectedInterfaceCode, component.Collection[1].CodeModule.Content());
                Assert.AreEqual(expectedCode, component.CodeModule.Content());
            }
        }
Exemplo n.º 19
0
        public void ExtractInterfaceRefactoring_PassTargetIn()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 23, 1, 27);

            //Expectation
            const string expectedCode =
                @"Implements ITestModule1


Private Sub ITestModule1_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
    Err.Raise 5 'TODO implement interface member
End Sub

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";

            const string expectedInterfaceCode =
                @"Option Explicit

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

";

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, selection);
            var         project  = vbe.Object.VBProjects.Item(0);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            //Specify Params to remove
            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            model.Members.ElementAt(0).IsSelected = true;

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new ExtractInterfaceRefactoring(vbe.Object, parser.State, null, factory.Object);

            refactoring.Refactor(parser.State.AllUserDeclarations.Single(s => s.DeclarationType == DeclarationType.ClassModule));

            //Assert
            Assert.AreEqual(expectedInterfaceCode, project.VBComponents.Item(1).CodeModule.Lines());
            Assert.AreEqual(expectedCode, project.VBComponents.Item(0).CodeModule.Lines());
        }
Exemplo n.º 20
0
        public void ExtractInterfaceRefactoring_ImplementProcAndFuncAndPropGetSetLet()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(b) As Variant
End Function

Public Property Get Buzz()
End Property

Public Property Let Buzz(value)
End Property

Public Property Set Buzz(value)
End Property";

            var selection = new Selection(1, 23, 1, 27);

            //Expectation
            const string expectedCode =
                @"Implements ITestModule1


Private Sub ITestModule1_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
    Err.Raise 5 'TODO implement interface member
End Sub

Private Function ITestModule1_Fizz(ByRef b As Variant) As Variant
    Err.Raise 5 'TODO implement interface member
End Function

Private Property Get ITestModule1_Buzz() As Variant
    Err.Raise 5 'TODO implement interface member
End Property

Private Property Let ITestModule1_Buzz(ByRef value As Variant)
    Err.Raise 5 'TODO implement interface member
End Property

Private Property Set ITestModule1_Buzz(ByRef value As Variant)
    Err.Raise 5 'TODO implement interface member
End Property

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(b) As Variant
End Function

Public Property Get Buzz()
End Property

Public Property Let Buzz(value)
End Property

Public Property Set Buzz(value)
End Property";

            const string expectedInterfaceCode =
                @"Option Explicit

Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Public Function Fizz(ByRef b As Variant) As Variant
End Function

Public Property Get Buzz() As Variant
End Property

Public Property Let Buzz(ByRef value As Variant)
End Property

Public Property Set Buzz(ByRef value As Variant)
End Property

";

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, selection);
            var         project  = vbe.Object.VBProjects.Item(0);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            //Specify Params to remove
            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            foreach (var member in model.Members)
            {
                member.IsSelected = true;
            }

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new ExtractInterfaceRefactoring(vbe.Object, parser.State, null, factory.Object);

            refactoring.Refactor(qualifiedSelection);

            //Assert
            Assert.AreEqual(expectedInterfaceCode, project.VBComponents.Item(1).CodeModule.Lines());
            Assert.AreEqual(expectedCode, project.VBComponents.Item(0).CodeModule.Lines());
        }
Exemplo n.º 21
0
        private static IRefactoring TestRefactoring(IVBE vbe, IRewritingManager rewritingManager, RubberduckParserState state, ExtractInterfaceModel model, IMessageBox msgBox = null)
        {
            var factory = SetupFactory(model);

            return(TestRefactoring(vbe, rewritingManager, state, factory.Object, msgBox));
        }