TestDataBuilders: ValidOrder()/ValidClient() with explicit Build(); After tests migrated

Domain objects in After-side tests are constructed only through the
builders, so the upcoming OrderLines evolution changes builder internals
instead of every test. Before keeps object initializers (legacy world).

yak: testdatabuilders-validordervalidclient-after-test-migration-91vl
This commit is contained in:
2026-09-16 22:32:13 +01:00
parent 53586d33a4
commit 08b52806de
6 changed files with 158 additions and 65 deletions
+11 -6
View File
@@ -22,6 +22,11 @@ explicit — and that is where this exercise lives.
percentage *actually applied* (0 when the total does not strictly exceed the
barrier), and the discounted total. Rounding is half-up, in integer math.
- Unit tests for all of the above already pass.
- `ValidOrder()` / `ValidClient()` test data builders in the test project
(`tests/BeforeAfter.Tests/TestData/`) — construct domain objects in tests
through them, so tests survive domain evolution. Import their static
factories with `using static BeforeAfter.Tests.TestData.OrderBuilder;`
(and `...ClientBuilder;`).
## The challenge
@@ -61,6 +66,8 @@ instead of assuming there is only one order around.
```csharp
using After;
using static BeforeAfter.Tests.TestData.ClientBuilder;
using static BeforeAfter.Tests.TestData.OrderBuilder;
namespace BeforeAfter.Tests;
@@ -74,9 +81,8 @@ public class DiscountedOrderMappingTests
public void A_discounted_order_can_be_correlated_onto_its_order()
{
var db = new DbContext();
var client = new Client { Name = "Acme" };
var order = new Order { Description = "big order", TotalInCents = 150_00 };
client.Orders.Add(order);
var order = ValidOrder().WithDescription("big order").WithTotal(150_00).Build();
var client = ValidClient().WithName("Acme").WithOrder(order).Build();
db.Save(client);
db.Save(order);
@@ -98,9 +104,8 @@ public class DiscountedOrderMappingTests
public void Saving_a_discounted_order_keeps_the_stored_total_untouched()
{
var db = new DbContext();
var client = new Client { Name = "Acme" };
var order = new Order { Description = "big order", TotalInCents = 150_00 };
client.Orders.Add(order);
var order = ValidOrder().WithDescription("big order").WithTotal(150_00).Build();
var client = ValidClient().WithName("Acme").WithOrder(order).Build();
db.Save(client);
db.Save(order);