Exemple #1
0
        public void FindAllImplementations_SelectedImplementation_ReturnsCorrectNumber()
        {
            const string inputClass =
                @"Implements IClass1

Public Sub IClass1_Foo()
End Sub";

            const string inputInterface =
                @"Public Sub Foo()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputClass)
                          .AddComponent("Class2", ComponentType.ClassModule, inputClass)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputInterface)
                          .Build();

            var vbe    = builder.AddProject(project).Build();
            var parser = MockParser.Create(vbe.Object);

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

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, null, parser.State, vbe.Object, vm, null);

            command.Execute(parser.State.AllUserDeclarations.First(s => s.IdentifierName == "IClass1_Foo"));

            Assert.AreEqual(2, vm.Tabs[0].SearchResults.Count);
        }
        public void FindAllImplementations_StateNotReady_Aborts()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub

Private Sub Bar()
    Foo: Foo
    Foo
    Foo
End Sub";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            vbe.Setup(s => s.ActiveCodePane).Returns(value: null);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                state.SetStatusAndFireStateChanged(this, ParserState.ResolvedDeclarations, CancellationToken.None);

                var vm           = new SearchResultsWindowViewModel();
                var uiDispatcher = new Mock <IUiDispatcher>();
                var command      = new FindAllImplementationsCommand(state, vbe.Object, vm, new FindAllImplementationsService(null, null, state, vm, null, uiDispatcher.Object));

                command.Execute(state.AllUserDeclarations.Single(s => s.IdentifierName == "Foo"));

                Assert.IsFalse(vm.Tabs.Any());
            }
        }
Exemple #3
0
        public void FindAllImplementations_CanExecute_StateNotReady()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub

Private Sub Bar()
    Foo: Foo
    Foo
    Foo
End Sub";

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);

            vbe.Setup(s => s.ActiveCodePane).Returns(value: null);

            var state = MockParser.CreateAndParse(vbe.Object);

            state.SetStatusAndFireStateChanged(this, ParserState.ResolvedDeclarations);

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, null, state, vbe.Object, vm, null);

            Assert.IsFalse(command.CanExecute(state.AllUserDeclarations.Single(s => s.IdentifierName == "Foo")));
        }
        public void FindAllImplementations_SelectedImplementation_ReturnsCorrectNumber()
        {
            const string inputClass =
                @"Implements IClass1

Public Sub IClass1_Foo()
End Sub";

            const string inputInterface =
                @"Public Sub Foo()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputClass)
                          .AddComponent("Class2", ComponentType.ClassModule, inputClass)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputInterface)
                          .Build();

            var vbe          = builder.AddProject(project).Build();
            var uiDispatcher = new Mock <IUiDispatcher>();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var vm      = new SearchResultsWindowViewModel();
                var command = new FindAllImplementationsCommand(null, null, state, vbe.Object, vm, null, uiDispatcher.Object);

                command.Execute(state.AllUserDeclarations.First(s => s.IdentifierName == "IClass1_Foo"));

                Assert.AreEqual(2, vm.Tabs[0].SearchResults.Count);
            }
        }
        public void FindAllImplementations_NoResults_DisplayMessageBox()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub";

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, default(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 messageBox = new Mock <IMessageBox>();

            messageBox.Setup(m =>
                             m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(),
                                    It.IsAny <MessageBoxIcon>())).Returns(DialogResult.OK);

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, messageBox.Object, parser.State, vbe.Object, vm, null);

            command.Execute(parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "Foo"));

            messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(),
                                          It.IsAny <MessageBoxIcon>()), Times.Once);
        }
        public void FindAllImplementations_SingleResult_Navigates()
        {
            const string inputClass =
                @"Implements IClass1

Public Sub IClass1_Foo()
End Sub";

            const string inputInterface =
                @"Public Sub Foo()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputClass)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputInterface)
                          .Build();

            var vbe          = builder.AddProject(project).Build();
            var uiDispatcher = new Mock <IUiDispatcher>();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var navigateCommand = new Mock <INavigateCommand>();

                var vm      = new SearchResultsWindowViewModel();
                var command = new FindAllImplementationsCommand(navigateCommand.Object, null, state, vbe.Object, vm, null, uiDispatcher.Object);

                command.Execute(state.AllUserDeclarations.Single(s => s.IdentifierName == "Foo"));

                navigateCommand.Verify(n => n.Execute(It.IsAny <object>()), Times.Once);
            }
        }
Exemple #7
0
        public void FindAllImplementations_NoResults_DisplayMessageBox()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub";

            IVBComponent component;
            var          vbe          = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component);
            var          uiDispatcher = new Mock <IUiDispatcher>();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var messageBox = new Mock <IMessageBox>();
                messageBox.Setup(m =>
                                 m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(),
                                        It.IsAny <MessageBoxIcon>())).Returns(DialogResult.OK);

                var vm      = new SearchResultsWindowViewModel();
                var command = new FindAllImplementationsCommand(null, messageBox.Object, state, vbe.Object, vm, null, uiDispatcher.Object);

                command.Execute(state.AllUserDeclarations.Single(s => s.IdentifierName == "Foo"));

                messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(),
                                              It.IsAny <MessageBoxIcon>()), Times.Once);
            }
        }
        public void FindAllImplementations_NullTarget_Aborts()
        {
            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe = builder.BuildFromSingleStandardModule(string.Empty, out component);

            vbe.Setup(s => s.ActiveCodePane).Returns(value: null);
            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 vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, null, parser.State, vbe.Object, vm, null);

            command.Execute(null);

            Assert.IsFalse(vm.Tabs.Any());
        }
