This is my solution's structure:
Storage.csproj
> FileDownloader.cs
> GitHubProvider.cs (implements IStorageProvider)
> IStorageProvider.cs
Storage.Test.csproj
> FileDownloaderFixture.cs
The idea is that I can use the class FileDownloader
, inject it with a IStorageProvider
, call myFileDownloader.Download(url)
, and it will download the file to the filesystem.
Now, the question is: how do I unit test this? I wrote the following test:
[TestClass]
public class FileDownloaderFixture
{
[TestMethod]
public void TestDownload()
{
//Arrange
var storageProviderMock = new Mock<IStorageProvider>(MockBehavior.Strict);
storageProviderMock.Setup(s => s.Download("http://host.com/file.txt")).Returns(Status.Success);
var myFileDownloader = new FileDownloader(storageProviderMock.Object);
//Act
myFileDownloader.DownloadFile("http://host.com/file.txt");
//Assert
storageProviderMock.Verify(s => s.Download("http://host.com/file.txt"));
}
}
It looks nice and clean, but... it's useless. It doesn't prove the fact that the code in GitHubProvider.Download(url)
works. I don't even use methods from GitHubProvider
. So what's the point?
The only other idea I have is to set up a test GitHub account & repository, and work with that. But this solution won't work very well if, for instance, I had to pay for each access to the repository. What then?