Files
OpenNest/OpenNest.IO.Tests/NestWriterModifiedDateTests.cs
T
ajandClaude Opus 5.5 2963764215 feat(io): let NestWriter keep a nest's own modified date
Write always stamped DateLastModified with the save time. That is right
for an ordinary save, but a converter carrying another system's date
cannot keep it: every PEP nest imported into the server recorded the
import time as its modified date.

PreserveDateLastModified (init, default false) writes the nest's own
date instead; every existing caller keeps stamping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 07:14:06 -04:00

42 lines
1.3 KiB
C#

namespace OpenNest.IO.Tests;
/// <summary>
/// An ordinary save records when it happened; a converter can keep the source system's
/// modified date through write and read.
/// </summary>
public class NestWriterModifiedDateTests
{
private static readonly DateTime SourceDate = new(2019, 5, 2, 13, 50, 15, DateTimeKind.Unspecified);
[Fact]
public void Write_StampsTheSaveTimeByDefault()
{
var nest = new Nest("Stamped") { DateLastModified = SourceDate };
var before = DateTime.Now;
var restored = RoundTrip(new NestWriter(nest));
Assert.InRange(restored.DateLastModified, before.AddSeconds(-1), DateTime.Now.AddSeconds(1));
Assert.Equal(restored.DateLastModified, nest.DateLastModified);
}
[Fact]
public void Write_PreserveDateLastModified_KeepsTheNestsOwnDate()
{
var nest = new Nest("Preserved") { DateLastModified = SourceDate };
var restored = RoundTrip(new NestWriter(nest) { PreserveDateLastModified = true });
Assert.Equal(SourceDate, restored.DateLastModified);
Assert.Equal(SourceDate, nest.DateLastModified);
}
private static Nest RoundTrip(NestWriter writer)
{
using var stream = new MemoryStream();
Assert.True(writer.Write(stream));
stream.Position = 0;
return new NestReader(stream).Read();
}
}