Exemple #9
0
        public void FindAllImplementations_CanExecute_NullActiveCodePane()
        {
            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleStandardModule(string.Empty, out component);

            vbe.Setup(s => s.ActiveCodePane).Returns(value: null);

            var state = MockParser.CreateAndParse(vbe.Object);

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, null, state, vbe.Object, vm, null);

            Assert.IsFalse(command.CanExecute(null));
        }
        public void FindAllImplementations_CanExecute_NullTarget()
        {
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(string.Empty, out _);

            vbe.Setup(s => s.ActiveCodePane).Returns(value: null);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var vm           = new SearchResultsWindowViewModel();
                var uiDispatcher = new Mock <IUiDispatcher>();
                var command      = new FindAllImplementationsCommand(state, vbe.Object, vm, new FindAllImplementationsService(null, null, state, vm, null, uiDispatcher.Object));

                Assert.IsFalse(command.CanExecute(null));
            }
        }
        public void FindAllImplementations_SelectedReference_ReturnsCorrectNumber()
        {
            const string inputClass =
                @"Implements IClass1

Public Sub IClass1_Foo()
End Sub

Public Sub Buzz()
    IClass1_Foo
End Sub";

            const string inputInterface =
                @"Public Sub Foo()
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none)
                          .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputClass, new Selection(7, 5, 7, 5))
                          .AddComponent("Class2", vbext_ComponentType.vbext_ct_ClassModule, inputClass)
                          .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputInterface)
                          .Build();

            var vbe = builder.AddProject(project).Build();

            vbe.Setup(v => v.ActiveCodePane).Returns(project.Object.VBComponents.Item("Class1").CodeModule.CodePane);

            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 vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, null, parser.State, vbe.Object, vm, null);

            command.Execute(null);

            Assert.AreEqual(2, vm.Tabs[0].SearchResults.Count);
        }
        public void FindAllImplementations_ReturnsCorrectNumberForProperty()
        {
            var intrface =
                @"Option Explicit

Public Property Get Foo(Bar As Long) As Long
End Property

Public Property Let Foo(Bar As Long, NewValue As Long)
End Property
";

            var implementation =
                @"Option Explicit

Implements TestInterface

Private Property Get TestInterface_Foo(Bar As Long) As Long
End Property

Private Property Let TestInterface_Foo(Bar As Long, RHS As Long)
End Property
";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, implementation)
                          .AddComponent("Class2", ComponentType.ClassModule, implementation)
                          .AddComponent("TestInterface", ComponentType.ClassModule, intrface)
                          .Build();

            var vbe          = builder.AddProject(project).Build();
            var uiDispatcher = new Mock <IUiDispatcher>();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var vm      = new SearchResultsWindowViewModel();
                var command = new FindAllImplementationsCommand(null, null, state, vbe.Object, vm, null, uiDispatcher.Object);

                command.Execute(state.AllUserDeclarations.Single(s => s.IdentifierName == "Foo" && s.DeclarationType == DeclarationType.PropertyGet));

                Assert.AreEqual(2, vm.Tabs[0].SearchResults.Count);
            }
        }
        public void FindAllImplementations_SingleResult_Navigates()
        {
            const string inputClass =
                @"Implements IClass1

Public Sub IClass1_Foo()
End Sub";

            const string inputInterface =
                @"Public Sub Foo()
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none)
                          .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputClass)
                          .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputInterface)
                          .Build();

            var vbe      = builder.AddProject(project).Build();
            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 navigateCommand = new Mock <INavigateCommand>();

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(navigateCommand.Object, null, parser.State, vbe.Object, vm, null);

            command.Execute(parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "Foo"));

            navigateCommand.Verify(n => n.Execute(It.IsAny <object>()), Times.Once);
        }
        public void FindAllImplementations_SelectedReference_ReturnsCorrectNumber()
        {
            const string inputClass =
                @"Implements IClass1

Public Sub IClass1_Foo()
End Sub

Public Sub Buzz()
    IClass1_Foo
End Sub";

            const string inputInterface =
                @"Public Sub Foo()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputClass, new Selection(7, 5, 7, 5))
                          .AddComponent("Class2", ComponentType.ClassModule, inputClass)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputInterface)
                          .Build();

            var vbe = builder.AddProject(project).Build();

            vbe.Setup(v => v.ActiveCodePane).Returns(project.Object.VBComponents["Class1"].CodeModule.CodePane);

            var uiDispatcher = new Mock <IUiDispatcher>();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var vm      = new SearchResultsWindowViewModel();
                var command = new FindAllImplementationsCommand(null, null, state, vbe.Object, vm, null, uiDispatcher.Object);

                command.Execute(null);

                Assert.AreEqual(2, vm.Tabs[0].SearchResults.Count);
            }
        }
        public void FindAllImplementations_StateNotReady_Aborts()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub

Private Sub Bar()
    Foo: Foo
    Foo
    Foo
End Sub";

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe = builder.BuildFromSingleStandardModule(inputCode, out component);

            vbe.Setup(s => s.ActiveCodePane).Returns(value: null);
            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");
            }

            parser.State.SetStatusAndFireStateChanged(ParserState.ResolvedDeclarations);

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllImplementationsCommand(null, null, parser.State, vbe.Object, vm, null);

            command.Execute(parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "Foo"));

            Assert.IsFalse(vm.Tabs.Any());
        }
 protected FindAllImplementationsCommandMenuItemBase(FindAllImplementationsCommand command)
     : base(command)
 {
 }
 public ProjectExplorerFindAllImplementationsCommandMenuItem(FindAllImplementationsCommand command)
     : base(command)
 {
 }
 public FindAllImplementationsCommandMenuItem(FindAllImplementationsCommand command)
     : base(command)
 {
 }