Esempio n. 1
0
        public void UISetsProgressBarColor_LimeGreenForSuccess_IncludesIgnoredTests()
        {
            var testMethods = @"'@TestMethod
Public Sub TestMethod1()
End Sub

'@TestMethod
Public Sub TestMethod2()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetTestModuleInput + testMethods);

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

            var model = new TestExplorerModel(vbe, parser.State);

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

            model.Tests[0].Result = new TestResult(TestOutcome.Succeeded);
            model.Tests[1].Result = new TestResult(TestOutcome.Ignored);

            model.AddExecutedTest(model.Tests[0]);
            model.AddExecutedTest(model.Tests[1]);

            Assert.AreEqual(model.ProgressBarColor, Colors.LimeGreen);
        }
Esempio n. 2
0
        public void UISetsProgressBarColor_RedForFailure_IncludesNonFailingTests()
        {
            var testMethods = @"'@TestMethod
Public Sub TestMethod1()
End Sub

'@TestMethod
Public Sub TestMethod2()
End Sub

'@TestMethod
Public Sub TestMethod3()
End Sub

'@TestMethod
Public Sub TestMethod4()
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(new Mock <ISinks>().Object));

            var model = new TestExplorerModel(vbe.Object, parser.State);

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

            model.Tests[0].Result = new TestResult(TestOutcome.Succeeded);
            model.Tests[1].Result = new TestResult(TestOutcome.Inconclusive);
            model.Tests[2].Result = new TestResult(TestOutcome.Failed);
            model.Tests[3].Result = new TestResult(TestOutcome.Ignored);

            model.AddExecutedTest(model.Tests[0]);
            model.AddExecutedTest(model.Tests[1]);
            model.AddExecutedTest(model.Tests[2]);
            model.AddExecutedTest(model.Tests[3]);

            Assert.AreEqual(model.ProgressBarColor, Colors.Red);
        }
Esempio n. 3
0
        public void ClearLastRun()
        {
            var testMethods = @"'@TestMethod
Public Sub TestMethod1()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetTestModuleInput + testMethods);

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

            var model = new TestExplorerModel(vbe, parser.State);

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

            model.Tests[0].Result = new TestResult(TestOutcome.Succeeded);
            model.AddExecutedTest(model.Tests[0]);

            Assert.AreEqual(1, model.LastRun.Count);

            model.ClearLastRun();

            Assert.AreEqual(0, model.LastRun.Count);
        }
Esempio n. 4
0
        public void AddingExecutedTestUpdatesLastRun()
        {
            var testMethods = @"'@TestMethod
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(new Mock <ISinks>().Object));

            var model = new TestExplorerModel(vbe.Object, parser.State);

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

            Assert.AreEqual(0, model.LastRun.Count);

            model.Tests[0].Result = new TestResult(TestOutcome.Succeeded);
            model.AddExecutedTest(model.Tests[0]);

            Assert.AreEqual(1, model.LastRun.Count);
        }
Esempio n. 5
0
        public void UISetsProgressBarColor_GoldForInconclusive()
        {
            var testMethods = @"'@TestMethod
Public Sub TestMethod1()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetTestModuleInput + testMethods);

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

            using (var state = parser.State)
            {
                var model = new TestExplorerModel(vbe, state);

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

                model.Tests.First().Result = new TestResult(TestOutcome.Inconclusive);
                model.AddExecutedTest(model.Tests.First());

                Assert.AreEqual(model.ProgressBarColor, Colors.Gold);
            }
        }
Esempio n. 6
0
        public void UISetsProgressBarColor_LimeGreenForSuccess()
        {
            var testMethods = @"'@TestMethod
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());

            var model = new TestExplorerModel(vbe.Object, parser.State);

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

            model.Tests.First().Result = new TestResult(TestOutcome.Succeeded);
            model.AddExecutedTest(model.Tests.First());

            Assert.AreEqual(model.ProgressBarColor, Colors.LimeGreen);
        }
Esempio n. 7
0
        public void Run(IEnumerable <TestMethod> tests)
        {
            var testMethods = tests as IList <TestMethod> ?? tests.ToList();

            if (!testMethods.Any())
            {
                return;
            }

            var modules = testMethods.GroupBy(test => test.Declaration.QualifiedName.QualifiedModuleName);

            foreach (var module in modules)
            {
                var testInitialize = module.Key.FindTestInitializeMethods(_state).ToList();
                var testCleanup    = module.Key.FindTestCleanupMethods(_state).ToList();

                var capturedModule    = module;
                var moduleTestMethods = testMethods
                                        .Where(test => test.Declaration.QualifiedName.QualifiedModuleName.ProjectId == capturedModule.Key.ProjectId &&
                                               test.Declaration.QualifiedName.QualifiedModuleName.ComponentName == capturedModule.Key.ComponentName);

                Run(module.Key.FindModuleInitializeMethods(_state));
                foreach (var test in moduleTestMethods)
                {
                    // no need to run setup/teardown for ignored tests
                    if (test.Declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.IgnoreTest))
                    {
                        test.UpdateResult(TestOutcome.Ignored);
                        OnTestCompleted();
                        continue;
                    }

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    Run(testInitialize);
                    test.Run();
                    Run(testCleanup);

                    stopwatch.Stop();
                    test.Result.SetDuration(stopwatch.ElapsedMilliseconds);

                    OnTestCompleted();
                    _model.AddExecutedTest(test);
                }
                Run(module.Key.FindModuleCleanupMethods(_state));
            }
        }