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:
@@ -1,4 +1,6 @@
|
||||
using After;
|
||||
using static BeforeAfter.Tests.TestData.ClientBuilder;
|
||||
using static BeforeAfter.Tests.TestData.OrderBuilder;
|
||||
|
||||
namespace BeforeAfter.Tests;
|
||||
|
||||
@@ -15,9 +17,8 @@ public class AfterPersistenceTests
|
||||
public void Save_maps_domain_state_into_data_records()
|
||||
{
|
||||
var db = new DbContext();
|
||||
var client = new Client { Name = "Acme" };
|
||||
var order = new Order { Description = "one", TotalInCents = 15000 };
|
||||
client.Orders.Add(order);
|
||||
var order = ValidOrder().WithDescription("one").WithTotal(150_00).Build();
|
||||
var client = ValidClient().WithName("Acme").WithOrder(order).Build();
|
||||
|
||||
db.Save(client);
|
||||
db.Save(order);
|
||||
@@ -29,7 +30,7 @@ public class AfterPersistenceTests
|
||||
var orderRow = Assert.Single(db.Orders);
|
||||
Assert.Equal(order.Id, orderRow.Id);
|
||||
Assert.Equal("one", orderRow.Description);
|
||||
Assert.Equal(15000, orderRow.TotalInCents);
|
||||
Assert.Equal(150_00, orderRow.TotalInCents);
|
||||
Assert.Equal(client.Id, orderRow.ClientId); // the graph is flattened to a key
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ public class AfterPersistenceTests
|
||||
public void An_order_without_client_stores_an_empty_client_id()
|
||||
{
|
||||
var db = new DbContext();
|
||||
var order = new Order { Description = "orphan" };
|
||||
var order = ValidOrder().WithDescription("orphan").Build();
|
||||
|
||||
db.Save(order);
|
||||
|
||||
@@ -48,14 +49,13 @@ public class AfterPersistenceTests
|
||||
public void Saving_again_refreshes_the_row_instead_of_duplicating_it()
|
||||
{
|
||||
var db = new DbContext();
|
||||
var client = new Client { Name = "Acme" };
|
||||
var order = new Order { Description = "one" };
|
||||
client.Orders.Add(order);
|
||||
var order = ValidOrder().WithDescription("one").WithTotal(150_00).Build();
|
||||
var client = ValidClient().WithName("Acme").WithOrder(order).Build();
|
||||
db.Save(client);
|
||||
db.Save(order);
|
||||
|
||||
order.Description = "one (edited)";
|
||||
order.TotalInCents = 9900;
|
||||
order.TotalInCents = 99_00;
|
||||
client.Name = "Acme GmbH";
|
||||
db.Save(order);
|
||||
db.Save(client);
|
||||
@@ -64,7 +64,7 @@ public class AfterPersistenceTests
|
||||
var orderRow = Assert.Single(db.Orders);
|
||||
Assert.Equal(order.Id, orderRow.Id);
|
||||
Assert.Equal("one (edited)", orderRow.Description);
|
||||
Assert.Equal(9900, orderRow.TotalInCents);
|
||||
Assert.Equal(99_00, orderRow.TotalInCents);
|
||||
Assert.Equal(client.Id, orderRow.ClientId);
|
||||
|
||||
var clientRow = Assert.Single(db.Clients);
|
||||
@@ -75,9 +75,8 @@ public class AfterPersistenceTests
|
||||
public void Rows_are_reachable_through_Set_and_Find()
|
||||
{
|
||||
var db = new DbContext();
|
||||
var client = new Client { Name = "Acme" };
|
||||
var order = new Order { Description = "one" };
|
||||
client.Orders.Add(order);
|
||||
var order = ValidOrder().WithDescription("one").WithTotal(150_00).Build();
|
||||
var client = ValidClient().WithName("Acme").WithOrder(order).Build();
|
||||
db.Save(client);
|
||||
db.Save(order);
|
||||
|
||||
@@ -98,9 +97,8 @@ public class AfterPersistenceTests
|
||||
public void Loading_an_order_restores_its_state_and_its_client()
|
||||
{
|
||||
var db = new DbContext();
|
||||
var client = new Client { Name = "Acme" };
|
||||
var order = new Order { Description = "one", TotalInCents = 150_00 };
|
||||
client.Orders.Add(order);
|
||||
var order = ValidOrder().WithDescription("one").WithTotal(150_00).Build();
|
||||
var client = ValidClient().WithName("Acme").WithOrder(order).Build();
|
||||
db.Save(client);
|
||||
db.Save(order);
|
||||
|
||||
@@ -122,12 +120,12 @@ public class AfterPersistenceTests
|
||||
public void Loading_a_client_restores_it_with_all_of_its_orders()
|
||||
{
|
||||
var db = new DbContext();
|
||||
var client = new Client { Name = "Acme" };
|
||||
client.Orders.Add(new Order { Description = "one", TotalInCents = 150_00 });
|
||||
client.Orders.Add(new Order { Description = "two", TotalInCents = 250_00 });
|
||||
var first = ValidOrder().WithDescription("one").WithTotal(150_00).Build();
|
||||
var second = ValidOrder().WithDescription("two").WithTotal(250_00).Build();
|
||||
var client = ValidClient().WithName("Acme").WithOrder(first).WithOrder(second).Build();
|
||||
db.Save(client);
|
||||
db.Save(client.Orders[0]);
|
||||
db.Save(client.Orders[1]);
|
||||
db.Save(first);
|
||||
db.Save(second);
|
||||
|
||||
var loaded = db.LoadClient(client.Id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user