Skip to content

Commit 3e60dea

Browse files
committed
Fixed unit tests which evaluate missing interfaces in binding models
In binding models, the types used for topic references must implement `ITopicBindingModel` and the types used for relationships must implement `IAssociatedTopicBindingModel`. If they don't, an exception is thrown. Previously, this was validated via unit tests that used `TopicViewModel` as the type for each of those, thus failing validation. We now derive `ITopicViewModel` from `ITopicBindingModel` (ffe775e) and `IAssociatedTopicBindingModel` (8ad42b9), however, and thus that actually satisfies the condition. That makes view models more flexible by allowing them to double as binding models. But it breaks our unit tests. To fix this, I've introduced a new `EmptyViewModel` which implements no interfaces, and used it as the return type for the `InvalidreferenceTypeTopicBindingModel` as well as the `ContentTypes` collection type on the `InvalidRelationshipBaseTypeTopicBindingModel`. This effectively satisfies the expectations of those unit tests, and correctly returns them to throwing the expected exception.
1 parent ffe775e commit 3e60dea

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

OnTopic.Tests/BindingModels/InvalidReferenceTypeTopicBindingModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66
using System;
7-
using OnTopic.Mapping.Annotations;
87
using OnTopic.Models;
9-
using OnTopic.ViewModels;
8+
using OnTopic.Tests.ViewModels;
109

1110
namespace OnTopic.Tests.BindingModels {
1211

@@ -24,7 +23,7 @@ public class InvalidReferenceTypeTopicBindingModel : BasicTopicBindingModel {
2423

2524
public InvalidReferenceTypeTopicBindingModel(string? key = null) : base(key, "Page") { }
2625

27-
public TopicViewModel BaseTopic { get; } = new();
26+
public EmptyViewModel BaseTopic { get; } = new();
2827

2928
} //Class
3029
} //Namespace

OnTopic.Tests/BindingModels/InvalidRelationshipBaseTypeTopicBindingModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System;
77
using System.Collections.ObjectModel;
88
using OnTopic.Models;
9-
using OnTopic.ViewModels;
9+
using OnTopic.Tests.ViewModels;
1010

1111
namespace OnTopic.Tests.BindingModels {
1212

@@ -24,7 +24,7 @@ public class InvalidRelationshipBaseTypeTopicBindingModel : BasicTopicBindingMod
2424

2525
public InvalidRelationshipBaseTypeTopicBindingModel(string? key = null) : base(key, "ContentTypeDescriptor") { }
2626

27-
public Collection<TopicViewModel> ContentTypes { get; } = new();
27+
public Collection<EmptyViewModel> ContentTypes { get; } = new();
2828

2929
} //Class
3030
} //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 OnTopic.Models;
7+
8+
namespace OnTopic.Tests.ViewModels {
9+
10+
/*============================================================================================================================
11+
| VIEW MODEL: EMPTY
12+
\---------------------------------------------------------------------------------------------------------------------------*/
13+
/// <summary>
14+
/// A view model that does not implement any properties or interfaces. This will be invalid for mapping models that expect
15+
/// e.g. <see cref="IAssociatedTopicBindingModel"/> or <see cref="ITopicBindingModel"/>.
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 EmptyViewModel {
21+
22+
}
23+
}

0 commit comments

Comments
 (0)