Hi there.
I have the following routine, which iterates through all the files in a directory. The class that the routine is a part of uses a BackhroundWorker object (m_fileReaderWorker) which is instanciated during the class creation process.
I would like to test just this routine, without creating a new class:
Private Sub WorkWithFilesInDir(ByVal aDir As DirectoryInfo)
For Each aFile As FileInfo In aDir.GetFiles()
If Not m_fileReaderWorker.CancellationPending Then
... do stuff
Else
Exit For
End If
Next
End Sub
Here is my unit test code:
Public Sub WorkWithDirectoryTest()
Dim target As WebsiteConverter_Accessor = New WebsiteConverter_Accessor
Dim aDir As New DirectoryInfo("D:site")
target.WorkWithDirectory(aDir)
End Sub
The unit test runs perfectly fine until it hits the line:
If Not m_fileReaderWorker.CancellationPending Then
since m_fileReaderWorker is Nothing. How can I mock this out, so that when I run the unit test, I can force CancellationPending to return False all the time?
Cheers.
Jas.