I would have to say, mocking would be the best approach here.
Abstract away from Directory (IFileManager).
I find that IFileManager.WriteStream(Stream s, string Path) to be a
nice method for dealing with this kind of stuff and then that hides
the internal byte writer while loop and makes it easy to mock.
But then it depends if your doing integration / unit testing :).
Ben
On 08/10/2007, hmobius <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> How would you go about unit testing a simple FTP library with commands
> in it such as Upload, Download, RenameRemoteFile etc? I can't think of
> a good way to set up a test class that doesn't rely on my already
> having set up a FTP account in the right place. Is mocking the way to
> go?
>
> At the moment, I'm running on this code, but the TearDown routines are
> failing because the local file I've created is "being used by another
> process" when they are called. I'm guessing that the issue is I'm
> trying to delete a file before the setup routine has released it, but
> any thoughts you might have would be appreciated.
>
> Dan
>
> -- Error
>
> TestCase 'FtpConnectionTests.Setup.Test.TearDown'
> failed: The process cannot access the file 'D:\CodeSVN\dotCoop2.0\Code
> \Common\UnitTests\bin\Debug\ftptests\localftptest.txt' because it is
> being used by another process.
> System.IO.IOException
> Message: The process cannot access the file 'D:\CodeSVN
> \dotCoop2.0\Code\Common\UnitTests\bin\Debug\ftptests\localftptest.txt'
> because it is being used by another process.
> Source: mscorlib
> StackTrace:
> at System.IO.__Error.WinIOError(Int32 errorCode, String
> maybeFullPath)
> at System.IO.File.Delete(String path)
> D:\CodeSVN\dotCoop2.0\Code\Common\UnitTests
> \FtpConnectionTests.cs(55,0): at
> Mcd.Common.FtpConnectionTests.TearDown()
>
> -- Code
>
> [TestFixtureSetUp]
> public void FixtureSetup()
> {
> //Create directory for local files
> Directory.CreateDirectory(LocalDirectory);
> }
>
> [SetUp]
> public void Setup()
> {
> //Create file for uploading
> File.Create(Path.Combine(LocalDirectory, LocalFileName));
> FileAssert.Exists(Path.Combine(LocalDirectory,
> LocalFileName));
> }
>
> [Test]
> public void Test()
> {
> Console.WriteLine("Into the test");
> }
>
> [TearDown]
> public void TearDown()
> {
> //Delete file
> File.Delete(Path.Combine(LocalDirectory, LocalFileName));
> FileAssert.NotExists(Path.Combine(LocalDirectory,
> LocalFileName));
> }
>
> [TestFixtureTearDown]
> public void FixtureTearDown()
> {
> //Delete directory for local files and any files left in it.
> Directory.Delete(LocalDirectory, true);
> }
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---