Beispiel #1
0
        public void Should_ShowToolWindow_When_Invoked()
        {
            var package = Substitute.For <IPackage>();

            var command = new ShowToolWindowCommand(package);

            command.MenuCommand.Invoke();

            package.Received().ShowToolWindow();
        }
        public void Execute_ServiceCalled()
        {
            var logger = new TestLogger(logToConsole: true);
            var toolwindowServiceMock = new Mock <IToolWindowService>();

            var testSubject = new ShowToolWindowCommand(ValidCommandId, ValidToolWindowId, toolwindowServiceMock.Object, Mock.Of <IMenuCommandService>(), logger);

            // Act
            testSubject.Execute(null, null);

            toolwindowServiceMock.Verify(x => x.Show(ValidToolWindowId), Times.Once);
            logger.AssertNoOutputMessages();
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken,
                                                      IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await ShowToolWindowCommand.InitializeAsync(this);

            await CmmnSearchCommand.InitializeAsync(this);
        }
        public void Execute_NonCriticalException_IsSuppressed()
        {
            var logger = new TestLogger(logToConsole: true);
            var toolwindowServiceMock = new Mock <IToolWindowService>();

            toolwindowServiceMock.Setup(x => x.Show(ValidToolWindowId)).Throws(new InvalidOperationException("thrown by test"));

            var testSubject = new ShowToolWindowCommand(ValidCommandId, ValidToolWindowId, toolwindowServiceMock.Object, Mock.Of <IMenuCommandService>(), logger);

            // Act
            testSubject.Execute(null, null);

            toolwindowServiceMock.Verify(x => x.Show(ValidToolWindowId), Times.Once);
            logger.AssertPartialOutputStringExists(ValidToolWindowId.ToString(), "thrown by test");
        }
        public void Execute_CriticalException_IsNotSuppressed()
        {
            var logger = new TestLogger(logToConsole: true);
            var toolwindowServiceMock = new Mock <IToolWindowService>();

            toolwindowServiceMock.Setup(x => x.Show(ValidToolWindowId)).Throws(new StackOverflowException("thrown by test"));

            var testSubject = new ShowToolWindowCommand(ValidCommandId, ValidToolWindowId, toolwindowServiceMock.Object, Mock.Of <IMenuCommandService>(), logger);

            // Act
            Action act = () => testSubject.Execute(null, null);

            act.Should().ThrowExactly <StackOverflowException>().And.Message.Should().Be("thrown by test");
            logger.AssertNoOutputMessages();
        }
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            var logger = componentModel.GetService <ILogger>();

            logger.WriteLine(Resources.StartedPackageInitialization);

            // We're not storing references to the command handler instances.
            // We relying on the fact that the command handler instance registers a
            // callback with the menu service to stop it from being garbage collected.
            await ShowToolWindowCommand.CreateAsync(this,
                                                    new CommandID(Constants.CommandSetGuid, Constants.HotspotsToolWindowCommandId),
                                                    HotspotsToolWindow.ToolWindowId);

            await ShowToolWindowCommand.CreateAsync(this,
                                                    new CommandID(Constants.CommandSetGuid, Constants.TaintToolWindowCommandId),
                                                    TaintToolWindow.ToolWindowId);

            logger.WriteLine(Resources.FinishedPackageInitialization);
        }
Beispiel #7
0
        public void Should_Throw_When_PackageIsNull()
        {
            var command = new ShowToolWindowCommand(null);

            Assert.IsNull(command);
        }