public void TelemetryLoggerAccessor_GetLogger() { // Arrange ConfigurableServiceProvider sp = new ConfigurableServiceProvider(); var loggerInstance = new ConfigurableTelemetryLogger(); var componentModel = ConfigurableComponentModel.CreateWithExports( MefTestHelpers.CreateExport <ITelemetryLogger>(loggerInstance)); sp.RegisterService(typeof(SComponentModel), componentModel); // Act ITelemetryLogger logger = TelemetryLoggerAccessor.GetLogger(sp); // Assert logger.Should().Be(loggerInstance, "Failed to find the MEF service: {0}", nameof(ITelemetryLogger)); }
private TaggerProvider CreateTaggerProvider() { var tableManagerProviderMock = new Mock <ITableManagerProvider>(); tableManagerProviderMock.Setup(t => t.GetTableManager(StandardTables.ErrorsTable)) .Returns(new Mock <ITableManager>().Object); var textDocFactoryServiceMock = new Mock <ITextDocumentFactoryService>(); var settingsMock = new Mock <ISonarLintSettings>(); var contentTypeRegistryServiceMock = new Mock <IContentTypeRegistryService>(); contentTypeRegistryServiceMock.Setup(c => c.ContentTypes).Returns(Enumerable.Empty <IContentType>()); var fileExtensionRegistryServiceMock = new Mock <IFileExtensionRegistryService>(); var languageRecognizer = new SonarLanguageRecognizer(contentTypeRegistryServiceMock.Object, fileExtensionRegistryServiceMock.Object); // DTE object setup var mockProject = new Mock <Project>(); mockProject.Setup(p => p.Name).Returns("MyProject"); var project = mockProject.Object; var mockProjectItem = new Mock <ProjectItem>(); mockProjectItem.Setup(s => s.ContainingProject).Returns(project); var projectItem = mockProjectItem.Object; var mockSolution = new Mock <Solution>(); mockSolution.Setup(s => s.FindProjectItem(It.IsAny <string>())).Returns(projectItem); var solution = mockSolution.Object; var mockDTE = new Mock <DTE>(); mockDTE.Setup(d => d.Solution).Returns(solution); var dte = mockDTE.Object; var serviceProvider = new ConfigurableServiceProvider(); serviceProvider.RegisterService(typeof(DTE), mockDTE.Object); var provider = new TaggerProvider(tableManagerProviderMock.Object, textDocFactoryServiceMock.Object, daemonMock.Object, serviceProvider, settingsMock.Object, languageRecognizer, new TestLogger()); return(provider); }
public void VsShellUtils_ActivateSolutionExplorer() { // Setup var serviceProvider = new ConfigurableServiceProvider(); var dteMock = new DTEMock(); serviceProvider.RegisterService(typeof(DTE), dteMock); // Sanity Assert.IsFalse(dteMock.ToolWindows.SolutionExplorer.Window.Active); // Act VsShellUtils.ActivateSolutionExplorer(serviceProvider); // Verify Assert.IsTrue(dteMock.ToolWindows.SolutionExplorer.Window.Active, "Expected to become Active"); }
public void VsShellUtils_ActivateSolutionExplorer() { // Arrange var serviceProvider = new ConfigurableServiceProvider(); var dteMock = new DTEMock(); serviceProvider.RegisterService(typeof(DTE), dteMock); // Sanity dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse(); // Act VsShellUtils.ActivateSolutionExplorer(serviceProvider); // Assert dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeTrue("Expected to become Active"); }
public void VsShellUtils_SaveSolution_Silent() { // Setup var serviceProvider = new ConfigurableServiceProvider(); var solution = new SolutionMock(); serviceProvider.RegisterService(typeof(SVsSolution), solution); solution.SaveSolutionElementAction = (options, hierarchy, docCookie) => { Assert.AreEqual(__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, (__VSSLNSAVEOPTIONS)options, "Unexpected save options"); Assert.IsNull(hierarchy, "Expecting the scope to be the whole solution"); Assert.AreEqual(0U, docCookie, "Expecting the scope to be the whole solution"); return(VSConstants.S_OK); }; // Act + Verify Assert.IsTrue(VsShellUtils.SaveSolution(serviceProvider, silent: true)); }
public void VsShellUtils_SaveSolution_Silent() { // Arrange var serviceProvider = new ConfigurableServiceProvider(); var solution = new SolutionMock(); serviceProvider.RegisterService(typeof(SVsSolution), solution); solution.SaveSolutionElementAction = (options, hierarchy, docCookie) => { ((__VSSLNSAVEOPTIONS)options).Should().Be(__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, "Unexpected save options"); hierarchy.Should().BeNull("Expecting the scope to be the whole solution"); docCookie.Should().Be(0U, "Expecting the scope to be the whole solution"); return(VSConstants.S_OK); }; // Act + Assert VsShellUtils.SaveSolution(serviceProvider, silent: true).Should().BeTrue(); }
public void VsShellUtils_SaveSolution_Prompt() { // Setup var serviceProvider = new ConfigurableServiceProvider(); var solution = new SolutionMock(); serviceProvider.RegisterService(typeof(SVsSolution), solution); int hrResult = 0; solution.SaveSolutionElementAction = (options, hierarchy, docCookie) => { Assert.AreEqual(__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty | __VSSLNSAVEOPTIONS.SLNSAVEOPT_PromptSave, (__VSSLNSAVEOPTIONS)options, "Unexpected save options"); Assert.IsNull(hierarchy, "Expecting the scope to be the whole solution"); Assert.AreEqual(0U, docCookie, "Expecting the scope to be the whole solution"); return(hrResult); }; // Case 1: user selected 'Yes' hrResult = VSConstants.S_OK; //0 // Act + Verify Assert.IsTrue(VsShellUtils.SaveSolution(serviceProvider, silent: false)); // Case 2: user selected 'No' hrResult = VSConstants.S_FALSE; //1 // Act + Verify Assert.IsFalse(VsShellUtils.SaveSolution(serviceProvider, silent: false)); // Case 3: user selected 'Cancel' hrResult = VSConstants.E_ABORT; // Act + Verify Assert.IsFalse(VsShellUtils.SaveSolution(serviceProvider, silent: false)); }
public void VsShellUtils_SaveSolution_Prompt() { // Arrange var serviceProvider = new ConfigurableServiceProvider(); var solution = new SolutionMock(); serviceProvider.RegisterService(typeof(SVsSolution), solution); int hrResult = 0; solution.SaveSolutionElementAction = (options, hierarchy, docCookie) => { ((__VSSLNSAVEOPTIONS)options).Should().Be(__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty | __VSSLNSAVEOPTIONS.SLNSAVEOPT_PromptSave, "Unexpected save options"); hierarchy.Should().BeNull("Expecting the scope to be the whole solution"); docCookie.Should().Be(0U, "Expecting the scope to be the whole solution"); return(hrResult); }; // Case 1: user selected 'Yes' hrResult = VSConstants.S_OK; //0 // Act + Assert VsShellUtils.SaveSolution(serviceProvider, silent: false).Should().BeTrue(); // Case 2: user selected 'No' hrResult = VSConstants.S_FALSE; //1 // Act + Assert VsShellUtils.SaveSolution(serviceProvider, silent: false).Should().BeFalse(); // Case 3: user selected 'Cancel' hrResult = VSConstants.E_ABORT; // Act + Assert VsShellUtils.SaveSolution(serviceProvider, silent: false).Should().BeFalse(); }
static VsServiceProviderHelper() { GlobalServiceProvider = new ConfigurableServiceProvider(); GlobalServiceProvider.RegisterService(typeof(SVsActivityLog), new ConfigurableVsActivityLog(), true); ServiceProvider.CreateFromSetSite(GlobalServiceProvider); }