示例#1
0
        public static void TestEmptyDictionaryReturnNoNamingStylePreferencesObjectReturnsFalse()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();
            var result = editorConfigStorageLocation.TryGetOption(new object(), new Dictionary <string, object>(), typeof(NamingStylePreferences), out var @object);

            Assert.False(result, "Expected TryParseReadonlyDictionary to return 'false' for empty dictionary");
        }
示例#2
0
        public static void TestOrderedByAccessibilityBeforeName(string firstName, string secondName, string firstNameAfterOrdering, string firstAccessibility, string secondAccessibility)
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();
            var newDictionary = new Dictionary <string, string>()
            {
                [$"dotnet_naming_rule.{firstName}.severity"]                        = "error",
                [$"dotnet_naming_rule.{firstName}.symbols"]                         = "first_symbols",
                [$"dotnet_naming_rule.{firstName}.style"]                           = $"{firstName}_style",
                ["dotnet_naming_symbols.first_symbols.applicable_kinds"]            = "method,property",
                ["dotnet_naming_symbols.first_symbols.applicable_accessibilities"]  = firstAccessibility,
                [$"dotnet_naming_style.{firstName}_style.capitalization"]           = "pascal_case",
                [$"dotnet_naming_style.{secondName}_style.capitalization"]          = "camel_case",
                [$"dotnet_naming_rule.{secondName}.severity"]                       = "error",
                [$"dotnet_naming_rule.{secondName}.symbols"]                        = "second_symbols",
                [$"dotnet_naming_rule.{secondName}.style"]                          = $"{secondName}_style",
                ["dotnet_naming_symbols.second_symbols.applicable_kinds"]           = "method,property",
                ["dotnet_naming_symbols.second_symbols.applicable_accessibilities"] = secondAccessibility,
            };

            var result = editorConfigStorageLocation.TryGetOption(
                newDictionary,
                typeof(NamingStylePreferences),
                out var combinedNamingStyles);

            var secondNameAfterOrdering = firstNameAfterOrdering == firstName ? secondName : firstName;

            Assert.True(result, "Expected non-empty dictionary to return true");
            var namingStylePreferences = Assert.IsAssignableFrom <NamingStylePreferences>(combinedNamingStyles);

            Assert.Equal($"{firstNameAfterOrdering}_style", namingStylePreferences.Rules.NamingRules[0].NamingStyle.Name);
            Assert.Equal($"{secondNameAfterOrdering}_style", namingStylePreferences.Rules.NamingRules[1].NamingStyle.Name);
        }
示例#3
0
        public static void TestNonEmptyDictionaryReturnsTrue()
        {
            var editorConfigStorageLocation =
                new NamingStylePreferenceEditorConfigStorageLocation();
            var newDictionary = new Dictionary <string, string>()
            {
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.severity"] =
                    "error",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols"] =
                    "method_and_property_symbols",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style"] =
                    "pascal_case_style",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_kinds"] =
                    "method,property",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities"] =
                    "*",
                ["dotnet_naming_style.pascal_case_style.capitalization"] = "pascal_case"
            };

            var result = editorConfigStorageLocation.TryGetOption(
                newDictionary,
                typeof(NamingStylePreferences),
                out var combinedNamingStyles
                );

            Assert.True(result, "Expected non-empty dictionary to return true");
            var namingStylePreferences = Assert.IsAssignableFrom <NamingStylePreferences>(
                combinedNamingStyles
                );

            Assert.Equal(
                ReportDiagnostic.Error,
                namingStylePreferences.Rules.NamingRules[0].EnforcementLevel
                );
        }
        public static void TestEmptyDictionaryReturnNoNamingStylePreferencesObjectReturnsFalse()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();
            var result = editorConfigStorageLocation.TryGetOption(StructuredAnalyzerConfigOptions.Create(DictionaryAnalyzerConfigOptions.EmptyDictionary), typeof(NamingStylePreferences), out _);

            Assert.False(result, "Expected TryParseReadonlyDictionary to return 'false' for empty dictionary");
        }
示例#5
0
        public static void TestObjectTypeThrowsInvalidOperationException()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();

            Assert.Throws <InvalidOperationException>(() =>
            {
                editorConfigStorageLocation.TryGetOption(new object(), new Dictionary <string, object>(), typeof(object), out var @object);
            });
        }
        public static void TestObjectTypeThrowsInvalidOperationException()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();

            Assert.Throws <InvalidOperationException>(() =>
            {
                editorConfigStorageLocation.TryGetOption(StructuredAnalyzerConfigOptions.Create(DictionaryAnalyzerConfigOptions.EmptyDictionary), typeof(object), out var @object);
            });
        }
示例#7
0
        public static void TestEmptyDictionaryDefaultNamingStylePreferencesObjectReturnsFalse()
        {
            var editorConfigStorageLocation    = new NamingStylePreferenceEditorConfigStorageLocation();
            var existingNamingStylePreferences = new NamingStylePreferences(
                ImmutableArray.Create <SymbolSpecification>(),
                ImmutableArray.Create <NamingStyle>(),
                ImmutableArray.Create <SerializableNamingRule>());

            var result = editorConfigStorageLocation.TryGetOption(
                existingNamingStylePreferences,
                new Dictionary <string, object>(),
                typeof(NamingStylePreferences),
                out var @object);

            Assert.False(result, "Expected TryParseReadonlyDictionary to return 'false' for empty dictionary");
        }
示例#8
0
        public static void TestNonEmptyDictionaryReturnsTrue()
        {
            var initialDictionary = new Dictionary <string, object>()
            {
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.severity"]       = "warning",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols"]        = "method_and_property_symbols",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style"]          = "pascal_case_style",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_kinds"]           = "method,property",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities"] = "*",
                ["dotnet_naming_style.pascal_case_style.capitalization"] = "pascal_case"
            };
            var existingNamingStylePreferences = ParseDictionary(initialDictionary);

            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();
            var newDictionary = new Dictionary <string, object>()
            {
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.severity"]       = "error",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols"]        = "method_and_property_symbols",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style"]          = "pascal_case_style",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_kinds"]           = "method,property",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities"] = "*",
                ["dotnet_naming_style.pascal_case_style.capitalization"] = "pascal_case"
            };

            var result = editorConfigStorageLocation.TryGetOption(
                existingNamingStylePreferences,
                newDictionary,
                typeof(NamingStylePreferences),
                out var combinedNamingStyles);

            Assert.True(result, "Expected non-empty dictionary to return true");
            var isNamingStylePreferencesObject = combinedNamingStyles is NamingStylePreferences;

            Assert.True(isNamingStylePreferencesObject, $"Expected returned object to be of type '{nameof(NamingStylePreferences)}'");
            Assert.Equal(DiagnosticSeverity.Error, ((NamingStylePreferences)combinedNamingStyles).Rules.NamingRules[0].EnforcementLevel);
        }