jeudi 2 juin 2016

How to use TDD when your method is designed to perform many tasks

I'm still trying to follow the path to TDD.

Let's say I have a SunSystemBroker triggered when a file is uploaded to a Shared Folder. This broker is designed to open this file, extract records from it, try to find associated payments in another systems and finally to call a workflow!

If I want to follow TDD to develop the IBroker.Process() method how shall i do?

Note: Broker are independent assemblies inheriting from IBroker and loaded by a console app (like plugins).

This console is in charge of triggering each broker!

public interface IFileTriggeredBroker : IBroker
{
    FileSystemTrigger Trigger { get; }
    void Process(string file);
}

public class SunSystemPaymentBroker : IFileTriggeredBroker
{
    private readonly IDbDatasourceFactory _hrdbFactory;
    private readonly IExcelDatasourceFactory _xlFactory;
    private readonly IK2DatasourceFactory _k2Factory;
    private ILog _log;

    public void Process(string file)
    {
        (...)
        // _xlFactory.Create(file) > Extract
        // _hrdbFactory.Create() > Find
        // Compare Records
        // _k2Factory.Create > Start
    }
}

Each method are tested individually.

Thank you Seb

Aucun commentaire:

Enregistrer un commentaire