Пример #1
0
        public void ConfigExt_GetSettingOrDefault_NoSetting_DefaultIsReturned()
        {
            var config = new AnalysisConfig
            {
                ServerSettings = new AnalysisProperties
                {
                    new Property {
                        Id = "foo", Value = "value"
                    }
                }
            };

            // 1. Non-null default
            var result = ConfigSettingsExtensions.GetSettingOrDefault(config, "id1", true, "default1");

            result.Should().Be("default1");

            // 2. Null default is ok
            result = ConfigSettingsExtensions.GetSettingOrDefault(config, "id1", true, null);
            result.Should().BeNull();

            // 3. Case-sensitive
            result = ConfigSettingsExtensions.GetSettingOrDefault(config, "FOO", true, "not found");
            result.Should().Be("not found");

            // 4. Not including server settings -> missing
            result = ConfigSettingsExtensions.GetSettingOrDefault(config, "foo", false, "default1");
            result.Should().Be("default1");
        }
        public void SetSettingsFilePath_WhenFileNameIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            Action action = () => ConfigSettingsExtensions.SetSettingsFilePath(new AnalysisConfig(), null);

            // Act & Assert
            action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("fileName");
        }
        public void SetSettingsFilePath_WhenConfigIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            Action action = () => ConfigSettingsExtensions.SetSettingsFilePath(null, "foo");

            // Act & Assert
            action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("config");
        }
        public void GetAnalysisSettings_WhenConfigIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            Action action = () => ConfigSettingsExtensions.GetAnalysisSettings(null, false);

            // Act & Assert
            action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("config");
        }
        public void GetConfigValue_WhenSettingIdIsWhitespace_ThrowsArgumentNullException()
        {
            // Arrange
            Action action = () => ConfigSettingsExtensions.GetConfigValue(new AnalysisConfig(), "   ", "bar");

            // Act & Assert
            action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("settingId");
        }
        public void GetConfigValue_WhenConfigIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            Action action = () => ConfigSettingsExtensions.GetConfigValue(null, "foo", "bar");

            // Act & Assert
            action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("config");
        }
Пример #7
0
        public void ConfigExt_FindServerVersion_NoSetting_ReturnsNull()
        {
            var config = new AnalysisConfig();

            var actualVersion = ConfigSettingsExtensions.FindServerVersion(config);

            actualVersion.Should().BeNull();
        }
Пример #8
0
        public void ConfigExt_GetSettingOrDefault_InvalidArgs_Throw()
        {
            // 1. Null config
            Action action = () => ConfigSettingsExtensions.GetSettingOrDefault(null, "anySetting", true, "defaultValue");

            action.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("config");

            // 2. Null setting name
            action = () => ConfigSettingsExtensions.GetSettingOrDefault(new AnalysisConfig(), null, true, "defaultValue");
            action.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("settingName");
        }
Пример #9
0
        public void ConfigExt_FindServerVersion_ValidVersion_ReturnsVersion()
        {
            var config = new AnalysisConfig
            {
                SonarQubeVersion = "6.7.1.2"
            };

            var actualVersion = ConfigSettingsExtensions.FindServerVersion(config);

            actualVersion.Should().Be(new Version("6.7.1.2"));
        }
Пример #10
0
        public void ConfigExt_FindServerVersion_InvalidVersion_ReturnsNull()
        {
            var config = new AnalysisConfig
            {
                SonarQubeVersion = "invalid"
            };

            var actualVersion = ConfigSettingsExtensions.FindServerVersion(config);

            actualVersion.Should().BeNull();
        }
Пример #11
0
        private static IAnalysisPropertyProvider GetAnalysisSettingsIsolatedFromEnvironment(AnalysisConfig config, bool includeServerSettings)
        {
            IAnalysisPropertyProvider provider = null;

            // Make sure the test isn't affected by the hosting environment
            // The SonarCloud VSTS extension sets additional properties in an environment variable that
            // would affect the test
            using (var scope = new EnvironmentVariableScope())
            {
                scope.SetVariable(EnvScannerPropertiesProvider.ENV_VAR_KEY, null);

                provider = ConfigSettingsExtensions.GetAnalysisSettings(config, includeServerSettings);
            }

            return(provider);
        }
Пример #12
0
        public void ConfigExt_GetSettingOrDefault_SettingExists_ValueIsReturned()
        {
            var config = new AnalysisConfig
            {
                ServerSettings = new AnalysisProperties
                {
                    new Property {
                        Id = "id1", Value = "server value"
                    }
                },
                LocalSettings = new AnalysisProperties
                {
                    new Property {
                        Id = "id1", Value = "local value"
                    }
                }
            };

            // 1. Local value should take precedence
            var result = ConfigSettingsExtensions.GetSettingOrDefault(config, "id1", true, "local value");

            result.Should().Be("local value");
        }
Пример #13
0
        public void ConfigExt_FindServerVersion_WhenConfigIsNull_Throws()
        {
            Action action = () => ConfigSettingsExtensions.FindServerVersion(null);

            action.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("config");
        }