I am trying to write some unit tests. The application has a number of external API calls that I would like to mock using NSubstitute. The issue is these calls use service objects that need to be instantiated in the function and can't be passed in the constructor after substitution.
For example, in the code below I am adding an account to Quickbooks:
public async Task AddQuickbooksAsync(int accountId)
{
var qbChannel = await GetQuickbooksChannel();
var account = await GetAsync(accountId);
var quickbooksBO = new QuickbooksBO(qbChannel);
quickbooksBO.AddAccount(account);
quickbooksBO.UpdateRefreshedTokens(qbChannel);
await context.SaveChangesAsync();
}
I want to mock the following function call using NSubstitute, but couldn't figure out how:
var quickbooksBO = new QuickbooksBO(qbChannel);
quickbooksBO.AddAccount(account);
How can I do this?