Skip to content

Commit affbe10

Browse files
committed
Set LastModified to fallback to VersionHistory
Also added unit test to validate behavior.
1 parent b516f5a commit affbe10

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

Ignia.Topics.Tests/TopicTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,32 @@ public void Topic_TitleTest() {
224224

225225
}
226226

227+
/*==========================================================================================================================
228+
| TEST: LAST MODIFIED
229+
\-------------------------------------------------------------------------------------------------------------------------*/
230+
/// <summary>
231+
/// Returns the last modified date using a couple of techniques, and ensures it's returned correctly.
232+
/// </summary>
233+
[TestMethod]
234+
public void Topic_LastModifiedTest() {
235+
236+
var topic1 = TopicFactory.Create("Topic1", "Page");
237+
var topic2 = TopicFactory.Create("Topic2", "Page");
238+
var topic3 = TopicFactory.Create("Topic3", "Page");
239+
240+
var lastModified = new DateTime(1976, 10, 15);
241+
242+
topic1.LastModified = lastModified;
243+
244+
topic2.VersionHistory.Add(lastModified);
245+
topic3.Attributes.SetValue("LastModified", lastModified.ToShortDateString());
246+
247+
Assert.AreEqual<DateTime>(lastModified, topic1.LastModified);
248+
Assert.AreEqual<DateTime>(lastModified, topic2.LastModified);
249+
Assert.AreEqual<DateTime>(lastModified, topic3.LastModified);
250+
251+
}
252+
227253
/*==========================================================================================================================
228254
| TEST: DERIVED TOPIC
229255
\-------------------------------------------------------------------------------------------------------------------------*/

Ignia.Topics/Topic.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,14 @@ public DateTime LastModified {
319319
get {
320320

321321
/*----------------------------------------------------------------------------------------------------------------------
322-
| Return minimum date value, if LastModified is not already populated
322+
| Establish default value
323323
\---------------------------------------------------------------------------------------------------------------------*/
324-
if (String.IsNullOrWhiteSpace(Attributes.GetValue("LastModified", ""))) {
325-
return DateTime.MinValue;
326-
}
324+
var defaultValue = VersionHistory.Count > 0 ? VersionHistory.LastOrDefault() : DateTime.MinValue;
327325

328326
/*----------------------------------------------------------------------------------------------------------------------
329327
| Return converted string attribute value, if available
330328
\---------------------------------------------------------------------------------------------------------------------*/
331-
var lastModified = Attributes.GetValue("LastModified");
329+
var lastModified = Attributes.GetValue("LastModified", defaultValue.ToString());
332330

333331
// Return converted DateTime
334332
if (DateTime.TryParse(lastModified, out var dateTimeValue)) {
@@ -338,9 +336,7 @@ public DateTime LastModified {
338336
/*----------------------------------------------------------------------------------------------------------------------
339337
| Otherwise, return default of minimum value
340338
\---------------------------------------------------------------------------------------------------------------------*/
341-
else {
342-
return DateTime.MinValue;
343-
}
339+
return defaultValue;
344340

345341
}
346342
set => SetAttributeValue("LastModified", value.ToString());

0 commit comments

Comments
 (0)