Testing and stabilizing
Before starting refactoring, it is essential to have established end-to-end (E2E) tests to ensure the stability of the code base and to prevent introducing regressions or bugs.
In Chapter 5, within the Understanding tests and role in refactoring section, you can find a detailed explanation of the E2E tests. The purpose of these tests is to verify that when you invoke an endpoint, the response matches your expectations. As outlined in Chapter 5, these tests play a crucial role in ensuring that refactoring does not introduce unintended side effects. You can see an example of this approach here:
[Fact]
public async Task Can_Create_SalesOrder()
{
DateTime now = DateTime.UtcNow;
SalesOrderJson body = new(Guid.NewGuid().ToString(),
$"{now.Year:0000}{now.Month:00}{now.Day:00}-{now.Hour:00}{now.Minute:00}",
Guid.NewGuid(), "Customer",
now, new List<SalesOrderRowJson>
{
new()
...