Skip to content

Commit bea5a20

Browse files
committed
Introduced unit test for validating the mapping of records
1 parent f3695e9 commit bea5a20

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using System.ComponentModel.DataAnnotations;
7+
using OnTopic.Models;
8+
9+
namespace OnTopic.Tests.BindingModels {
10+
11+
/*============================================================================================================================
12+
| BINDING MODEL: RECORD
13+
\---------------------------------------------------------------------------------------------------------------------------*/
14+
/// <summary>
15+
/// Provides a strongly-typed binding model based on a C# 9.0 <c>record</c> data type to ensure that it can be properly
16+
/// mapped from.
17+
/// </summary>
18+
/// <remarks>
19+
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
20+
/// </remarks>
21+
public class RecordTopicBindingModel : ITopicBindingModel {
22+
23+
public RecordTopicBindingModel() { }
24+
25+
public string? Key { get; init; }
26+
27+
[Required]
28+
public string? ContentType { get; init; }
29+
30+
} //Class
31+
} //Namespace

OnTopic.Tests/ReverseTopicMappingServiceTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,31 @@ public async Task Map_Existing_ReturnsUpdatedTopic() {
155155

156156
}
157157

158+
/*==========================================================================================================================
159+
| TEST: MAP: RECORD: RETURNS NEW TOPIC
160+
\-------------------------------------------------------------------------------------------------------------------------*/
161+
/// <summary>
162+
/// Establishes a <see cref="ReverseTopicMappingService"/> and tests mapping a binding model that's based on a C# 9.0
163+
/// record type.
164+
/// </summary>
165+
[TestMethod]
166+
public async Task Map_Record_ReturnsNewTopic() {
167+
168+
var mappingService = new ReverseTopicMappingService(_topicRepository);
169+
170+
var bindingModel = new RecordTopicBindingModel() {
171+
Key = "Test",
172+
ContentType = "TextAttributeDescriptor"
173+
};
174+
175+
var target = await mappingService.MapAsync<TextAttributeDescriptor>(bindingModel).ConfigureAwait(false);
176+
177+
Assert.IsNotNull(target);
178+
Assert.AreEqual<string>("Test", target.Key);
179+
Assert.AreEqual<string>("TextAttributeDescriptor", target.ContentType);
180+
181+
}
182+
158183
/*==========================================================================================================================
159184
| TEST: MAP: COMPLEX OBJECT: RETURNS FLATTENED TOPIC
160185
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)