public void NuGetHelper_HandleFailures()
        {
            // Arrange
            var sp         = CreateServiceProvider();
            var testLogger = new TestLogger();

            // Case 1: No MEF service
            // Act + Assert
            using (new AssertIgnoreScope()) // Missing MEF service
            {
                NuGetHelper.TryInstallPackage(sp, testLogger, new ProjectMock("prj"), "pcg").Should().BeFalse("No MEF service should be resulted with a false returned value");
            }
            testLogger.AssertOutputStrings(0);

            // Case 2: Exception from the service
            sp.RegisterService(typeof(SComponentModel), ConfigurableComponentModel.CreateWithExports(MefTestHelpers.CreateExport <IVsPackageInstaller>(new ConfigurablePackageInstaller(simulateInstallerException: true))), replaceExisting: true);
            // Act + Assert
            NuGetHelper.TryInstallPackage(sp, testLogger, new ProjectMock("prj"), "pcg").Should().BeFalse("Non critical exception should result with a false returned value");
            testLogger.AssertOutputStrings(1);
        }
Exemple #2
0
        private static void TestPluginSupport(bool expectedResult, string vsVersion, SonarQubePlugin installedPlugin,
                                              MinimumSupportedSonarQubePlugin minimumSupportedPlugin,
                                              string expectedMessage)
        {
            // Arrange
            VisualStudioHelpers.VisualStudioVersion = vsVersion;
            var logger = new TestLogger();

            // Act
            var result = ConnectionWorkflow.IsSonarQubePluginSupported(new[] { installedPlugin }, minimumSupportedPlugin, logger);

            // Assert
            result.Should().Be(expectedResult);
            logger.AssertOutputStrings(expectedMessage);
        }