Files

52 lines
2.1 KiB
C#
Raw Permalink Normal View History

2026-08-17 11:52:48 +08:00
using System;
using System.IO;
2026-08-17 11:52:48 +08:00
using Xunit;
namespace Prophet.CoopWithDsh.Tests
{
public sealed class SnapshotModelTests
{
[Fact]
public void CreateDeduplicatesPathsAndPreservesDirtyState()
{
var snapshot = SnapshotModel.Create("one", 10, "F:\\Project\\App.sln", new[] {
new OpenDocument { Path = "F:\\Project\\main.cs", Label = "main.cs", Dirty = false },
new OpenDocument { Path = "f:\\project\\MAIN.cs", Label = "MAIN.cs", Dirty = true },
}, new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero));
Assert.Equal(1, snapshot.Version);
Assert.Equal("visualstudio", snapshot.Ide);
Assert.Single(snapshot.Documents);
Assert.True(snapshot.Documents[0].Dirty);
Assert.Equal("2026-01-01T00:00:00.0000000Z", snapshot.UpdatedAt);
}
[Fact]
public void PublisherWritesProtocolV1WithoutExternalJsonRuntime()
{
var root = Path.Combine(Path.GetTempPath(), "coop-with-dsh-test-" + Guid.NewGuid().ToString("N"));
try
{
using (var publisher = new SnapshotPublisher(root))
{
var snapshot = SnapshotModel.Create(publisher.InstanceId, 42, null, new[] {
new OpenDocument { Path = "F:\\Project\\main.cs", Label = "main.cs", Dirty = true },
}, new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero));
publisher.Publish(snapshot);
var json = File.ReadAllText(publisher.FilePath);
Assert.Contains("\"version\":1", json);
Assert.Contains("\"ide\":\"visualstudio\"", json);
Assert.Contains("\"documents\":[{", json);
Assert.Contains("\"dirty\":true", json);
Assert.DoesNotContain("\"workspace\"", json);
}
}
finally
{
if (Directory.Exists(root)) Directory.Delete(root, true);
}
}
2026-08-17 11:52:48 +08:00
}
}