private void State_StateChanged(object sender, ParserStateEventArgs e)
        {
            if (e.State != ParserState.ResolvedDeclarations)
            {
                return;
            }

            _dispatcher.Invoke(() =>
            {
                var tests = UnitTestHelpers.GetAllTests(_vbe, _state).ToList();

                var removedTests = Tests.Where(test =>
                                               !tests.Any(t =>
                                                          t.Declaration.ComponentName == test.Declaration.ComponentName &&
                                                          t.Declaration.IdentifierName == test.Declaration.IdentifierName &&
                                                          t.Declaration.ProjectId == test.Declaration.ProjectId)).ToList();

                // remove old tests
                foreach (var test in removedTests)
                {
                    Tests.Remove(test);
                }

                // update declarations for existing tests--declarations are immutable
                foreach (var test in Tests.Except(removedTests))
                {
                    var declaration = tests.First(t =>
                                                  t.Declaration.ComponentName == test.Declaration.ComponentName &&
                                                  t.Declaration.IdentifierName == test.Declaration.IdentifierName &&
                                                  t.Declaration.ProjectId == test.Declaration.ProjectId).Declaration;

                    test.SetDeclaration(declaration);
                }

                // add new tests
                foreach (var test in tests)
                {
                    if (!Tests.Any(t =>
                                   t.Declaration.ComponentName == test.Declaration.ComponentName &&
                                   t.Declaration.IdentifierName == test.Declaration.IdentifierName &&
                                   t.Declaration.ProjectId == test.Declaration.ProjectId))
                    {
                        Tests.Add(test);
                    }
                }
            });
        }
示例#2
0
        public void Discovery_IgnoresNonAnnotatedTestMethods()
        {
            var testMethods = @"Public Sub TestMethod1()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none)
                          .AddComponent("TestModule1", vbext_ComponentType.vbext_ct_StdModule, GetTestModuleInput + testMethods);

            var vbe      = builder.AddProject(project.Build()).Build();
            var mockHost = new Mock <IHostApplication>();

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

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

            Assert.IsFalse(UnitTestHelpers.GetAllTests(vbe.Object, parser.State).Any());
        }