diff --git a/docs/CHANGELOG-v1.md b/docs/CHANGELOG-v1.md index 4a8ab31313..a2b59c47f6 100644 --- a/docs/CHANGELOG-v1.md +++ b/docs/CHANGELOG-v1.md @@ -10,6 +10,11 @@ See [upgrade notes][upgrade-notes] for helpful information when upgrading from p ## Unreleased +What's changed since v1.7.0: + +- Bug fixes: + - Fixed ResourceTags does not contain a method named ToHashtable. [#798](https://github.com/microsoft/PSRule/issues/798) + ## v1.7.0 What's changed since v1.6.0: diff --git a/src/PSRule/Definitions/Resource.cs b/src/PSRule/Definitions/Resource.cs index b53d4b9140..e2d2189721 100644 --- a/src/PSRule/Definitions/Resource.cs +++ b/src/PSRule/Definitions/Resource.cs @@ -139,6 +139,9 @@ public sealed class ResourceTags : Dictionary { public ResourceTags() : base(StringComparer.OrdinalIgnoreCase) { } + /// + /// Convert from a hashtable to resource tags. + /// internal static ResourceTags FromHashtable(Hashtable hashtable) { if (hashtable == null || hashtable.Count == 0) @@ -151,6 +154,9 @@ internal static ResourceTags FromHashtable(Hashtable hashtable) return tags; } + /// + /// Convert from a dictionary of string pairs to resource tags. + /// internal static ResourceTags FromDictionary(Dictionary dictionary) { if (dictionary == null) @@ -163,11 +169,17 @@ internal static ResourceTags FromDictionary(Dictionary dictionar return tags; } - internal Hashtable ToHashtable() + /// + /// Convert resource tags to a hashtable. + /// + public Hashtable ToHashtable() { return new Hashtable(this, StringComparer.OrdinalIgnoreCase); } + /// + /// Check if a specific resource tag exists. + /// internal bool Contains(object key, object value) { if (key == null || value == null || !(key is string k) || !ContainsKey(k)) diff --git a/src/PSRule/Definitions/Rules/Rule.cs b/src/PSRule/Definitions/Rules/Rule.cs index 862b39f71a..2b8dc89867 100644 --- a/src/PSRule/Definitions/Rules/Rule.cs +++ b/src/PSRule/Definitions/Rules/Rule.cs @@ -38,7 +38,6 @@ public RuleV1(string apiVersion, SourceFile source, ResourceMetadata metadata, R string ILanguageBlock.Id => Name; } - internal sealed class RuleV1Spec : Spec, IRuleSpec { public LanguageIf Condition { get; set; } diff --git a/tests/PSRule.Tests/RulesTests.cs b/tests/PSRule.Tests/RulesTests.cs index 86e77c21e7..4044371965 100644 --- a/tests/PSRule.Tests/RulesTests.cs +++ b/tests/PSRule.Tests/RulesTests.cs @@ -26,6 +26,9 @@ public void ReadYamlRule() var rule = HostHelper.GetRuleYaml(GetSource(), context).ToArray(); Assert.NotNull(rule); Assert.Equal("BasicRule", rule[0].RuleName); + + var hashtable = rule[0].Tag.ToHashtable(); + Assert.Equal("tag", hashtable["feature"]); } [Fact]