mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-02 04:31:34 -05:00
Document and Undo/ (ChangeScope, NestFingerprint, NestUndoState) use only Core, Data, IO and Engine, so they move into the toolkit-neutral library both desktop front ends share. Namespaces are unchanged, so the WinForms app compiles as before; it keeps using the internal scope factories and fingerprint through InternalsVisibleTo. The scope, fingerprint and SaveAs/save-point rules now have Linux tests in OpenNest.Desktop.Tests; before, only the Windows-only WinForms suite covered them.
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using OpenNest.IO;
|
|
using OpenNest.Undo;
|
|
|
|
namespace OpenNest.Desktop.Tests;
|
|
|
|
public sealed class DocumentTests : IDisposable
|
|
{
|
|
private readonly string directory =
|
|
Directory.CreateTempSubdirectory("opennest-desktop-document-").FullName;
|
|
|
|
public void Dispose() => Directory.Delete(directory, recursive: true);
|
|
|
|
[Fact]
|
|
public void SaveAs_WritesAReadableNestNamedAfterTheFile()
|
|
{
|
|
var document = new Document { Nest = TestNests.OneSquare() };
|
|
var path = Path.Combine(directory, "Renamed Job.nest");
|
|
|
|
document.SaveAs(path);
|
|
|
|
Assert.Equal("Renamed Job", document.Name);
|
|
Assert.Equal(path, document.LastSavePath);
|
|
Assert.True(document.HasSavePath);
|
|
var read = new NestReader(path).Read();
|
|
Assert.Equal("Renamed Job", read.Name);
|
|
Assert.Single(read.Plates);
|
|
Assert.Single(read.Plates[0].Parts);
|
|
}
|
|
|
|
[Fact]
|
|
public void SaveAs_MarksTheCurrentHistoryStateSaved()
|
|
{
|
|
var document = new Document { Nest = TestNests.OneSquare() };
|
|
document.History.Reset(new NestUndoState(NestSnapshot.Capture(document.Nest)));
|
|
document.Nest.Plates[0].Parts[0].Offset(1, 0);
|
|
document.History.Commit("Move", new NestUndoState(NestSnapshot.Capture(document.Nest)));
|
|
Assert.False(document.History.IsAtSavePoint);
|
|
|
|
document.SaveAs(Path.Combine(directory, "saved.nest"));
|
|
|
|
Assert.True(document.History.IsAtSavePoint);
|
|
}
|
|
|
|
[Fact]
|
|
public void Serialize_RoundTripsThroughTheNestReader()
|
|
{
|
|
var document = new Document { Nest = TestNests.OneSquare() };
|
|
|
|
using var stream = new MemoryStream(document.Serialize());
|
|
var read = new NestReader(stream).Read();
|
|
|
|
Assert.Equal(document.Nest.Plates[0].Parts.Count, read.Plates[0].Parts.Count);
|
|
}
|
|
}
|