64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using PepLib.Codes;
|
|
using PepLib.Enums;
|
|
using PepLib.Geometry;
|
|
using PepLib.IO;
|
|
using PepLib.Models;
|
|
using Xunit;
|
|
|
|
namespace PepLib.Core.Tests.IO;
|
|
|
|
public class DrawingDxfExporterTests
|
|
{
|
|
[Fact]
|
|
public void Export_RectangularLoop_ProducesFourLines()
|
|
{
|
|
// Arrange: a square 10x10 in incremental mode
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
// Mode defaults to Incremental in Loop constructor
|
|
loop.Add(new RapidMove(new Vector(0, 0))); // position at (0,0)
|
|
loop.Add(new LinearMove(new Vector(10, 0))); // → (10,0)
|
|
loop.Add(new LinearMove(new Vector(0, 10))); // → (10,10)
|
|
loop.Add(new LinearMove(new Vector(-10, 0))); // → (0,10)
|
|
loop.Add(new LinearMove(new Vector(0, -10))); // → (0,0)
|
|
drawing.Loops.Add(loop);
|
|
|
|
// Act
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
// Assert: stream is non-empty and contains 4 line entities
|
|
Assert.True(stream.Length > 0);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var lines = doc.Entities.OfType<ACadSharp.Entities.Line>().ToList();
|
|
var arcs = doc.Entities.OfType<ACadSharp.Entities.Arc>().ToList();
|
|
Assert.Equal(4, lines.Count);
|
|
Assert.Empty(arcs);
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_LoopWithArc_ProducesLineAndArc()
|
|
{
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
loop.Add(new RapidMove(new Vector(5, 0))); // start at (5,0)
|
|
loop.Add(new LinearMove(new Vector(5, 0))); // → (10,0)
|
|
loop.Add(new CircularMove(new Vector(-5, 5), new Vector(-5, 0), RotationType.CCW)); // arc: end=(5,5), center=(5,0)
|
|
drawing.Loops.Add(loop);
|
|
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var lines = doc.Entities.OfType<ACadSharp.Entities.Line>().ToList();
|
|
var arcs = doc.Entities.OfType<ACadSharp.Entities.Arc>().ToList();
|
|
Assert.Single(lines);
|
|
Assert.Single(arcs);
|
|
}
|
|
}
|