File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 \-------------------------------------------------------------------------------------------------------------------------*/
You can’t perform that action at this time.
0 commit comments