我需要一些想法来对这个任务方法进行单元测试
这是有问题的方法:
public void StartBatchProcessing(IFileBatch fileBatch)
{
var dataWarehouseFactsMerger = m_dataWarehouseFactsMergerFactory.Create(fileBatch);
dataWarehouseFactsMerger.Merge();
if(!m_isTaskStarted)
{
m_isTaskStarted = true;
m_lastQueuedBatchProcessingTask = new TaskFactory().StartNew(() => ProcessBatch(dataWarehouseFactsMerger));
}
else
{
m_lastQueuedBatchProcessingTask = m_lastQueuedBatchProcessingTask.ContinueWith(previous => ProcessBatch(dataWarehouseFactsMerger));
}
}
正如您所看到的,我正在使用 TPL 将任务一个接一个地排队,并且我想测试任务是否会在前一个任务完成后立即按照它们到达的顺序执行。
ProcessBatch 方法受到保护,因此我认为它可以在派生类中被覆盖,并用于设置某些标志或某些内容并断言。
所有想法都受到欢迎和赞赏。
This is the method in question:
public void StartBatchProcessing(IFileBatch fileBatch)
{
var dataWarehouseFactsMerger = m_dataWarehouseFactsMergerFactory.Create(fileBatch);
dataWarehouseFactsMerger.Merge();
if(!m_isTaskStarted)
{
m_isTaskStarted = true;
m_lastQueuedBatchProcessingTask = new TaskFactory().StartNew(() => ProcessBatch(dataWarehouseFactsMerger));
}
else
{
m_lastQueuedBatchProcessingTask = m_lastQueuedBatchProcessingTask.ContinueWith(previous => ProcessBatch(dataWarehouseFactsMerger));
}
}
As you can see I'm using TPL to queue tasks one after the other and I would like to test that the tasks will execute in the order they arrive as soon as the previous one finishes.
The ProcessBatch method is protected so I think it could be overwritten in a derived class and be used to set some flag or something and assert that.
All ideas are welcome and appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个
DataWarehouseFactsMergerFactory
的实现,它创建能够记录输入的fileBatch
以及每个任务的开始时间的DataWarehouseFactsMerger
的实现,但对于其余的,实际上什么也不做。You could create an implementation of
DataWarehouseFactsMergerFactory
that creates implementations ofDataWarehouseFactsMerger
that are capable of logging whichfileBatch
was entered and the start time of each task, but for the rest don't really do anything.