Tôi đã tạo mẫu kiểu người xây dựng thông thạo để giúp tải dữ liệu về các thử nghiệm của mình. Thứ tự của một số phương pháp là quan trọng và đã tự hỏi những gì các phương pháp ưa thích để quản lý trình tự chính xác là.Cách ưa thích để quản lý đơn đặt hàng trong mẫu trình xây dựng là gì?
Tôi có sau đây vào lúc này:
using NUnit.Framework;
[TestFixture]
public class DataBuilderTests
{
[Test]
public void Can_NAME()
{
new DataLoader()
.Start() // must be called first
.Setup() // then called next
.LoadEmployees() // optional order not NB
.LoadProducts() // optional order not NB
.StartCleanup() // begin cleanup
.CleanupEmployees() // optional order not NB
.CleanupProducts() // optional order not NB
.End();
}
}
public class DataLoader
{
public DataBuilderSetup Start()
{
return new DataBuilderSetup(this);
}
}
public class DataBuilderSetup
{
private readonly DataLoader _dataLoader;
public DataBuilderSetup(DataLoader dataLoader)
{
_dataLoader = dataLoader;
}
public DataBuilderOptions Setup()
{
// do setup
return new DataBuilderOptions(_dataLoader);
}
}
public class DataBuilderOptions
{
private readonly DataLoader _dataLoader;
public DataBuilderOptions(DataLoader dataLoader)
{
_dataLoader = dataLoader;
}
public DataBuilderOptions LoadEmployees()
{
// load
return this;
}
public DataBuilderOptions LoadProducts()
{
// load
return this;
}
public DataBuilderCleanupOptions StartCleanup()
{
return new DataBuilderCleanupOptions(_dataLoader);
}
}
public class DataBuilderCleanupOptions
{
private readonly DataLoader _dataLoader;
public DataBuilderCleanupOptions(DataLoader dataLoader)
{
_dataLoader = dataLoader;
}
public DataBuilderCleanupOptions CleanupEmployees()
{
// cleanup
return this;
}
public DataBuilderCleanupOptions CleanupProducts()
{
// cleanup
return this;
}
public DataLoader End()
{
return _dataLoader;
}
}
Có vấn đề gì với giải pháp hiện tại của bạn? –
Không có gì, chỉ là một cái gì đó tôi đã đưa ra sáng nay và đã tò mò như thế nào những người khác xử lý các kịch bản – Chev
Có 'CleanupEmployees' phải được gọi là nếu' LoadEmployees' được gọi là? –