public void Menu_item_should_be_enabled_if_command_can_execute()
        {
            var menuCommand = new MenuCommand { CanExecute = new Observable<bool>(true) };

            var menuItem = new CommandToolStripMenuItem(menuCommand);

            Assert.IsTrue(menuItem.Enabled);
        }
        public void Menu_item_text_should_match_command()
        {
            var menuCommand = new MenuCommand { Text = "someText" };

            var menuItem = new CommandToolStripMenuItem(menuCommand);

            Assert.AreEqual(menuItem.Text, menuCommand.Text);
        }
        public void Menu_item_should_run_command_when_clicked()
        {
            var command = MockRepository.GenerateStub<ICommand>();
            var menuCommand = new MenuCommand { Command = command };
            var menuItem = new CommandToolStripMenuItem(menuCommand);

            menuItem.PerformClick();

            command.AssertWasCalled(c => c.Execute(Arg<IProgressMonitor>.Is.Anything));
        }
        public void Menu_item_should_become_enabled_if_command_can_execute()
        {
            var canExecute = new Observable<bool>();
            var menuCommand = new MenuCommand { CanExecute = canExecute };
            var menuItem = new CommandToolStripMenuItem(menuCommand);
            Assert.IsFalse(menuItem.Enabled);

            canExecute.Value = true;

            Assert.IsTrue(menuItem.Enabled);
        }
        public void Menu_item_image_should_come_from_command()
        {
            var menuCommand = new MenuCommand();
            var menuItem = new CommandToolStripMenuItem(menuCommand);
            Assert.IsNull(menuItem.Image);

            var image = new Bitmap(1, 1);
            menuCommand.Image = image;
            menuItem = new CommandToolStripMenuItem(menuCommand);

            Assert.AreEqual(image, menuItem.Image);
        }
        ///<summary>
        /// Constructor providing a command, task manager and keys parser.
        ///</summary>
        ///<param name="command">The command to use.</param>
        ///<param name="taskManager">The task manager to use.</param>
        ///<param name="keysParser">The keys parser to use.</param>
        public CommandToolStripMenuItem(MenuCommand command, ITaskManager taskManager, IKeysParser keysParser)
            : base(command.Text, command.Image)
        {
            Enabled = command.CanExecute;
            command.CanExecute.PropertyChanged += (s, e) => Enabled = command.CanExecute;

            if (taskManager != null)
                Click += (s, e) => taskManager.QueueTask(command.Command);
            else
                Click += (s, e) => command.Command.Execute(NullProgressMonitor.CreateInstance());

            if (!string.IsNullOrEmpty(command.Shortcut))
                ShortcutKeys = keysParser.Parse(command.Shortcut.Replace(" ", ""));
        }
Ejemplo n.º 7
0
        public ReportsNode(IProjectTreeModel projectTreeModel, 
            IFileSystem fileSystem)
        {
            // TODO: i18n
            Text = "Reports";
            Image = Properties.Resources.Report.ToBitmap();

            var deleteAllReportsCommand = new MenuCommand
            {
                Command = new DeleteAllReportsCommand(projectTreeModel, fileSystem),
                Text = "Delete all reports"
            };
            Commands = new List<MenuCommand> { deleteAllReportsCommand };
        }
