Skip to content

Commit 5b5dae0

Browse files
committed
Introduced unit test for validation of [FilterByAttribute()]
This validates that the validation within the `[FilterByAttribute()]` constructor (384f730) works as expected by raising an `ArgumentException` if the `Key` is set to `ContentType`. In that case, the implementation should instead use `[FilterByContentType()]`.
1 parent 384f730 commit 5b5dae0

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,25 @@ public async Task Map_FilterByAttribute_ReturnsFilteredCollection() {
967967

968968
}
969969

970+
/*==========================================================================================================================
971+
| TEST: MAP: FILTER BY INVALID ATTRIBUTE: THROWS EXCEPTION
972+
\-------------------------------------------------------------------------------------------------------------------------*/
973+
/// <summary>
974+
/// Attempts to map a view model that has an invalid <see cref="FilterByAttributeAttribute.Key"/> value of <c>ContentType
975+
/// </c>; throws an <see cref="ArgumentException"/>.
976+
/// </summary>
977+
[TestMethod]
978+
[ExpectedException(typeof(ArgumentException))]
979+
public async Task Map_FilterByInvalidAttribute_ThrowsExceptions() {
980+
981+
var topic = TopicFactory.Create("Test", "FilteredInvalid");
982+
983+
var target = await _mappingService.MapAsync<FilteredInvalidTopicViewModel>(topic).ConfigureAwait(false);
984+
985+
Assert.AreEqual<int>(2, target.Children.Count);
986+
987+
}
988+
970989
/*==========================================================================================================================
971990
| TEST: MAP: FILTER BY CONTENT TYPE: RETURNS FILTERED COLLECTION
972991
\-------------------------------------------------------------------------------------------------------------------------*/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using OnTopic.Mapping.Annotations;
7+
using OnTopic.ViewModels;
8+
using OnTopic.ViewModels.Collections;
9+
10+
namespace OnTopic.Tests.ViewModels {
11+
12+
/*============================================================================================================================
13+
| VIEW MODEL: FILTERED TOPIC (INVALID)
14+
\---------------------------------------------------------------------------------------------------------------------------*/
15+
/// <summary>
16+
/// Provides a strongly-typed data transfer object for testing views properties annotated with the <see cref="
17+
/// FilterByAttributeAttribute"/>. Includes an invalid <see cref="FilterByAttributeAttribute"/>.
18+
/// </summary>
19+
/// <remarks>
20+
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
21+
/// </remarks>
22+
public class FilteredInvalidTopicViewModel {
23+
24+
[FilterByAttribute("ContentType", "Page")]
25+
public TopicViewModelCollection<TopicViewModel> Children { get; } = new();
26+
27+
} //Class
28+
} //Namespace

0 commit comments

Comments
 (0)