Skip to content

Commit 6b8ed99

Browse files
committed
Introduced unit test for mapping constructors with an AttributeDictionary
As per Feature #99, we now support mapping models that have a constructor with a single `AttributeDictionary` parameter (72ca032). In these cases, scalar properties in the `AttributeCollection` will be set via constructor, thus bypassing unnecessary calls to reflection. The new unit test confirms that this works by ensuring that such a constructor correctly sets a `Subtitle` property, without interfering with the standard handling for `Title` and `LastModified` (which are handled via compatible properties).
1 parent d4b77c1 commit 6b8ed99

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,30 @@ public async Task Map_Generic_ReturnsConvertedProperty() {
148148

149149
}
150150

151+
/*==========================================================================================================================
152+
| TEST: MAP: ATTRIBUTE DICTIONARY: RETURNS NEW MODEL
153+
\-------------------------------------------------------------------------------------------------------------------------*/
154+
/// <summary>
155+
/// Establishes a <see cref="TopicMappingService"/> and attempts to map a view model with a constructor containing a <see
156+
/// cref="AttributeDictionary"/>. Confirms that the expected model is returned.
157+
/// </summary>
158+
[Fact]
159+
public async Task Map_AttributeDictionary_ReturnsNewModel() {
160+
161+
var topic = new Topic("Test", "Page");
162+
var lastModified = new DateTime(2021, 12, 22);
163+
164+
topic.Attributes.SetValue("Subtitle", "Value");
165+
topic.VersionHistory.Add(lastModified);
166+
167+
var target = await _mappingService.MapAsync<PageTopicViewModel>(topic).ConfigureAwait(false);
168+
169+
Assert.Equal("Test", target?.Title);
170+
Assert.Equal("Value", target?.Subtitle);
171+
Assert.Equal(lastModified, target?.LastModified);
172+
173+
}
174+
151175
/*==========================================================================================================================
152176
| TEST: MAP: CONSTRUCTOR: RETURNS NEW MODEL
153177
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)