mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-07 15:52:20 -04:00
Prepare BOM rows for quantity editing:
- BomQuantity.TryParse accepts only a whole number of at least 1
(surrounding spaces allowed; no sign, decimal, exponent, separator or
overflow).
- BomPartRow keeps the BOM's own quantity (BomQty), refuses invalid
typed quantities in TrySetQuantity, and raises PropertyChanged for
Material, Thickness and Qty plus the status they affect, so a bound
grid can refresh.
- A blank BOM quantity becomes 1, as it was imported before, but is now
visible in the row and counted in the summary ("had no BOM quantity
(1 used)"). A BOM quantity below 1 is no longer imported as 0: the
row reads "Needs quantity" until the operator enters one.
BomImportFlowTests covers BOM items to rows to an edited quantity to the
group total and the created nest's required quantity. Mutation reds:
a zero floor, signed or decimal input, ignoring the quantity in the
status, not assuming 1 for blanks, setting unparsed text and dropping
the status notification each fail the Bom tests.
154 lines
4.5 KiB
C#
154 lines
4.5 KiB
C#
using OpenNest.IO.Bom;
|
|
|
|
namespace OpenNest.Tests.Bom;
|
|
|
|
public class BomPartRowTests
|
|
{
|
|
[Theory]
|
|
[InlineData(null, "/d/PT01.dxf", "Steel", 0.25, BomRowStatus.NoFileName)]
|
|
[InlineData(" ", "/d/PT01.dxf", "Steel", 0.25, BomRowStatus.NoFileName)]
|
|
[InlineData("PT01", null, "Steel", 0.25, BomRowStatus.NoDrawing)]
|
|
[InlineData("PT01", "/d/PT01.dxf", null, 0.25, BomRowStatus.NeedsMaterial)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "\t", 0.25, BomRowStatus.NeedsMaterial)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "Steel", null, BomRowStatus.NeedsThickness)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "Steel", 0.0, BomRowStatus.NeedsThickness)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "Steel", -0.25, BomRowStatus.NeedsThickness)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "Steel", double.NaN, BomRowStatus.NeedsThickness)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "Steel", double.PositiveInfinity, BomRowStatus.NeedsThickness)]
|
|
[InlineData("PT01", "/d/PT01.dxf", "Steel", 0.25, BomRowStatus.Ready)]
|
|
public void Status_FollowsTheFirstMissingValue(
|
|
string? fileName,
|
|
string? dxfPath,
|
|
string? material,
|
|
double? thickness,
|
|
BomRowStatus expected
|
|
)
|
|
{
|
|
var row = new BomPartRow
|
|
{
|
|
FileName = fileName,
|
|
DxfPath = dxfPath,
|
|
Material = material,
|
|
Thickness = thickness,
|
|
Qty = 1,
|
|
};
|
|
|
|
Assert.Equal(expected, row.Status);
|
|
Assert.Equal(expected is not (BomRowStatus.NoFileName or BomRowStatus.NoDrawing), row.IsEditable);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData(0)]
|
|
[InlineData(-2)]
|
|
public void Status_NeedsAQuantityOfAtLeastOne(int? qty)
|
|
{
|
|
var row = ReadyRow();
|
|
row.Qty = qty;
|
|
|
|
Assert.Equal(BomRowStatus.NeedsQuantity, row.Status);
|
|
Assert.True(row.IsEditable);
|
|
}
|
|
|
|
[Fact]
|
|
public void Status_ChangesWhenTheOperatorFillsInAValue()
|
|
{
|
|
var row = new BomPartRow { FileName = "PT01", DxfPath = "/d/PT01.dxf" };
|
|
Assert.Equal(BomRowStatus.NeedsMaterial, row.Status);
|
|
|
|
row.Material = "Steel";
|
|
Assert.Equal(BomRowStatus.NeedsThickness, row.Status);
|
|
|
|
row.Thickness = 0.25;
|
|
Assert.Equal(BomRowStatus.NeedsQuantity, row.Status);
|
|
|
|
Assert.True(row.TrySetQuantity("3"));
|
|
Assert.Equal(BomRowStatus.Ready, row.Status);
|
|
Assert.Equal("Ready", row.StatusText);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("0")]
|
|
[InlineData("-1")]
|
|
[InlineData("2.5")]
|
|
[InlineData("")]
|
|
[InlineData("abc")]
|
|
public void TrySetQuantity_RefusesInvalidTextAndKeepsTheQuantity(string text)
|
|
{
|
|
var row = ReadyRow();
|
|
row.Qty = 4;
|
|
row.QtyAssumed = true;
|
|
var changes = Changes(row);
|
|
|
|
Assert.False(row.TrySetQuantity(text));
|
|
|
|
Assert.Equal(4, row.Qty);
|
|
Assert.True(row.QtyAssumed);
|
|
Assert.Empty(changes);
|
|
}
|
|
|
|
[Fact]
|
|
public void TrySetQuantity_SetsTheQuantityAndReportsTheChange()
|
|
{
|
|
var row = ReadyRow();
|
|
row.QtyAssumed = true;
|
|
var changes = Changes(row);
|
|
|
|
Assert.True(row.TrySetQuantity(" 12 "));
|
|
|
|
Assert.Equal(12, row.Qty);
|
|
Assert.False(row.QtyAssumed);
|
|
Assert.Equal(new[] { "Qty", "Status", "StatusText" }, changes);
|
|
}
|
|
|
|
[Fact]
|
|
public void EditingMaterialOrThickness_ReportsTheValueAndTheStatus()
|
|
{
|
|
var row = ReadyRow();
|
|
var changes = Changes(row);
|
|
|
|
row.Material = "Aluminum";
|
|
row.Thickness = 0.125;
|
|
row.Thickness = 0.125;
|
|
|
|
Assert.Equal(
|
|
new[] { "Material", "Status", "StatusText", "Thickness", "Status", "StatusText" },
|
|
changes
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void Describe_NamesEveryStatus()
|
|
{
|
|
Assert.Equal(
|
|
new[]
|
|
{
|
|
"Ready",
|
|
"Needs material",
|
|
"Needs thickness",
|
|
"Needs quantity",
|
|
"No drawing found",
|
|
"No file name",
|
|
},
|
|
Enum.GetValues<BomRowStatus>().Select(BomPartRow.Describe)
|
|
);
|
|
}
|
|
|
|
private static BomPartRow ReadyRow() =>
|
|
new()
|
|
{
|
|
FileName = "PT01",
|
|
DxfPath = "/d/PT01.dxf",
|
|
Material = "Steel",
|
|
Thickness = 0.25,
|
|
Qty = 1,
|
|
};
|
|
|
|
private static List<string?> Changes(BomPartRow row)
|
|
{
|
|
var names = new List<string?>();
|
|
row.PropertyChanged += (_, e) => names.Add(e.PropertyName);
|
|
return names;
|
|
}
|
|
}
|