Ejemplo n.º 8
0
        public void SetUp()
        {
            windowManager = TestWindowManager.Create();

            menuManager = MockRepository.GenerateStub<IMenuManager>();
            windowManager.Stub(wm => wm.MenuManager).Return(menuManager);
            menuManager.Stub(mm => mm.Add(Arg<string>.Is.Anything, Arg<Func<MenuCommand>>.Is.Anything))
                .Do((Action<string, Func<MenuCommand>>)((m, f) => menuCommand = f()));

        	var testExplorerController = MockRepository.GenerateStub<ITestExplorerController>();
        	var testExplorerModel = MockRepository.GenerateStub<ITestExplorerModel>();
        	
			package = new TestExplorerPackage(windowManager, testExplorerController, testExplorerModel);
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            windowManager = MockRepository.GenerateStub<IWindowManager>();
            windowManager.Stub(wm => wm.Register(Arg<string>.Is.Anything, Arg<Action>.Is.Anything, Arg<Location>.Is.Anything))
                .Do((Action<string, Action, Location>)((i, a, l) => a()));

            menuManager = MockRepository.GenerateStub<IMenuManager>();
            windowManager.Stub(wm => wm.MenuManager).Return(menuManager);
            menuManager.Stub(mm => mm.Add(Arg<string>.Is.Anything, Arg<Func<MenuCommand>>.Is.Anything))
                .Do((Action<string, Func<MenuCommand>>)((m, f) => menuCommand = f()));

            var runtimeLogController = MockRepository.GenerateStub<IRuntimeLogController>();

            runtimeLogPackage = new RuntimeLogPackage(windowManager, runtimeLogController);
        }
        public void SetUp()
        {
            windowManager = TestWindowManager.Create();

            menuManager = MockRepository.GenerateStub<IMenuManager>();
            windowManager.Stub(wm => wm.MenuManager).Return(menuManager);
            menuManager.Stub(mm => mm.Add(Arg<string>.Is.Anything, Arg<Common.Func<MenuCommand>>.Is.Anything))
                .Do((Common.Action<string, Common.Func<MenuCommand>>)((m, f) => menuCommand = f()));

            var testResultsController = MockRepository.GenerateStub<ITestResultsController>();
            var optionsController = MockRepository.GenerateStub<IOptionsController>();
            var testTreeModel = MockRepository.GenerateStub<ITestTreeModel>();
            var testStatistics = new TestStatistics();

            package = new TestResultsPackage(windowManager, testResultsController, optionsController, testTreeModel, testStatistics);
        }
        public void SetUp()
        {
            windowManager = TestWindowManager.Create();

            menuManager = MockRepository.GenerateStub<IMenuManager>();
            windowManager.Stub(wm => wm.MenuManager).Return(menuManager);
            menuManager.Stub(mm => mm.Add(Arg<string>.Is.Anything, Arg<Func<MenuCommand>>.Is.Anything))
                .Do((Action<string, Func<MenuCommand>>)((m, f) => menuCommand = f()));

            var projectController = MockRepository.GenerateStub<IProjectController>();
            var reportController = MockRepository.GenerateStub<IReportController>();
            var taskManager = MockRepository.GenerateStub<ITaskManager>();
        	var commandFactory = MockRepository.GenerateStub<ICommandFactory>();
        	
			package = new ProjectExplorerPackage(windowManager, projectController, reportController, taskManager, commandFactory);
        }
 /// <summary>
 /// Constructor providing a command and task manager.
 /// </summary>
 /// <remarks>
 /// When clicked, the command will be queued with the 
 /// supplied task manager.
 /// </remarks>
 /// <param name="command">The command to use.</param>
 /// <param name="taskManager">The task manager to use.</param>
 public CommandToolStripMenuItem(MenuCommand command, ITaskManager taskManager)
     : this(command, taskManager, new KeysParser())
 { }
 ///<summary>
 /// Constructor providing a menu command.
 ///</summary>
 /// <remarks>
 /// When clicked, the command will be run synchronously.
 /// </remarks>
 ///<param name="command">The command to use.</param>
 public CommandToolStripMenuItem(MenuCommand command)
     : this(command, null)
 { }
Ejemplo n.º 14
0
 public void Add(MenuCommand menuCommand)
 {
     var menuItem = new CommandToolStripMenuItem(menuCommand);
     item.DropDownItems.Add(menuItem);
 }
        public void Menu_item_should_run_command_with_task_manager_if_provided_when_clicked()
        {
            var command = MockRepository.GenerateStub<ICommand>();
            var menuCommand = new MenuCommand { Command = command };
            var taskManager = MockRepository.GenerateStub<ITaskManager>();
            var menuItem = new CommandToolStripMenuItem(menuCommand, taskManager);

            menuItem.PerformClick();

            taskManager.AssertWasCalled(tm => tm.QueueTask(command));
        }
        public void Menu_shortcut_should_be_set_if_provided()
        {
            const string shortcut = "S";
            var menuCommand = new MenuCommand { Shortcut = shortcut };
            var keysParser = MockRepository.GenerateStub<IKeysParser>();

            new CommandToolStripMenuItem(menuCommand, null, keysParser);

            keysParser.AssertWasCalled(kp => kp.Parse(shortcut));
        }