Skip to content

Commit 9f63d37

Browse files
committed
Introduced test to validate Version is available on TopicLoaded event
The `TopicLoadEventArgs` event has an optional `Version` property that should be populated when loading a specific version. This test currently fails due to a bug in the `StubTopicRepository` test double, which will be fixed in a subsequent commit.
1 parent e315506 commit 9f63d37

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

OnTopic.Tests/TopicRepositoryBaseTest.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ public void Delete_AttributeDescriptor_UpdatesContentTypeCache() {
936936
| TEST: LOAD: TOPIC LOADED EVENT: IS RAISED
937937
\-------------------------------------------------------------------------------------------------------------------------*/
938938
/// <summary>
939-
/// Loads a topic using <see cref="StubTopicRepository.Load(Int32, DateTime, Topic?)"/> and ensures that the <see cref="
939+
/// Loads a topic using <see cref="StubTopicRepository.Load(Int32, Topic?, Boolean)"/> and ensures that the <see cref="
940940
/// ITopicRepository.TopicLoaded"/> event is raised.
941941
/// </summary>
942942
[TestMethod]
@@ -946,11 +946,39 @@ public void Load_TopicLoadedEvent_IsRaised() {
946946

947947
_cachedTopicRepository.TopicLoaded += eventHandler;
948948

949-
var topic = _topicRepository.Load("Root:Web");
949+
var topic = _topicRepository.Load("Root:Web");
950+
951+
_cachedTopicRepository.TopicLoaded -= eventHandler;
952+
953+
Assert.IsTrue(hasFired);
954+
955+
void eventHandler(object? sender, TopicLoadEventArgs eventArgs) => hasFired = true;
956+
957+
}
958+
959+
/*==========================================================================================================================
960+
| TEST: LOAD: TOPIC LOADED EVENT: IS RAISED WITH VERSION
961+
\-------------------------------------------------------------------------------------------------------------------------*/
962+
/// <summary>
963+
/// Loads a topic using <see cref="StubTopicRepository.Load(Int32, DateTime, Topic?)"/> and ensures that the <see cref="
964+
/// ITopicRepository.TopicLoaded"/> event is raised.
965+
/// </summary>
966+
[TestMethod]
967+
public void Load_TopicLoadedEvent_IsRaisedWithVersion() {
968+
969+
var hasFired = false;
970+
var topicId = _topicRepository.Load("Root:Web")?.Id;
971+
var version = DateTime.UtcNow;
972+
973+
_cachedTopicRepository.TopicLoaded += eventHandler;
974+
975+
var topic = _topicRepository.Load(topicId?? -1, version);
950976

951977
_cachedTopicRepository.TopicLoaded -= eventHandler;
952978

953979
Assert.IsTrue(hasFired);
980+
Assert.AreEqual<int?>(topicId, topic?.Id);
981+
Assert.AreEqual<DateTime?>(version, topic?.VersionHistory.LastOrDefault());
954982

955983
void eventHandler(object? sender, TopicLoadEventArgs eventArgs) => hasFired = true;
956984

0 commit comments

Comments
 (0)