Skip to content

Commit d4b77c1

Browse files
committed
Introduced unit tests for the new AsAttributeDictionary() method
The `AtAttributeDictionary()` method is a convenience method on `AttributeCollection` that allows all `AttributeRecord` objects in both the collection as well as, optionally, the collections of any `BaseTopic` that the current topic derives from, to be converted into a lightweight `AttributeDictionary` (a781356). This commit introduces unit tests that verify that a) inheritance works as expected, and b) excluded attributes (such as `Title` and `LastModified`) are not set.
1 parent 11894b7 commit d4b77c1

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

OnTopic.Tests/AttributeDictionaryTest.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,54 @@ public void GetType_InvalidKey_ReturnsNull() {
176176

177177
}
178178

179+
/*==========================================================================================================================
180+
| TEST: AS ATTRIBUTE DICTIONARY: EXCLUDED KEYS: EXCLUDED
181+
\-------------------------------------------------------------------------------------------------------------------------*/
182+
/// <summary>
183+
/// Constructs a <see cref="AttributeDictionary"/> using <see cref="AttributeCollection.AsAttributeDictionary(Boolean)"/>
184+
/// and confirms that <see cref="AttributeDictionary.GetValue(String)"/> doesn't include the excluded values.
185+
/// </summary>
186+
[Fact]
187+
public void AsAttributeDictionary_ExcludedKeys_Excluded() {
188+
189+
var topic = new Topic("Test", "Page");
190+
191+
topic.Attributes.SetValue("Title", "Page Title");
192+
topic.Attributes.SetValue("LastModified", "October 15, 1976");
193+
topic.Attributes.SetValue("Subtitle", "Subtitle");
194+
195+
var attributes = topic.Attributes.AsAttributeDictionary();
196+
197+
Assert.Single(attributes.Keys);
198+
Assert.Null(attributes.GetValue("Title"));
199+
Assert.Null(attributes.GetValue("LastModified"));
200+
Assert.Equal("Subtitle", attributes.GetValue("Subtitle"));
201+
202+
}
203+
204+
/*==========================================================================================================================
205+
| TEST: AS ATTRIBUTE DICTIONARY: INHERIT FROM BASE: INHERITS VALUES
206+
\-------------------------------------------------------------------------------------------------------------------------*/
207+
/// <summary>
208+
/// Constructs a <see cref="AttributeDictionary"/> using <see cref="AttributeCollection.AsAttributeDictionary(Boolean)"/>
209+
/// and confirms that <see cref="AttributeDictionary.GetValue(String)"/> correctly inherits values.
210+
/// </summary>
211+
[Fact]
212+
public void AsAttributeDictionary_InheritFromBase_InheritsValues() {
213+
214+
var baseTopic = new Topic("BaseTopic", "Page");
215+
var topic = new Topic("Test", "Page");
216+
217+
topic.BaseTopic = baseTopic;
218+
219+
baseTopic.Attributes.SetValue("Subtitle", "Subtitle");
220+
221+
var attributes = topic.Attributes.AsAttributeDictionary(true);
222+
223+
Assert.Single(attributes.Keys);
224+
Assert.Equal("Subtitle", attributes.GetValue("Subtitle"));
225+
226+
}
227+
179228
} //Class
180229
} //Namespace

0 commit comments

Comments
 (0)