public void AddsTest_NullActiveCodePane()
        {
            var input = @"
Option Explicit
Option Private Module

'@TestModule
Private Assert As Object
";

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

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

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var addTestMethodCommand = new AddTestMethodCommand(vbe.Object, state);

                addTestMethodCommand.Execute(null);
                var module = component.CodeModule;

                Assert.AreEqual(input, module.Content());
            }
        }
        public void AddsTestPicksNextNumberAccountsForNonTests()
        {
            var input = @"
Option Explicit
Option Private Module

'@TestModule

Private Assert As Object
Public Function TestMethod1() As Long
End Function
'@TestMethod
Public Sub TestMethod2()
End Sub
{0}";

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleStandardModule(string.Format(input, string.Empty), out component);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var addTestMethodCommand = new AddTestMethodCommand(vbe.Object, state);

                addTestMethodCommand.Execute(null);
                var module = component.CodeModule;

                var expected = string.Format(input,
                                             AddTestMethodCommand.TestMethodTemplate.Replace(AddTestMethodCommand.NamePlaceholder,
                                                                                             "TestMethod3")) +
                               Environment.NewLine;
                var actual = module.Content();
                Assert.AreEqual(expected, actual);
            }
        }
Exemplo n.º 3
0
        public void AddsTest_NullActiveCodePane()
        {
            var input =
                @"Option Explicit
Option Private Module


'@TestModule
Private Assert As Object
";

            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe = builder.BuildFromSingleStandardModule(input, out component);

            vbe.Setup(s => s.ActiveCodePane).Returns((CodePane)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 addTestMethodCommand = new AddTestMethodCommand(vbe.Object, parser.State);

            addTestMethodCommand.Execute(null);

            Assert.AreEqual(input, component.CodeModule.Lines());
        }
        public void AddsTest()
        {
            var input = @"
Option Explicit
Option Private Module

'@TestModule

Private Assert As Object
{0}";

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleStandardModule(string.Format(input, string.Empty), out component);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var addTestMethodCommand = new AddTestMethodCommand(vbe.Object, state);

                addTestMethodCommand.Execute(null);
                var module = component.CodeModule;

                Assert.AreEqual(
                    string.Format(input,
                                  AddTestMethodCommand.TestMethodTemplate.Replace(AddTestMethodCommand.NamePlaceholder, "TestMethod1")) +
                    Environment.NewLine, module.Content());
            }
        }
Exemplo n.º 5
0
        public void AddsTest()
        {
            var input =
                @"Option Explicit
Option Private Module


'@TestModule
Private Assert As Object
{0}";

            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleStandardModule(string.Format(input, string.Empty), 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 addTestMethodCommand = new AddTestMethodCommand(vbe.Object, parser.State);

            addTestMethodCommand.Execute(null);

            Assert.AreEqual(
                string.Format(input,
                              AddTestMethodCommand.TestMethodTemplate.Replace(AddTestMethodCommand.NamePlaceholder, "TestMethod1")) +
                Environment.NewLine, component.CodeModule.Lines());
        }
Exemplo n.º 6
0
        public void AddTest_CanExecute_NoTestModule()
        {
            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(string.Empty, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var addTestMethodCommand = new AddTestMethodCommand(vbe.Object, state);

            Assert.IsFalse(addTestMethodCommand.CanExecute(null));
        }
Exemplo n.º 7
0
        public void AddTest_CanExecute_NonReadyState()
        {
            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(string.Empty, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            state.SetStatusAndFireStateChanged(this, ParserState.ResolvingReferences);

            var addTestMethodCommand = new AddTestMethodCommand(vbe.Object, state);

            Assert.IsFalse(addTestMethodCommand.CanExecute(null));
        }
Exemplo n.º 8
0
        public TestExplorerViewModel(IVBE vbe,
                                     RubberduckParserState state,
                                     ITestEngine testEngine,
                                     TestExplorerModel model,
                                     IClipboardWriter clipboard,
                                     IGeneralConfigService configService,
                                     ISettingsFormFactory settingsFormFactory,
                                     IMessageBox messageBox)
        {
            _vbe        = vbe;
            _state      = state;
            _testEngine = testEngine;
            _testEngine.TestCompleted += TestEngineTestCompleted;
            Model                = model;
            _clipboard           = clipboard;
            _settingsFormFactory = settingsFormFactory;
            _messageBox          = messageBox;

            _navigateCommand = new NavigateCommand(_state.ProjectsProvider);

            RunAllTestsCommand = new RunAllTestsCommand(vbe, state, testEngine, model, null);
            RunAllTestsCommand.RunCompleted += RunCompleted;

            AddTestModuleCommand      = new AddTestModuleCommand(vbe, state, configService, _messageBox);
            AddTestMethodCommand      = new AddTestMethodCommand(vbe, state);
            AddErrorTestMethodCommand = new AddTestMethodExpectedErrorCommand(vbe, state);

            RefreshCommand              = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRefreshCommand, CanExecuteRefreshCommand);
            RepeatLastRunCommand        = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRepeatLastRunCommand, CanExecuteRepeatLastRunCommand);
            RunNotExecutedTestsCommand  = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunNotExecutedTestsCommand, CanExecuteRunNotExecutedTestsCommand);
            RunInconclusiveTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunInconclusiveTestsCommand, CanExecuteRunInconclusiveTestsCommand);
            RunFailedTestsCommand       = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunFailedTestsCommand, CanExecuteRunFailedTestsCommand);
            RunPassedTestsCommand       = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunPassedTestsCommand, CanExecuteRunPassedTestsCommand);
            RunSelectedTestCommand      = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSelectedTestCommand, CanExecuteSelectedTestCommand);

            CopyResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCopyResultsCommand);

            OpenTestSettingsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), OpenSettings);

            SetOutcomeGroupingCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
            {
                GroupByOutcome  = (bool)param;
                GroupByLocation = !(bool)param;
            });

            SetLocationGroupingCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
            {
                GroupByLocation = (bool)param;
                GroupByOutcome  = !(bool)param;
            });
        }
