Skip to content

Commit 0b62fe0

Browse files
committed
Merge branch 'improvement/AttributeValueDictionary' into develop
When we first introduced the `AttributeValueDictionary` (#99), we inadvertently introduced a naming conflict with the `AttributeDictionary` in the `Microsoft.AspNetCore.Mvc.ViewFeatures` namespace. Unfortunately, the `ViewFeatures` namespace is often appropriate to introduce as a global namespace for view models, resulting in a naming conflict. To disambiguate it, I have renamed it to `AttributeValueDictionary`. This isn't ideal, but there's at least some precedence for this in the ASP.NET Core MVC `RouteValueDictionary`, which is a mapping of route parameter names to route parameter values. As part of this, I also renamed associated tests and test fixtures.
2 parents c627336 + 4a7b9d8 commit 0b62fe0

20 files changed

Lines changed: 89 additions & 89 deletions

OnTopic.Tests/AttributeDictionaryTest.cs renamed to OnTopic.Tests/AttributeValueDictionaryTest.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
namespace OnTopic.Tests {
1010

1111
/*============================================================================================================================
12-
| CLASS: ATTRIBUTE DICTIONARY TEST
12+
| CLASS: ATTRIBUTE VALUE DICTIONARY TEST
1313
\---------------------------------------------------------------------------------------------------------------------------*/
1414
/// <summary>
15-
/// Provides unit tests for the <see cref="AttributeDictionary"/> class.
15+
/// Provides unit tests for the <see cref="AttributeValueDictionary"/> class.
1616
/// </summary>
1717
[ExcludeFromCodeCoverage]
1818
public class AttributeDictionaryTest {
@@ -21,8 +21,8 @@ public class AttributeDictionaryTest {
2121
| TEST: GET VALUE: RETURNS EXPECTED VALUE
2222
\-------------------------------------------------------------------------------------------------------------------------*/
2323
/// <summary>
24-
/// Constructs a <see cref="AttributeDictionary"/> based on the <paramref name="input"/> data and confirms that <see cref=
25-
/// "AttributeDictionary.GetValue(String)"/> returns the <paramref name="expected"/> value.
24+
/// Constructs a <see cref="AttributeValueDictionary"/> based on the <paramref name="input"/> data and confirms that <see
25+
/// cref="AttributeValueDictionary.GetValue(String)"/> returns the <paramref name="expected"/> value.
2626
/// </summary>
2727
/// <param name="input">The value to add to the dictionary.</param>
2828
/// <param name="expected">The value expected to be returned.</param>
@@ -35,7 +35,7 @@ public class AttributeDictionaryTest {
3535
[InlineData("Hello", "Hello")]
3636
public void GetValue_ReturnsExpectedValue(string? input, string? expected) {
3737

38-
var attributes = new AttributeDictionary() {{"Key", input}};
38+
var attributes = new AttributeValueDictionary() {{"Key", input}};
3939

4040
Assert.Equal(expected, attributes.GetValue("Key"));
4141

@@ -45,8 +45,8 @@ public void GetValue_ReturnsExpectedValue(string? input, string? expected) {
4545
| TEST: GET BOOLEAN: RETURNS EXPECTED VALUE
4646
\-------------------------------------------------------------------------------------------------------------------------*/
4747
/// <summary>
48-
/// Constructs a <see cref="AttributeDictionary"/> based on the <paramref name="input"/> data and confirms that <see cref=
49-
/// "AttributeDictionary.GetBoolean(String)"/> returns the <paramref name="expected"/> value.
48+
/// Constructs a <see cref="AttributeValueDictionary"/> based on the <paramref name="input"/> data and confirms that <see
49+
/// cref="AttributeValueDictionary.GetBoolean(String)"/> returns the <paramref name="expected"/> value.
5050
/// </summary>
5151
/// <param name="input">The value to add to the dictionary.</param>
5252
/// <param name="expected">The value expected to be returned.</param>
@@ -59,7 +59,7 @@ public void GetValue_ReturnsExpectedValue(string? input, string? expected) {
5959
[InlineData("Hello", null)]
6060
public void GetBoolean_ReturnsExpectedValue(string input, bool? expected) {
6161

62-
var attributes = new AttributeDictionary() {{"Key", input}};
62+
var attributes = new AttributeValueDictionary() {{"Key", input}};
6363

6464
Assert.Equal(expected, attributes.GetBoolean("Key"));
6565

@@ -69,8 +69,8 @@ public void GetBoolean_ReturnsExpectedValue(string input, bool? expected) {
6969
| TEST: GET INTEGER: RETURNS EXPECTED VALUE
7070
\-------------------------------------------------------------------------------------------------------------------------*/
7171
/// <summary>
72-
/// Constructs a <see cref="AttributeDictionary"/> based on the <paramref name="input"/> data and confirms that <see cref=
73-
/// "AttributeDictionary.GetInteger(String)"/> returns the <paramref name="expected"/> value.
72+
/// Constructs a <see cref="AttributeValueDictionary"/> based on the <paramref name="input"/> data and confirms that <see
73+
/// cref="AttributeValueDictionary.GetInteger(String)"/> returns the <paramref name="expected"/> value.
7474
/// </summary>
7575
/// <param name="input">The value to add to the dictionary.</param>
7676
/// <param name="expected">The value expected to be returned.</param>
@@ -82,7 +82,7 @@ public void GetBoolean_ReturnsExpectedValue(string input, bool? expected) {
8282
[InlineData("Hello", null)]
8383
public void GetInteger_ReturnsExpectedValue(string input, int? expected) {
8484

85-
var attributes = new AttributeDictionary() {{"Key", input}};
85+
var attributes = new AttributeValueDictionary() {{"Key", input}};
8686

8787
Assert.Equal(expected, attributes.GetInteger("Key"));
8888

@@ -92,8 +92,8 @@ public void GetInteger_ReturnsExpectedValue(string input, int? expected) {
9292
| TEST: GET DOUBLE: RETURNS EXPECTED VALUE
9393
\-------------------------------------------------------------------------------------------------------------------------*/
9494
/// <summary>
95-
/// Constructs a <see cref="AttributeDictionary"/> based on the <paramref name="input"/> data and confirms that <see cref=
96-
/// "AttributeDictionary.GetDouble(String)"/> returns the <paramref name="expected"/> value.
95+
/// Constructs a <see cref="AttributeValueDictionary"/> based on the <paramref name="input"/> data and confirms that <see
96+
/// cref="AttributeValueDictionary.GetDouble(String)"/> returns the <paramref name="expected"/> value.
9797
/// </summary>
9898
/// <param name="input">The value to add to the dictionary.</param>
9999
/// <param name="expected">The value expected to be returned.</param>
@@ -106,7 +106,7 @@ public void GetInteger_ReturnsExpectedValue(string input, int? expected) {
106106
[InlineData("Hello", null)]
107107
public void GetDouble_ReturnsExpectedValue(string input, double? expected) {
108108

109-
var attributes = new AttributeDictionary() {{"Key", input}};
109+
var attributes = new AttributeValueDictionary() {{"Key", input}};
110110

111111
Assert.Equal(expected, attributes.GetDouble("Key"));
112112

@@ -116,8 +116,8 @@ public void GetDouble_ReturnsExpectedValue(string input, double? expected) {
116116
| TEST: GET DATE/TIME: RETURNS EXPECTED VALUE
117117
\-------------------------------------------------------------------------------------------------------------------------*/
118118
/// <summary>
119-
/// Constructs a <see cref="AttributeDictionary"/> based on the <paramref name="input"/> data and confirms that <see cref=
120-
/// "AttributeDictionary.GetDateTime(String)"/> returns the expected value.
119+
/// Constructs a <see cref="AttributeValueDictionary"/> based on the <paramref name="input"/> data and confirms that <see
120+
/// cref="AttributeValueDictionary.GetDateTime(String)"/> returns the expected value.
121121
/// </summary>
122122
/// <param name="input">The value to add to the dictionary.</param>
123123
/// <param name="isSet">Determines whether a valid <see cref="DateTime"/> is expected in response.</param>
@@ -130,7 +130,7 @@ public void GetDouble_ReturnsExpectedValue(string input, double? expected) {
130130
[InlineData("Hello", false)]
131131
public void GetDate_ReturnsExpectedValue(string input, bool isSet) {
132132

133-
var attributes = new AttributeDictionary() {{"Key", input}};
133+
var attributes = new AttributeValueDictionary() {{"Key", input}};
134134

135135
Assert.Equal(isSet? new DateTime(1976, 10, 15, 1, 2, 3) : null, attributes.GetDateTime("Key"));
136136

@@ -140,16 +140,16 @@ public void GetDate_ReturnsExpectedValue(string input, bool isSet) {
140140
| TEST: GET URI: RETURNS EXPECTED VALUE
141141
\-------------------------------------------------------------------------------------------------------------------------*/
142142
/// <summary>
143-
/// Constructs a <see cref="AttributeDictionary"/> based on the <paramref name="input"/> data and confirms that <see cref=
144-
/// "AttributeDictionary.GetUri(String)"/> returns the expected value.
143+
/// Constructs a <see cref="AttributeValueDictionary"/> based on the <paramref name="input"/> data and confirms that <see
144+
/// cref="AttributeValueDictionary.GetUri(String)"/> returns the expected value.
145145
/// </summary>
146146
/// <param name="input">The value to add to the dictionary.</param>
147147
[Theory]
148148
[InlineData("https://www.github.com/OnTopicCMS")]
149149
[InlineData("Some:\\\\URL")]
150150
public void GetUri_ReturnsExpectedValue(string input) {
151151

152-
var attributes = new AttributeDictionary() {{"Key", input}};
152+
var attributes = new AttributeValueDictionary() {{"Key", input}};
153153

154154
Assert.Equal(new Uri(input), attributes.GetUri("Key"));
155155

@@ -159,13 +159,13 @@ public void GetUri_ReturnsExpectedValue(string input) {
159159
| TEST: GET {TYPE}: INVALID KEY: RETURNS NULL
160160
\-------------------------------------------------------------------------------------------------------------------------*/
161161
/// <summary>
162-
/// Constructs a <see cref="AttributeDictionary"/> and confirms that each of the <see cref="AttributeDictionary.GetValue(
163-
/// String)"/> methods return <c>null</c> if an invalid key is passed.
162+
/// Constructs a <see cref="AttributeValueDictionary"/> and confirms that each of the <see cref="AttributeValueDictionary.
163+
/// GetValue(String)"/> methods return <c>null</c> if an invalid key is passed.
164164
/// </summary>
165165
[Fact]
166166
public void GetType_InvalidKey_ReturnsNull() {
167167

168-
var attributes = new AttributeDictionary();
168+
var attributes = new AttributeValueDictionary();
169169

170170
Assert.Null(attributes.GetValue("MissingKey"));
171171
Assert.Null(attributes.GetBoolean("MissingKey"));
@@ -180,8 +180,8 @@ public void GetType_InvalidKey_ReturnsNull() {
180180
| TEST: AS ATTRIBUTE DICTIONARY: EXCLUDED KEYS: EXCLUDED
181181
\-------------------------------------------------------------------------------------------------------------------------*/
182182
/// <summary>
183-
/// Constructs a <see cref="AttributeDictionary"/> using <see cref="AttributeCollection.AsAttributeDictionary(Boolean)"/>
184-
/// and confirms that <see cref="AttributeDictionary.GetValue(String)"/> doesn't include the excluded values.
183+
/// Constructs a <see cref="AttributeValueDictionary"/> using <see cref="AttributeCollection.AsAttributeDictionary(Boolean
184+
/// )"/> and confirms that <see cref="AttributeValueDictionary.GetValue(String)"/> doesn't include the excluded values.
185185
/// </summary>
186186
[Fact]
187187
public void AsAttributeDictionary_ExcludedKeys_Excluded() {
@@ -205,8 +205,8 @@ public void AsAttributeDictionary_ExcludedKeys_Excluded() {
205205
| TEST: AS ATTRIBUTE DICTIONARY: INHERIT FROM BASE: INHERITS VALUES
206206
\-------------------------------------------------------------------------------------------------------------------------*/
207207
/// <summary>
208-
/// Constructs a <see cref="AttributeDictionary"/> using <see cref="AttributeCollection.AsAttributeDictionary(Boolean)"/>
209-
/// and confirms that <see cref="AttributeDictionary.GetValue(String)"/> correctly inherits values.
208+
/// Constructs a <see cref="AttributeValueDictionary"/> using <see cref="AttributeCollection.AsAttributeDictionary(Boolean
209+
/// )"/> and confirms that <see cref="AttributeValueDictionary.GetValue(String)"/> correctly inherits values.
210210
/// </summary>
211211
[Fact]
212212
public void AsAttributeDictionary_InheritFromBase_InheritsValues() {

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public TopicMappingServiceTest(TopicInfrastructureFixture<StubTopicRepository> f
7474
/// <remarks>
7575
/// <para>
7676
/// The <see cref="TopicMappingService"/> includes functionality to map properties to attributes via a constructor that
77-
/// accepts a <see cref="AttributeDictionary"/>. This introduces some overhead which is not cost effective if there are
78-
/// not any attributes that map to properties. For larger numbers of mapped attributes, however, the <see cref="
79-
/// AttributeDictionary"/> can reduce the mapping time considerably, while also giving more control over the model
77+
/// accepts a <see cref="AttributeValueDictionary"/>. This introduces some overhead which is not cost effective if there
78+
/// are not any attributes that map to properties. For larger numbers of mapped attributes, however, the <see cref="
79+
/// AttributeValueDictionary"/> can reduce the mapping time considerably, while also giving more control over the model
8080
/// construction to the model developer. This test is intended to help identify and optimize that threshold based on
81-
/// improvements to the underlying <see cref="AttributeDictionary"/>, <see cref="TopicMappingService.MapAsync(Topic?,
82-
/// AssociationTypes)"/>, and <see cref="AttributeCollection.AsAttributeDictionary(bool)"/> convenience method.
81+
/// improvements to the underlying <see cref="AttributeValueDictionary"/>, <see cref="TopicMappingService.MapAsync(
82+
/// Topic?, AssociationTypes)"/>, and <see cref="AttributeCollection.AsAttributeDictionary(bool)"/> convenience method.
8383
/// </para>
8484
/// <para>
8585
/// This is only intended to be enabled when needed for specialized performance testing.
@@ -287,7 +287,7 @@ public async Task Map_Generic_ReturnsConvertedProperty() {
287287
\-------------------------------------------------------------------------------------------------------------------------*/
288288
/// <summary>
289289
/// Establishes a <see cref="TopicMappingService"/> and attempts to map a view model with a constructor containing a <see
290-
/// cref="AttributeDictionary"/>. Confirms that the expected model is returned.
290+
/// cref="AttributeValueDictionary"/>. Confirms that the expected model is returned.
291291
/// </summary>
292292
[Fact]
293293
public async Task Map_AttributeDictionary_ReturnsNewModel() {
@@ -307,7 +307,7 @@ public async Task Map_AttributeDictionary_ReturnsNewModel() {
307307
topic.Attributes.SetValue("UnmappedProperty", "Unmapped Value");
308308
topic.VersionHistory.Add(lastModified);
309309

310-
var target = await _mappingService.MapAsync<AttributeDictionaryConstructorTopicViewModel>(topic).ConfigureAwait(false);
310+
var target = await _mappingService.MapAsync<AttributeValueDictionaryConstructorTopicViewModel>(topic).ConfigureAwait(false);
311311

312312
Assert.Equal("Value", target?.Title);
313313
Assert.Equal("Short Title", target?.ShortTitle);

OnTopic.Tests/ViewModels/AttributeDictionaryConstructorTopicViewModel.cs renamed to OnTopic.Tests/ViewModels/AttributeValueDictionaryConstructorTopicViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ namespace OnTopic.Tests.ViewModels {
1212
| VIEW MODEL: ATTRIBUTE DICTIONARY CONSTRUCTOR
1313
\---------------------------------------------------------------------------------------------------------------------------*/
1414
/// <summary>
15-
/// Provides a strongly-typed data transfer object for testing a constructor with a <see cref="AttributeDictionary"/>.
15+
/// Provides a strongly-typed data transfer object for testing a constructor with a <see cref="AttributeValueDictionary"/>.
1616
/// </summary>
1717
/// <remarks>
1818
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
1919
/// </remarks>
20-
public record AttributeDictionaryConstructorTopicViewModel: PageTopicViewModel {
20+
public record AttributeValueDictionaryConstructorTopicViewModel: PageTopicViewModel {
2121

2222
/*==========================================================================================================================
2323
| CONSTRUCTOR
2424
\-------------------------------------------------------------------------------------------------------------------------*/
2525
/// <summary>
26-
/// Initializes a new <see cref="AttributeDictionaryConstructorTopicViewModel"/> with an <paramref name="attributes"/>
27-
/// dictionary.
26+
/// Initializes a new <see cref="AttributeValueDictionaryConstructorTopicViewModel"/> with an <paramref name="attributes"
27+
/// /> dictionary.
2828
/// </summary>
29-
/// <param name="attributes">An <see cref="AttributeDictionaryConstructorTopicViewModel"/> of attribute values.</param>
30-
public AttributeDictionaryConstructorTopicViewModel(AttributeDictionary attributes) : base(attributes) {
29+
/// <param name="attributes">An <see cref="AttributeValueDictionaryConstructorTopicViewModel"/> of attribute values.</param>
30+
public AttributeValueDictionaryConstructorTopicViewModel(AttributeValueDictionary attributes) : base(attributes) {
3131
Contract.Requires(attributes, nameof(attributes));
3232
MappedProperty = attributes.GetValue(nameof(MappedProperty));
3333
}
3434

3535
/// <summary>
36-
/// Initializes a new <see cref="AttributeDictionaryConstructorTopicViewModel"/> with no parameters.
36+
/// Initializes a new <see cref="AttributeValueDictionaryConstructorTopicViewModel"/> with no parameters.
3737
/// </summary>
38-
public AttributeDictionaryConstructorTopicViewModel() { }
38+
public AttributeValueDictionaryConstructorTopicViewModel() { }
3939

4040
/*==========================================================================================================================
4141
| PROPERTIES

OnTopic.Tests/ViewModels/LoadTestingViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class LoadTestingViewModel: KeyOnlyTopicViewModel {
2626
/// <summary>
2727
/// Initializes a new <see cref="LoadTestingViewModel"/> with an <paramref name="attributes"/> dictionary.
2828
/// </summary>
29-
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
30-
public LoadTestingViewModel(AttributeDictionary attributes) {
29+
/// <param name="attributes">An <see cref="AttributeValueDictionary"/> of attribute values.</param>
30+
public LoadTestingViewModel(AttributeValueDictionary attributes) {
3131
Contract.Requires(attributes);
3232
Property0 = attributes.GetInteger("Property0");
3333
Property1 = attributes.GetInteger("Property1");

OnTopic.ViewModels/TopicViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public record TopicViewModel: ITopicViewModel, ICoreTopicViewModel, IAssociatedT
2626
/// <summary>
2727
/// Initializes a new <see cref="TopicViewModel"/> with an <paramref name="attributes"/> dictionary.
2828
/// </summary>
29-
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
30-
public TopicViewModel(AttributeDictionary attributes) {
29+
/// <param name="attributes">An <see cref="AttributeValueDictionary"/> of attribute values.</param>
30+
public TopicViewModel(AttributeValueDictionary attributes) {
3131
Contract.Requires(attributes, nameof(attributes));
3232
IsHidden = attributes.GetBoolean("IsHidden")?? IsHidden;
3333
View = attributes.GetValue("View");

OnTopic.ViewModels/_contentTypes/ContentListTopicViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public record ContentListTopicViewModel: PageTopicViewModel {
2525
/// <summary>
2626
/// Initializes a new <see cref="ContentListTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
2727
/// </summary>
28-
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
29-
public ContentListTopicViewModel(AttributeDictionary attributes): base(attributes) {
28+
/// <param name="attributes">An <see cref="AttributeValueDictionary"/> of attribute values.</param>
29+
public ContentListTopicViewModel(AttributeValueDictionary attributes): base(attributes) {
3030
Contract.Requires(attributes, nameof(attributes));
3131
IsIndexed = attributes.GetBoolean(nameof(IsIndexed))?? IsIndexed;
3232
IndexLabel = attributes.GetValue(nameof(IndexLabel))?? IndexLabel;

OnTopic.ViewModels/_contentTypes/IndexTopicViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public record IndexTopicViewModel: PageTopicViewModel {
2525
/// <summary>
2626
/// Initializes a new <see cref="IndexTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
2727
/// </summary>
28-
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
29-
public IndexTopicViewModel(AttributeDictionary attributes): base(attributes) { }
28+
/// <param name="attributes">An <see cref="AttributeValueDictionary"/> of attribute values.</param>
29+
public IndexTopicViewModel(AttributeValueDictionary attributes): base(attributes) { }
3030

3131
/// <summary>
3232
/// Initializes a new <see cref="IndexTopicViewModel"/> with no parameters.

0 commit comments

Comments
 (0)