lundi 28 septembre 2015

How do I refactor this code for unit testing? [on hold]

I am having a hard time understanding the below question, what does he want ?


Rewrite the code below so methods in the Account Class can be unit tested. Then write a unit test for the GetActiveGoldAccountIds() method of the Account Class that does not actually cause db code to execute.

public class Account    
{    
    public Account() 
    {
    }

    public list<string> GetActiveGoldAccountIds()
    {
        AccountData accountData = new AccountData();
        list<string> filteredAccountList = new filteredList();
        list<string> accountList = accountData.GetGoldAccountIDs();
        foreach (string accountId in accountList)
        {
            if (accountData.isActive(accountId))
            {
                filteredAccountList.Add(accountId);
            }
        }
        return filteredAccountList;
    }
}

public class AccountData
{
    public AccountData() {}

    public list<string> GetGoldAccountIds()
    {
        return db.GetStuff1().ToList();
    }

    public bool IsActive(string accountId)
    {
         return db.GetStuff2();
    }
}

public class UnitTests
{
    void unitTest()
    {

    }
}

Aucun commentaire:

Enregistrer un commentaire