Skip to content

Commit 82e845a

Browse files
committed
Introduced ability to map Uri types
2 parents 5df14d8 + df6770e commit 82e845a

10 files changed

Lines changed: 42 additions & 11 deletions

File tree

OnTopic.AspNetCore.Mvc.Tests/ValidateTopicAttributeTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ValidateTopicAttributeTest {
3434
/// <summary>
3535
/// Given a <see cref="Controller"/>, generates a barebones <see cref="ActionExecutingContext"/> for testing.
3636
/// </summary>
37-
public ActionExecutingContext GetActionExecutingContext(Controller controller) {
37+
public static ActionExecutingContext GetActionExecutingContext(Controller controller) {
3838

3939
var modelState = new ModelStateDictionary();
4040

@@ -62,7 +62,7 @@ public ActionExecutingContext GetActionExecutingContext(Controller controller) {
6262
/// <summary>
6363
/// Generates a barebones <see cref="ControllerContext"/> for testing a controller.
6464
/// </summary>
65-
public ControllerContext GetControllerContext() =>
65+
public static ControllerContext GetControllerContext() =>
6666
new ControllerContext(
6767
new ActionContext() {
6868
HttpContext = new DefaultHttpContext(),
@@ -77,7 +77,7 @@ public ControllerContext GetControllerContext() =>
7777
/// <summary>
7878
/// Generates a barebones <see cref="ControllerContext"/> for testing a controller.
7979
/// </summary>
80-
public TopicController GetTopicController(Topic topic) =>
80+
public static TopicController GetTopicController(Topic topic) =>
8181
new TopicController(
8282
new DummyTopicRepository(),
8383
new DummyTopicMappingService()

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,14 @@ public async Task MapNullablePropertiesWithInvalidValues() {
182182
topic.Attributes.SetValue("NullableInteger", "A");
183183
topic.Attributes.SetValue("NullableBoolean", "43");
184184
topic.Attributes.SetValue("NullableDateTime", "Hello World");
185+
topic.Attributes.SetValue("NullableUrl", "invalid://Web\\Path\\File!?@Query=String?");
185186

186187
var target = await mappingService.MapAsync<NullablePropertyTopicViewModel>(topic).ConfigureAwait(false);
187188

188189
Assert.IsNull(target.NullableInteger);
189190
Assert.IsNull(target.NullableBoolean);
190191
Assert.IsNull(target.NullableDateTime);
192+
Assert.IsNull(target.NullableUrl);
191193

192194
//The following should not be null since they map to non-nullable properties which will have default values
193195
Assert.AreEqual(topic.Title, target.Title);
@@ -214,6 +216,7 @@ public async Task MapNullablePropertiesWithValidValues() {
214216
topic.Attributes.SetValue("NullableDouble", "3.14159265359");
215217
topic.Attributes.SetValue("NullableBoolean", "tRuE");
216218
topic.Attributes.SetValue("NullableDateTime", "10/15/1976");
219+
topic.Attributes.SetValue("NullableUrl", "/Web/Path/File?Query=String");
217220

218221
topic.Attributes.SetValue("Title", "Hello World.");
219222
topic.Attributes.SetValue("IsHidden", "true");
@@ -226,6 +229,7 @@ public async Task MapNullablePropertiesWithValidValues() {
226229
Assert.AreEqual<double?>(3.14159265359, target.NullableDouble);
227230
Assert.AreEqual<bool?>(true, target.NullableBoolean);
228231
Assert.AreEqual<DateTime?>(new DateTime(1976, 10, 15), target.NullableDateTime);
232+
Assert.AreEqual<Uri?>(new Uri("/Web/Path/File?Query=String", UriKind.RelativeOrAbsolute), target.NullableUrl);
229233

230234
Assert.AreEqual<string?>(topic.Title, target.Title);
231235
Assert.AreEqual<bool?>(target.IsHidden, target.IsHidden);

OnTopic.Tests/ViewModels/NullablePropertyTopicViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ public class NullablePropertyTopicViewModel {
2828

2929
public DateTime? NullableDateTime { get; set; }
3030

31-
public String? Title { get; set; }
31+
public Uri? NullableUrl { get; set; }
32+
33+
public string? Title { get; set; }
3234

3335
public bool? IsHidden { get; set; }
3436

3537
public DateTime? LastModified { get; set; }
3638

39+
3740
} //Class
3841
} //Namespace

OnTopic.ViewModels/ContentItemTopicViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66

7+
using System;
8+
79
namespace OnTopic.ViewModels {
810

911
/*============================================================================================================================
@@ -33,15 +35,15 @@ public class ContentItemTopicViewModel: ItemTopicViewModel {
3335
/// <summary>
3436
/// Gets an optional URL for additional information that should be linked to.
3537
/// </summary>
36-
public string? LearnMoreUrl { get; set; }
38+
public Uri? LearnMoreUrl { get; set; }
3739

3840
/*==========================================================================================================================
3941
| THUMBNAIL IMAGE
4042
\-------------------------------------------------------------------------------------------------------------------------*/
4143
/// <summary>
4244
/// Gets an optional path to a thumbnail image that should accompany the content item.
4345
/// </summary>
44-
public string? ThumbnailImage { get; set; }
46+
public Uri? ThumbnailImage { get; set; }
4547

4648
/*==========================================================================================================================
4749
| CATEGORY

OnTopic.ViewModels/PageTopicViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public class PageTopicViewModel: TopicViewModel, IPageTopicViewModel {
4848
/// <inheritdoc />
4949
public string? MetaKeywords { get; set; }
5050

51+
/*==========================================================================================================================
52+
| META KEYWORDS
53+
\-------------------------------------------------------------------------------------------------------------------------*/
54+
/// <summary>
55+
/// Determines whether or not search engines are expected to index the page.
56+
/// </summary>
5157
public bool? NoIndex { get; set; }
5258

5359
/*==========================================================================================================================

OnTopic.ViewModels/SectionTopicViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66

7+
using System;
8+
79
namespace OnTopic.ViewModels {
810

911
/*============================================================================================================================
@@ -25,7 +27,7 @@ public class SectionTopicViewModel : TopicViewModel {
2527
/// <summary>
2628
/// Provides a header image which may be displayed at the top of a section.
2729
/// </summary>
28-
public string? HeaderImageUrl { get; set; }
30+
public Uri? HeaderImageUrl { get; set; }
2931

3032
} //Class
3133
} //Namespace

OnTopic.ViewModels/TopicViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public class TopicViewModel: ITopicViewModel {
7070
/// <inheritdoc />
7171
public bool IsHidden { get; set; }
7272

73+
/*==========================================================================================================================
74+
| LAST MODIFIED
75+
\-------------------------------------------------------------------------------------------------------------------------*/
76+
/// <summary>
77+
/// The date that the topic was last modified on.
78+
/// </summary>
7379
public DateTime LastModified { get; set; }
7480

7581
/*==========================================================================================================================

OnTopic.ViewModels/VideoTopicViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66

7+
using System;
8+
79
namespace OnTopic.ViewModels {
810

911
/*============================================================================================================================
@@ -25,15 +27,15 @@ public class VideoTopicViewModel: PageTopicViewModel {
2527
/// <summary>
2628
/// Provides a URL reference to a video to display on the page.
2729
/// </summary>
28-
public string? VideoUrl { get; set; }
30+
public Uri? VideoUrl { get; set; }
2931

3032
/*==========================================================================================================================
3133
| POSTER URL
3234
\-------------------------------------------------------------------------------------------------------------------------*/
3335
/// <summary>
3436
/// Provides a URL reference to an image to display prior to playing the video.
3537
/// </summary>
36-
public string? PosterUrl { get; set; }
38+
public Uri? PosterUrl { get; set; }
3739

3840
} //Class
3941
} //Namespace

OnTopic/Internal/Reflection/TypeMemberInfoCollection.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ static TypeMemberInfoCollection() {
4141
typeof(double?),
4242
typeof(string),
4343
typeof(DateTime),
44-
typeof(DateTime?)
44+
typeof(DateTime?),
45+
typeof(Uri)
4546
};
4647
}
4748

@@ -434,6 +435,11 @@ private static bool IsSettableType(Type sourceType, Type? targetType = null) {
434435
valueObject = date;
435436
}
436437
}
438+
else if (type.Equals(typeof(Uri))) {
439+
if (Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var uri)) {
440+
valueObject = uri;
441+
}
442+
}
437443

438444
return valueObject;
439445

OnTopic/Metadata/ContentTypeDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace OnTopic.Metadata {
2020
/// <para>
2121
/// Each topic is associated with a content type. The content type determines which attributes are displayed in the Topics
2222
/// Editor (via the <see cref="AttributeDescriptors"/> property). The content type also determines, by default, which view
23-
/// is rendered by the <see cref="Topics.ITopicRoutingService"/> (assuming the value isn't overwritten down the pipe).
23+
/// is rendered by the <see cref="ITopicRoutingService"/> (assuming the value isn't overwritten down the pipe).
2424
/// </para>
2525
/// <para>
2626
/// Each content type associated with a <see cref="Topic"/> is itself a <see cref="Topic"/> with a Content Type of

0 commit comments

Comments
 (0)