Exemplo n.º 9
0
        public TestExplorerViewModel(VBE vbe,
                                     RubberduckParserState state,
                                     ITestEngine testEngine,
                                     TestExplorerModel model,
                                     IClipboardWriter clipboard,
                                     NewUnitTestModuleCommand newTestModuleCommand,
                                     NewTestMethodCommand newTestMethodCommand,
                                     IGeneralConfigService configService,
                                     IOperatingSystem operatingSystem)
        {
            _state      = state;
            _testEngine = testEngine;
            _testEngine.TestCompleted += TestEngineTestCompleted;
            _model           = model;
            _clipboard       = clipboard;
            _configService   = configService;
            _operatingSystem = operatingSystem;

            _navigateCommand = new NavigateCommand();

            _runAllTestsCommand = new RunAllTestsCommand(state, testEngine, model);
            _runAllTestsCommand.RunCompleted += RunCompleted;

            _addTestModuleCommand      = new AddTestModuleCommand(vbe, state, newTestModuleCommand);
            _addTestMethodCommand      = new AddTestMethodCommand(vbe, state, newTestMethodCommand);
            _addErrorTestMethodCommand = new AddTestMethodExpectedErrorCommand(vbe, state, newTestMethodCommand);

            _refreshCommand             = new DelegateCommand(ExecuteRefreshCommand, CanExecuteRefreshCommand);
            _repeatLastRunCommand       = new DelegateCommand(ExecuteRepeatLastRunCommand, CanExecuteRepeatLastRunCommand);
            _runNotExecutedTestsCommand = new DelegateCommand(ExecuteRunNotExecutedTestsCommand, CanExecuteRunNotExecutedTestsCommand);
            _runFailedTestsCommand      = new DelegateCommand(ExecuteRunFailedTestsCommand, CanExecuteRunFailedTestsCommand);
            _runPassedTestsCommand      = new DelegateCommand(ExecuteRunPassedTestsCommand, CanExecuteRunPassedTestsCommand);
            _runSelectedTestCommand     = new DelegateCommand(ExecuteSelectedTestCommand, CanExecuteSelectedTestCommand);

            _copyResultsCommand = new DelegateCommand(ExecuteCopyResultsCommand);

            _openTestSettingsCommand = new DelegateCommand(OpenSettings);

            _setOutcomeGroupingCommand = new DelegateCommand(param =>
            {
                GroupByOutcome  = (bool)param;
                GroupByLocation = !(bool)param;
            });

            _setLocationGroupingCommand = new DelegateCommand(param =>
            {
                GroupByLocation = (bool)param;
                GroupByOutcome  = !(bool)param;
            });
        }
Exemplo n.º 10
0
        public void AddTest_CanExecute()
        {
            var input = @"
Option Explicit
Option Private Module

'@TestModule
Private Assert As Object
";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(input, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var addTestMethodCommand = new AddTestMethodCommand(vbe.Object, state);

            Assert.IsTrue(addTestMethodCommand.CanExecute(null));
        }
Exemplo n.º 11
0
        public void AddTest_CanExecute_NoTestModule()
        {
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleStandardModule("", 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 addTestMethodCommand = new AddTestMethodCommand(vbe.Object, parser.State);

            Assert.IsFalse(addTestMethodCommand.CanExecute(null));
        }
        public TestExplorerViewModel(VBE vbe, ITestEngine testEngine, TestExplorerModelBase model, IClipboardWriter clipboard)
        {
            _testEngine = testEngine;
            _testEngine.TestCompleted += TestEngineTestCompleted;
            _model     = model;
            _clipboard = clipboard;

            _navigateCommand = new NavigateCommand();

            _runAllTestsCommand        = new RunAllTestsCommand(testEngine, model);
            _addTestModuleCommand      = new AddTestModuleCommand(vbe);
            _addTestMethodCommand      = new AddTestMethodCommand(vbe, model);
            _addErrorTestMethodCommand = new AddTestMethodExpectedErrorCommand(vbe, model);

            _refreshCommand             = new DelegateCommand(ExecuteRefreshCommand, CanExecuteRefreshCommand);
            _repeatLastRunCommand       = new DelegateCommand(ExecuteRepeatLastRunCommand, CanExecuteRepeatLastRunCommand);
            _runNotExecutedTestsCommand = new DelegateCommand(ExecuteRunNotExecutedTestsCommand, CanExecuteRunNotExecutedTestsCommand);
            _runFailedTestsCommand      = new DelegateCommand(ExecuteRunFailedTestsCommand, CanExecuteRunFailedTestsCommand);
            _runPassedTestsCommand      = new DelegateCommand(ExecuteRunPassedTestsCommand, CanExecuteRunPassedTestsCommand);
            _runSelectedTestCommand     = new DelegateCommand(ExecuteSelectedTestCommand, CanExecuteSelectedTestCommand);

            _copyResultsCommand = new DelegateCommand(ExecuteCopyResultsCommand);
        }
Exemplo n.º 13
0
 public AddTestMethodCommandMenuItem(AddTestMethodCommand command)
     : base(command)
 {
 }