using After;
namespace BeforeAfter.Tests.TestData;
///
/// Test data builder for an (TestDataBuilder pattern).
/// starts from a fresh order —
/// id, empty description, zero total, exactly what
/// new Order() gives — and every With... returns the builder for
/// chaining; hands back the order.
///
/// This class is the only place tests touch an order's *construction*: when
/// the domain evolves (e.g. OrderLines making the total computed), only these
/// internals change and the tests keep reading the same.
///
public sealed class OrderBuilder
{
private readonly Order _order = new();
private int? _totalInCents;
/// A valid, fresh order — the neutral starting point for tests.
public static OrderBuilder ValidOrder() => new();
public OrderBuilder WithId(Guid id)
{
_order.Id = id;
return this;
}
public OrderBuilder WithDescription(string description)
{
_order.Description = description;
return this;
}
///
/// Sets the total in cents (150_00 = €150.00). Since OrderLines
/// arrived, the total is computed — the requested total is realised in
/// as a single line carrying the order's description,
/// so WithDescription/WithTotal work in any order. This API
/// stayed identical across that domain evolution; only these internals
/// changed.
///
public OrderBuilder WithTotal(int totalInCents)
{
_totalInCents = totalInCents;
return this;
}
public Order Build()
{
if (_totalInCents is int total)
_order.Lines.Add(new OrderLine(_order.Description, total));
return _order;
}
}