Skip to content

Commit 6684b39

Browse files
committed
Patched unit test to account for validation bug
In #2bf635e, a bug was missed by the `Map_ComplexObject_ReturnsFlattenedTopic` unit test since the `Contact` content type had an `Email` attribute. As such, when the validator was supposed to be validating e.g. `AlternateEmail`, it was _actually_ validating `Email`, and passing. In a real-world scenario, however, this won't usually be the case, and defeats the benefit of validating the model against the content type. To account for this, the generic `Email` attribute was removed, and a new `Name` attribute was introduced. This clutters up the unit test and the model a bit by requiring two separate objects (`ContactTopicBindingModel` and `EmailTopicBindingModel`) but this effectively tests the same conditions while additionally validating that the `AttributePrefix` context is being properly accounted for as part of that validation.
1 parent 49bb3ef commit 6684b39

5 files changed

Lines changed: 34 additions & 10 deletions

File tree

OnTopic.TestDoubles/StubTopicRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private Topic CreateFakeData() {
222222

223223
var contactContentType = TopicFactory.Create("Contact", "ContentTypeDescriptor", contentTypes);
224224

225-
addAttribute(contactContentType, "Email");
225+
addAttribute(contactContentType, "Name");
226226
addAttribute(contactContentType, "AlternateEmail");
227227
addAttribute(contactContentType, "BillingContactEmail");
228228

OnTopic.Tests/BindingModels/ContactTopicBindingModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace OnTopic.Tests.BindingModels {
1818
/// </remarks>
1919
public class ContactTopicBindingModel {
2020

21-
public string? Email { get; set; }
21+
public string? Name { get; set; }
2222

2323
} //Class
2424
} //Namespace
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
7+
namespace OnTopic.Tests.BindingModels {
8+
9+
/*============================================================================================================================
10+
| BINDING MODEL: EMAIL
11+
\---------------------------------------------------------------------------------------------------------------------------*/
12+
/// <summary>
13+
/// Provides a minimal implementation of a custom topic binding model with a single property intended to be called from
14+
/// <see cref="MapToParentTopicBindingModel"/>.
15+
/// </summary>
16+
/// <remarks>
17+
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
18+
/// </remarks>
19+
public class EmailTopicBindingModel {
20+
21+
public string? Email { get; set; }
22+
23+
} //Class
24+
} //Namespace

OnTopic.Tests/BindingModels/MapToParentTopicBindingModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public class MapToParentTopicBindingModel : BasicTopicBindingModel {
2222
public ContactTopicBindingModel PrimaryContact { get; set; } = new ContactTopicBindingModel();
2323

2424
[MapToParent(AttributePrefix="Alternate")]
25-
public ContactTopicBindingModel AlternateContact { get; set; } = new ContactTopicBindingModel();
25+
public EmailTopicBindingModel AlternateContact { get; set; } = new EmailTopicBindingModel();
2626

2727
[MapToParent]
28-
public ContactTopicBindingModel BillingContact { get; set; } = new ContactTopicBindingModel();
28+
public EmailTopicBindingModel BillingContact { get; set; } = new EmailTopicBindingModel();
2929

3030
} //Class
3131
} //Namespace

OnTopic.Tests/ReverseTopicMappingServiceTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public async Task Map_Existing_ReturnsUpdatedTopic() {
139139
target.Title = "Original Attribute";
140140
target.DefaultValue = "Hello";
141141
target.IsRequired = true;
142-
target.IsExtendedAttribute = false;
142+
target.IsExtendedAttribute= false;
143143
target.Description = "Original Description";
144144

145145
target = (TextAttribute?)await mappingService.MapAsync(bindingModel, target).ConfigureAwait(false);
@@ -170,14 +170,14 @@ public async Task Map_ComplexObject_ReturnsFlattenedTopic() {
170170
ContentType = "Contact"
171171
};
172172

173-
bindingModel.PrimaryContact.Email = "PrimaryContact@Ignia.com";
174-
bindingModel.AlternateContact.Email = "AlternateContact@Ignia.com";
175-
bindingModel.BillingContact.Email = "BillingContact@Ignia.com";
176-
173+
bindingModel.PrimaryContact.Name = "Jeremy";
174+
bindingModel.AlternateContact.Email = "AlternateContact@Ignia.com";
175+
bindingModel.BillingContact.Email = "BillingContact@Ignia.com";
176+
177177
var target = (Topic?)await mappingService.MapAsync(bindingModel).ConfigureAwait(false);
178178

179179
Assert.IsNotNull(target);
180-
Assert.AreEqual<string>("PrimaryContact@Ignia.com", target.Attributes.GetValue("Email"));
180+
Assert.AreEqual<string>("Jeremy", target.Attributes.GetValue("Name"));
181181
Assert.AreEqual<string>("AlternateContact@Ignia.com", target.Attributes.GetValue("AlternateEmail"));
182182
Assert.AreEqual<string>("BillingContact@Ignia.com", target.Attributes.GetValue("BillingContactEmail"));
183183

0 commit comments

Comments
 (0)