Exemplo n.º 1
0
        public void FindAllReferences_ReturnsCorrectNumber()
        {
            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);

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

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

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

Private Sub Bar()
    Foo
End Sub";

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleStandardModule(inputCode, out component);
            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 FindAllReferencesCommand(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);
        }
Exemplo n.º 3
0
        public void FindAllReferences_FormNoResults_DisplaysMessageBox()
        {
            var code    = @"
Public Sub DoSomething()
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).Build();

            project.AddComponent(form.Component, form.CodeModule);
            builder.AddProject(project.Build());
            var vbe = builder.Build();

            vbe.SetupGet(v => v.SelectedVBComponent).Returns(form.Component.Object);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                AssertParserReady(state);

                var messageBox = new Mock <IMessageBox>();

                var vm           = new SearchResultsWindowViewModel();
                var uiDispatcher = new Mock <IUiDispatcher>();
                var command      = new FindAllReferencesCommand(state, vbe.Object, vm, new FindAllReferencesService(null, messageBox.Object, state, vm, null, uiDispatcher.Object));
                var target       = state.AllUserDeclarations.Single(s => s.IdentifierName == "Form1");

                command.Execute(target);

                messageBox.Verify(m => m.NotifyWarn(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            }
        }
Exemplo n.º 4
0
        public void FindAllReferences_ReferenceSelected_ReturnsCorrectNumber()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub

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

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

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

                command.Execute(null);

                Assert.AreEqual(4, vm.Tabs[0].SearchResults.Count);
            }
        }
Exemplo n.º 5
0
        public void FindAllReferences_FormMultipleResults_ReturnsCorrectNumber()
        {
            var code    = @"
Public Sub DoSomething()
    Form1.Width = 20
    Form1.Height = 200
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).AddControl("TextBox1").Build();

            project.AddComponent(form.Component, form.CodeModule);
            builder.AddProject(project.Build());
            var vbe = builder.Build();

            vbe.SetupGet(v => v.SelectedVBComponent).Returns(form.Component.Object);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                AssertParserReady(state);

                var vm           = new SearchResultsWindowViewModel();
                var uiDispatcher = new Mock <IUiDispatcher>();
                var command      = new FindAllReferencesCommand(state, vbe.Object, vm, new FindAllReferencesService(null, null, state, vm, null, uiDispatcher.Object));
                var target       = state.AllUserDeclarations.Single(s => s.IdentifierName == "Form1");

                command.Execute(target);

                Assert.AreEqual(1, vm.Tabs.Count);
                Assert.AreEqual(2, vm.Tabs[0].SearchResults.Count);
            }
        }
Exemplo n.º 6
0
        public void FindAllReferences_FormSingleResult_Navigates()
        {
            var code            = @"
Public Sub DoSomething()
    Form1.Height = 20
End Sub
";
            var navigateCommand = new Mock <INavigateCommand>();
            var builder         = new MockVbeBuilder();
            var project         = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form            = project.MockUserFormBuilder("Form1", code).AddControl("TextBox1").Build();

            project.AddComponent(form.Component, form.CodeModule);
            builder.AddProject(project.Build());
            var vbe = builder.Build();

            vbe.SetupGet(v => v.SelectedVBComponent).Returns(form.Component.Object);


            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                AssertParserReady(state);

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

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

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

Private Sub Bar()
    Foo
End Sub";

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

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

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

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

                navigateCommand.Verify(n => n.Execute(It.IsAny <object>()), Times.Once);
            }
        }
Exemplo n.º 8
0
        public void FindAllReferences_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 FindAllReferencesCommand(state, vbe.Object, vm, new FindAllReferencesService(null, null, state, vm, null, uiDispatcher.Object));

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

                Assert.IsFalse(vm.Tabs.Any());
            }
        }
Exemplo n.º 9
0
        public void FindAllReferences_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 FindAllReferencesCommand(null, null, parser.State, vbe.Object, vm, null);

            command.Execute(null);

            Assert.IsFalse(vm.Tabs.Any());
        }
Exemplo n.º 10
0
        public void FindAllReferences_NoResults_DisplayMessageBox()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub";

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

            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 FindAllReferencesCommand(null, messageBox.Object, state, vbe.Object, vm, null);

                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);
            }
        }
Exemplo n.º 11
0
        public void FindAllReferences_FormNoResults_DisplaysMessageBox()
        {
            var code    = @"
Public Sub DoSomething()
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).Build();

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

            vbe.SetupGet(v => v.SelectedVBComponent).Returns(form.Object);

            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new DeclarationFinderFactory()));

            AssertParserReady(parser);

            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 FindAllReferencesCommand(null, messageBox.Object, parser.State, vbe.Object, vm, null);
            var target  = parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "Form1");

            command.Execute(target);

            messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(),
                                          It.IsAny <MessageBoxIcon>()), Times.Once);
        }
Exemplo n.º 12
0
        public void FindAllReferences_ControlSingleResult_Navigates()
        {
            var code    = @"
Public Sub DoSomething()
    TextBox1.Height = 20
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).AddControl("TextBox1").Build();

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

            vbe.SetupGet(v => v.SelectedVBComponent).Returns(form.Object);

            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new DeclarationFinderFactory()));

            AssertParserReady(parser);
            var navigateCommand = new Mock <INavigateCommand>();

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllReferencesCommand(navigateCommand.Object, null, parser.State, vbe.Object, vm, null);
            var target  = parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "TextBox1");

            command.Execute(target);

            navigateCommand.Verify(n => n.Execute(It.IsAny <object>()), Times.Once);
        }
Exemplo n.º 13
0
        public void FindAllReferences_ControlMultipleResults_ReturnsCorrectNumber()
        {
            var code    = @"
Public Sub DoSomething()
    TextBox1.Height = 20
    TextBox1.Width = 200
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).AddControl("TextBox1").Build();

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

            vbe.SetupGet(v => v.SelectedVBComponent).Returns(form.Object);

            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new DeclarationFinderFactory()));

            AssertParserReady(parser);

            var vm      = new SearchResultsWindowViewModel();
            var command = new FindAllReferencesCommand(null, null, parser.State, vbe.Object, vm, null);
            var target  = parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "TextBox1");

            command.Execute(target);

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

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleStandardModule(inputCode, out component);
            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 FindAllReferencesCommand(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);
        }
Exemplo n.º 15
0
        public void FindAllReferences_ReferenceSelected_ReturnsCorrectNumber()
        {
            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, new Selection(5, 5, 5, 5));
            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 FindAllReferencesCommand(null, null, parser.State, vbe.Object, vm, null);

            command.Execute(null);

            Assert.AreEqual(4, vm.Tabs[0].SearchResults.Count);
        }
Exemplo n.º 16
0
        public void FindAllReferences_NullTarget_Aborts()
        {
            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 FindAllReferencesCommand(null, null, state, vbe.Object, vm, null);

            command.Execute(null);

            Assert.IsFalse(vm.Tabs.Any());
        }
Exemplo n.º 17
0
        public void FindAllReferences_NoResults_DisplayMessageBox()
        {
            const string inputCode =
                @"Public Sub Foo()
End Sub";

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

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

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

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

                messageBox.Verify(m => m.NotifyWarn(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            }
        }
Exemplo n.º 18
0
        public void FindAllReferences_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 FindAllReferencesCommand(null, null, parser.State, vbe.Object, vm, null);

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

            Assert.IsFalse(vm.Tabs.Any());
        }