Skip to content

Commit

Permalink
Introduced test for verifying exception on circular references
Browse files Browse the repository at this point in the history
While mapped properties permit circular references due to caching, this isn't possible with circular references when mapping constructor parameters, since the source object won't yet have been created—and, thus, won't yet have been cached. In this case, a `TopicMappingException` is expected. This unit test verifies that is the case. This concludes the testing for mapped constructor parameters (#35).
  • Loading branch information
JeremyCaney committed Mar 23, 2021
1 parent 8b3f14e commit 4ac3567
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions OnTopic.Tests/TopicMappingServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,27 @@ public async Task Map_Constructor_ReturnsNewModel() {

}

/*==========================================================================================================================
| TEST: MAP: CONSTRUCTOR: THROWS EXCEPTION
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a <see cref="TopicMappingService"/> and attempts to map a view model with a constructor containing a
/// circular reference, and confirms that a <see cref="TopicMappingException"/> is correctly thrown.
/// </summary>
[TestMethod]
[ExpectedException(typeof(TopicMappingException))]
public async Task Map_Constructor_ThrowsException() {

var topic = new Topic("Topic", "Constructed", null, 1);
var related = new Topic("Related", "Constructed", null, 2);

topic.References.SetValue("TopicReference", related);
related.References.SetValue("TopicReference", topic);

await _mappingService.MapAsync<ConstructedTopicViewModel>(topic).ConfigureAwait(false);

}

/*==========================================================================================================================
| TEST: MAP: DISABLED PROPERTY: RETURNS NULL
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down

0 comments on commit 4ac3567

Please # to comment.