Пример #1
0
        public void FindAllReferences_CanExecute_StateNotReady()
        {
            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));

                Assert.IsFalse(command.CanExecute(state.AllUserDeclarations.Single(s => s.IdentifierName == "Foo")));
            }
        }
Пример #2
0
        public void FindAllReferences_ControlMultipleSelection_IsNotEnabled()
        {
            var code    = @"
Public Sub DoSomething()
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).AddControl("TextBox1").AddControl("TextBox2").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 targets      = state.AllUserDeclarations.Where(s => s.IdentifierName.StartsWith("TextBox"));
                var uiDispatcher = new Mock <IUiDispatcher>();
                var command      = new FindAllReferencesCommand(state, vbe.Object, null, new FindAllReferencesService(null, null, state, null, null, uiDispatcher.Object));

                Assert.IsFalse(command.CanExecute(targets));
            }
        }
Пример #3
0
        public void FindAllReferences_ControlMultipleSelection_IsNotEnabled()
        {
            var code    = @"
Public Sub DoSomething()
End Sub
";
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected);
            var form    = project.MockUserFormBuilder("Form1", code).AddControl("TextBox1").AddControl("TextBox2").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 targets = parser.State.AllUserDeclarations.Where(s => s.IdentifierName.StartsWith("TextBox"));
            var command = new FindAllReferencesCommand(null, null, parser.State, vbe.Object, null, null);


            Assert.IsFalse(command.CanExecute(targets));
        }
Пример #4
0
        public void FindAllReferences_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 FindAllReferencesCommand(null, null, state, vbe.Object, vm, null);

            Assert.IsFalse(command.CanExecute(null));
        }
Пример #5
0
        public void FindAllReferences_CanExecute_NullActiveCodePane()
        {
            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 FindAllReferencesCommand(state, vbe.Object, vm, new FindAllReferencesService(null, null, state, vm, null, uiDispatcher.Object));

                Assert.IsFalse(command.CanExecute(null));
            }
        }
Пример #6
0
        public void FindAllReferences_CanExecute_NullActiveCodePane()
        {
            //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);

            Assert.IsFalse(command.CanExecute(null));
        }
Пример #7
0
        public void FindAllReferences_CanExecute_StateNotReady()
        {
            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);

            Assert.IsFalse(command.CanExecute(parser.State.AllUserDeclarations.Single(s => s.IdentifierName == "Foo")));
        }