Skip to content

Commit 546eb1b

Browse files
committed
Updated StubTopicRepository to use new AttributeDescriptor format
To more accurately test the current assumptions, updated the `StubTopicRepository` to create the new `AttributeDescriptor` format. This necessitated creating a couple of basic view models to accommodate mapping of a `TextAttribute` and `TopicReferenceAttribute`. It also required updating a few tests to accommodate the change in `ContentTypeDescriptor`s count, and the new `EditorType` names (e.g., `TextAttribute` instead of `FormField`).
1 parent 99c4bc9 commit 546eb1b

10 files changed

Lines changed: 121 additions & 41 deletions

Ignia.Topics.TestDoubles/StubTopicRepository.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ private Topic CreateFakeData() {
183183
var configuration = TopicFactory.Create("Configuration", "Container", rootTopic);
184184
var contentTypes = TopicFactory.Create("ContentTypes", "ContentTypeDescriptor", configuration);
185185

186-
addAttribute(contentTypes, "Key", "FormField", true);
187-
addAttribute(contentTypes, "ContentType", "FormField", true);
188-
addAttribute(contentTypes, "Title", "FormField", true);
189-
addAttribute(contentTypes, "TopicId", "TopicPointer");
186+
addAttribute(contentTypes, "Key", "TextAttribute", true);
187+
addAttribute(contentTypes, "ContentType", "TextAttribute", true);
188+
addAttribute(contentTypes, "Title", "TextAttribute", true);
189+
addAttribute(contentTypes, "TopicId", "TopicReferenceAttribute");
190190

191191
var contentTypeDescriptor = TopicFactory.Create("ContentTypeDescriptor", "ContentTypeDescriptor", contentTypes);
192192

193-
addAttribute(contentTypeDescriptor, "ContentTypes", "Relationships");
194-
addAttribute(contentTypeDescriptor, "Attributes", "TopicList");
193+
addAttribute(contentTypeDescriptor, "ContentTypes", "RelationshipAttribute");
194+
addAttribute(contentTypeDescriptor, "Attributes", "NestedTopicListAttribute");
195195

196196
TopicFactory.Create("Container", "ContentTypeDescriptor", contentTypes);
197197
TopicFactory.Create("Lookup", "ContentTypeDescriptor", contentTypes);
@@ -200,15 +200,22 @@ private Topic CreateFakeData() {
200200

201201
var attributeDescriptor = (ContentTypeDescriptor)TopicFactory.Create("AttributeDescriptor", "ContentTypeDescriptor", contentTypes);
202202

203-
addAttribute(attributeDescriptor, "DefaultValue", "FormField", true);
204-
addAttribute(attributeDescriptor, "IsRequired", "Checkbox", true);
203+
addAttribute(attributeDescriptor, "DefaultValue", "TextAttribute", true);
204+
addAttribute(attributeDescriptor, "IsRequired", "BooleanAttribute", true);
205+
206+
TopicFactory.Create("BooleanAttribute", "ContentTypeDescriptor", attributeDescriptor);
207+
TopicFactory.Create("NestedTopicListAttribute", "ContentTypeDescriptor", attributeDescriptor);
208+
TopicFactory.Create("NumberAttribute", "ContentTypeDescriptor", attributeDescriptor);
209+
TopicFactory.Create("RelationshipAttribute", "ContentTypeDescriptor", attributeDescriptor);
210+
TopicFactory.Create("TextAttribute", "ContentTypeDescriptor", attributeDescriptor);
211+
TopicFactory.Create("TopicReferenceAttribute", "ContentTypeDescriptor", attributeDescriptor);
205212

206213
var pageContentType = TopicFactory.Create("Page", "ContentTypeDescriptor", contentTypes);
207214

208215
addAttribute(pageContentType, "MetaTitle");
209216
addAttribute(pageContentType, "MetaDescription");
210217
addAttribute(pageContentType, "IsHidden");
211-
addAttribute(pageContentType, "TopicReference", "TopicPointer");
218+
addAttribute(pageContentType, "TopicReference", "TopicReferenceAttribute");
212219

213220
pageContentType.Relationships.SetTopic("ContentTypes", pageContentType);
214221
pageContentType.Relationships.SetTopic("ContentTypes", contentTypeDescriptor);
@@ -222,14 +229,13 @@ private Topic CreateFakeData() {
222229
/*------------------------------------------------------------------------------------------------------------------------
223230
| Local addAttribute() helper function
224231
\-----------------------------------------------------------------------------------------------------------------------*/
225-
AttributeDescriptor addAttribute(Topic contentType, string attributeKey, string editorType = "FormField", bool isRequired = false) {
232+
AttributeDescriptor addAttribute(Topic contentType, string attributeKey, string editorType = "TextAttribute", bool isRequired = false) {
226233
var container = contentType.Children.GetTopic("Attributes");
227234
if (container == null) {
228235
container = TopicFactory.Create("Attributes", "List", contentType);
229236
container.Attributes.SetBoolean("IsHidden", true);
230237
}
231-
var attribute = (AttributeDescriptor)TopicFactory.Create(attributeKey, "AttributeDescriptor", currentAttributeId++, container);
232-
attribute.EditorType = editorType;
238+
var attribute = (AttributeDescriptor)TopicFactory.Create(attributeKey, editorType, currentAttributeId++, container);
233239
attribute.IsRequired = isRequired;
234240
return attribute;
235241
}

Ignia.Topics.Tests/BindingModels/AttributeDescriptorTopicBindingModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Ignia.Topics.Tests.BindingModels {
1919
/// </remarks>
2020
public class AttributeDescriptorTopicBindingModel : BasicTopicBindingModel {
2121

22-
public AttributeDescriptorTopicBindingModel(string? key = null) : base(key, "AttributeDescriptor") { }
22+
public AttributeDescriptorTopicBindingModel(string? key = null, string? attributeType = null) : base(key, attributeType) { }
2323

2424
public string? Title { get; set; }
2525

Ignia.Topics.Tests/BindingModels/ReferenceTopicBindingModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Ignia.Topics.Tests.BindingModels {
2020
/// </remarks>
2121
public class ReferenceTopicBindingModel : BasicTopicBindingModel {
2222

23-
public ReferenceTopicBindingModel(string key) : base(key, "AttributeDescriptor") { }
23+
public ReferenceTopicBindingModel(string key) : base(key, "TopicReferenceAttribute") { }
2424

2525
[AttributeKey("TopicId")]
2626
public RelatedTopicBindingModel? DerivedTopic { get; set; }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using Ignia.Topics.Metadata;
7+
using Ignia.Topics.Metadata.AttributeTypes;
8+
9+
namespace Ignia.Topics.Tests.BindingModels {
10+
11+
/*============================================================================================================================
12+
| BINDING MODEL: TEXT ATTRIBUTE (DESCRIPTOR)
13+
\---------------------------------------------------------------------------------------------------------------------------*/
14+
/// <summary>
15+
/// Provides a minimal implementation of a custom topic binding model with a couple of scalar values mapping to properties
16+
/// on the <see cref="TextAttribute"/> content type.
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 TextAttributeTopicBindingModel : AttributeDescriptorTopicBindingModel {
22+
23+
public TextAttributeTopicBindingModel(string? key = null) : base(key, "TextAttribute") { }
24+
25+
} //Class
26+
} //Namespace

Ignia.Topics.Tests/ITopicRepositoryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void GetContentTypeDescriptors() {
199199

200200
var contentTypes = _topicRepository.GetContentTypeDescriptors();
201201

202-
Assert.AreEqual<int>(9, contentTypes.Count);
202+
Assert.AreEqual<int>(15, contentTypes.Count);
203203
Assert.IsNotNull(contentTypes.GetTopic("ContentTypeDescriptor"));
204204
Assert.IsNotNull(contentTypes.GetTopic("Page"));
205205
Assert.IsNotNull(contentTypes.GetTopic("LookupListItem"));

Ignia.Topics.Tests/ReverseTopicMappingServiceTest.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Ignia.Topics.Mapping.Annotations;
1414
using Ignia.Topics.Mapping.Reverse;
1515
using Ignia.Topics.Metadata;
16+
using Ignia.Topics.Metadata.AttributeTypes;
1617
using Ignia.Topics.Models;
1718
using Ignia.Topics.Repositories;
1819
using Ignia.Topics.TestDoubles;
@@ -64,18 +65,18 @@ public async Task MapGeneric() {
6465

6566
var mappingService = new ReverseTopicMappingService(_topicRepository);
6667

67-
var bindingModel = new AttributeDescriptorTopicBindingModel() {
68+
var bindingModel = new TextAttributeTopicBindingModel() {
6869
Key = "Test",
69-
ContentType = "AttributeDescriptor",
70+
ContentType = "TextAttribute",
7071
Title = "Test Attribute",
7172
DefaultValue = "Hello",
7273
IsRequired = true
7374
};
7475

75-
var target = await mappingService.MapAsync<AttributeDescriptor>(bindingModel).ConfigureAwait(false);
76+
var target = await mappingService.MapAsync<TextAttribute>(bindingModel).ConfigureAwait(false);
7677

7778
Assert.AreEqual<string>("Test", target.Key);
78-
Assert.AreEqual<string>("AttributeDescriptor", target.ContentType);
79+
Assert.AreEqual<string>("TextAttribute", target.ContentType);
7980
Assert.AreEqual<string>("Test Attribute", target.Title);
8081
Assert.AreEqual<string>("Hello", target.DefaultValue);
8182
Assert.AreEqual<bool>(true, target.IsRequired);
@@ -94,19 +95,19 @@ public async Task MapDynamic() {
9495

9596
var mappingService = new ReverseTopicMappingService(_topicRepository);
9697

97-
var bindingModel = new AttributeDescriptorTopicBindingModel {
98+
var bindingModel = new TextAttributeTopicBindingModel {
9899
Key = "Test",
99-
ContentType = "AttributeDescriptor",
100+
ContentType = "TextAttribute",
100101
Title = "Test Attribute",
101102
DefaultValue = "Hello",
102103
IsRequired = true
103104
};
104105

105-
var target = (AttributeDescriptor?)await mappingService.MapAsync(bindingModel).ConfigureAwait(false);
106+
var target = (TextAttribute?)await mappingService.MapAsync(bindingModel).ConfigureAwait(false);
106107

107108
Assert.IsNotNull(target);
108109
Assert.AreEqual<string>("Test", target.Key);
109-
Assert.AreEqual<string>("AttributeDescriptor", target.ContentType);
110+
Assert.AreEqual<string>("TextAttribute", target.ContentType);
110111
Assert.AreEqual<string>("Test Attribute", target.Title);
111112
Assert.AreEqual<string>("Hello", target.DefaultValue);
112113
Assert.AreEqual<bool>(true, target.IsRequired);
@@ -125,26 +126,26 @@ public async Task MapExisting() {
125126

126127
var mappingService = new ReverseTopicMappingService(_topicRepository);
127128

128-
var bindingModel = new AttributeDescriptorTopicBindingModel() {
129+
var bindingModel = new TextAttributeTopicBindingModel() {
129130
Key = "Test",
130-
ContentType = "AttributeDescriptor",
131+
ContentType = "TextAttribute",
131132
Title = null,
132133
DefaultValue = "World",
133134
IsRequired = false
134135
};
135136

136-
var target = (AttributeDescriptor?)TopicFactory.Create("Test", "AttributeDescriptor");
137+
var target = (TextAttribute?)TopicFactory.Create("Test", "TextAttribute");
137138

138139
target.Title = "Original Attribute";
139140
target.DefaultValue = "Hello";
140141
target.IsRequired = true;
141142
target.IsExtendedAttribute = false;
142143
target.Description = "Original Description";
143144

144-
target = (AttributeDescriptor?)await mappingService.MapAsync(bindingModel, target).ConfigureAwait(false);
145+
target = (TextAttribute?)await mappingService.MapAsync(bindingModel, target).ConfigureAwait(false);
145146

146147
Assert.AreEqual<string>("Test", target.Key);
147-
Assert.AreEqual<string>("AttributeDescriptor", target.ContentType);
148+
Assert.AreEqual<string>("TextAttribute", target.ContentType);
148149
Assert.AreEqual<string>("Test", target.Title); //Should inherit from "Key" since it will be null
149150
Assert.AreEqual<string>("World", target.DefaultValue);
150151
Assert.AreEqual<bool>(false, target.IsRequired);
@@ -253,15 +254,15 @@ public async Task MapNestedTopics() {
253254
var mappingService = new ReverseTopicMappingService(_topicRepository);
254255
var bindingModel = new ContentTypeDescriptorTopicBindingModel("Test");
255256

256-
bindingModel.Attributes.Add(new AttributeDescriptorTopicBindingModel("Attribute1"));
257-
bindingModel.Attributes.Add(new AttributeDescriptorTopicBindingModel("Attribute2"));
258-
bindingModel.Attributes.Add(new AttributeDescriptorTopicBindingModel("Attribute3") { DefaultValue = "New Value" });
257+
bindingModel.Attributes.Add(new TextAttributeTopicBindingModel("Attribute1"));
258+
bindingModel.Attributes.Add(new TextAttributeTopicBindingModel("Attribute2"));
259+
bindingModel.Attributes.Add(new TextAttributeTopicBindingModel("Attribute3") { DefaultValue = "New Value" });
259260

260261
var topic = TopicFactory.Create("Test", "ContentTypeDescriptor");
261262
var attributes = TopicFactory.Create("Attributes", "List", topic);
262263

263-
var attribute3 = (AttributeDescriptor)TopicFactory.Create("Attribute3", "AttributeDescriptor", attributes);
264-
var attribute4 = TopicFactory.Create("Attribute4", "AttributeDescriptor", attributes);
264+
var attribute3 = (AttributeDescriptor)TopicFactory.Create("Attribute3", "TextAttribute", attributes);
265+
var attribute4 = TopicFactory.Create("Attribute4", "TextAttribute", attributes);
265266

266267
attribute3.DefaultValue = "Original Value";
267268

@@ -293,12 +294,12 @@ public async Task MapTopicReferences() {
293294
}
294295
};
295296

296-
var target = (AttributeDescriptor?)await mappingService.MapAsync(bindingModel).ConfigureAwait(false);
297+
var target = (TopicReferenceAttribute?)await mappingService.MapAsync(bindingModel).ConfigureAwait(false);
297298

298299
target.DerivedTopic = _topicRepository.Load(target.Attributes.GetInteger("TopicId", -5));
299300

300301
Assert.IsNotNull(target.DerivedTopic);
301-
Assert.AreEqual<string>("FormField", target.EditorType);
302+
Assert.AreEqual<string>("TopicReference", target.EditorType);
302303

303304
}
304305

Ignia.Topics.Tests/TestDoubles/FakeViewModelLookupService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public FakeViewModelLookupService() : base(null, typeof(object)) {
4343
Add(typeof(SampleTopicViewModel));
4444
Add(typeof(ContentTypeDescriptorTopicViewModel));
4545
Add(typeof(AttributeDescriptorTopicViewModel));
46+
Add(typeof(TextAttributeTopicViewModel));
47+
Add(typeof(TopicReferenceAttributeTopicViewModel));
4648

4749
}
4850

Ignia.Topics.Tests/TopicMappingServiceTest.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Ignia.Topics.Mapping;
1414
using Ignia.Topics.Mapping.Annotations;
1515
using Ignia.Topics.Metadata;
16+
using Ignia.Topics.Metadata.AttributeTypes;
1617
using Ignia.Topics.Repositories;
1718
using Ignia.Topics.TestDoubles;
1819
using Ignia.Topics.Tests.TestDoubles;
@@ -287,11 +288,11 @@ public async Task MapRelationships() {
287288
\-------------------------------------------------------------------------------------------------------------------------*/
288289
/// <summary>
289290
/// Establishes a <see cref="TopicMappingService"/> and tests whether it successfully derives values from the key and
290-
/// type specified by <see cref="RelationshipAttribute"/>.
291+
/// type specified by <see cref="Mapping.Annotations.RelationshipAttribute"/>.
291292
/// </summary>
292293
/// <remarks>
293-
/// The <see cref="SampleTopicViewModel.RelationshipAlias"/> uses a <see cref="RelationshipAttribute"/> to set the
294-
/// relationship key to <c>AmbiguousRelationship</c> and the <see cref="RelationshipType"/> to <see
294+
/// The <see cref="SampleTopicViewModel.RelationshipAlias"/> uses <see cref="Mapping.Annotations.RelationshipAttribute"/>
295+
/// to set the relationship key to <c>AmbiguousRelationship</c> and the <see cref="RelationshipType"/> to <see
295296
/// cref="RelationshipType.IncomingRelationship"/>. <c>AmbiguousRelationship</c> refers to a relationship that is both
296297
/// outgoing and incoming. It should be smart enough to a) look for the <c>AmbigousRelationship</c> instead of the
297298
/// <c>RelationshipAlias</c>, and b) source from the <see cref="Topic.IncomingRelationships"/> collection.
@@ -637,9 +638,7 @@ public async Task MapGetterMethods() {
637638
public async Task MapCompatibleProperties() {
638639

639640
var mappingService = new TopicMappingService(_topicRepository, new FakeViewModelLookupService());
640-
var topic = (AttributeDescriptor)TopicFactory.Create("Attribute", "AttributeDescriptor");
641-
642-
topic.EditorType = "TopicList";
641+
var topic = (TextAttribute)TopicFactory.Create("Attribute", "TextAttribute");
643642

644643
topic.VersionHistory.Add(new DateTime(1976, 10, 15, 9, 30, 00));
645644

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using Ignia.Topics.ViewModels;
7+
8+
namespace Ignia.Topics.Tests.ViewModels {
9+
10+
/*============================================================================================================================
11+
| VIEW MODEL: TEXT ATTRIBUTE (DESCRIPTOR)
12+
\---------------------------------------------------------------------------------------------------------------------------*/
13+
/// <summary>
14+
/// Provides a strongly-typed data transfer object for testing view models with properties that map to custom collections
15+
/// on the source <see cref="Topic"/>, as part of <see cref="TopicMappingServiceTest.CustomCollection"/>.
16+
/// </summary>
17+
/// <remarks>
18+
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
19+
/// </remarks>
20+
public class TextAttributeTopicViewModel : AttributeDescriptorTopicViewModel {
21+
22+
} //Class
23+
} //Namespace
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using Ignia.Topics.ViewModels;
7+
8+
namespace Ignia.Topics.Tests.ViewModels {
9+
10+
/*============================================================================================================================
11+
| VIEW MODEL: TOPIC REFERENCE ATTRIBUTE (DESCRIPTOR)
12+
\---------------------------------------------------------------------------------------------------------------------------*/
13+
/// <summary>
14+
/// Provides a strongly-typed data transfer object for testing view models with properties that map to custom collections
15+
/// on the source <see cref="Topic"/>, as part of <see cref="TopicMappingServiceTest.CustomCollection"/>.
16+
/// </summary>
17+
/// <remarks>
18+
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
19+
/// </remarks>
20+
public class TopicReferenceAttributeTopicViewModel : AttributeDescriptorTopicViewModel {
21+
22+
} //Class
23+
} //Namespace

0 commit comments

Comments
 (0)