This is a common problem that people will run into; not only from a 
"mocking" perspective but more from a unit testing perspective.
There are many who would state that you are performing an integration test 
versus a unit test and other who would tell you to not attempt to test 
"infrastructure concern."

>From a mocking perspective... some classes just simply cannot be mocked or 
(better phrased) don't lend themselves to being mocked.
For File and Directory concerns, I have seen some that will attempt to 
create a wrapper around this functionality to enable (or promote) unit 
testing. Your mileage will vary on this... personally I find it a bad 
practice.

There are alternative options including allowing this concern to be handled 
in an integration test and not a unit test.
The alternatives, however, are based on what it is that you are actually 
hoping to achieve with the unit test. Are you trying to test GetWeekOfYear 
or that the files/directories are handled correctly?



On Monday, August 5, 2013 5:01:00 AM UTC-4, Mitesh Agrawal wrote:
>
> Hi I have following method in my class and I want to write unit test for 
> it using nunit and rhino mocks. My method moves all the folders from source 
> path to destination path, I am new to NUnit and Rhinomocks and I dont know 
> how to mock System.IO.Directory or System.IO.DirectoryInfo objects. I have 
> tried everything on google.
>
>         public void MoveDirectories() 
>         {
>             var dirList = (from f in new 
> DirectoryInfo(sourceDir).EnumerateDirectories("*")
>                            select f).ToList();
>
>             destinationDir = destinationDir + "//" + newDir;
>
>             foreach (var d in dirList)
>             {
>                 if (GetWeekOfYear(d.CreationTime) == weekNo)
>                 {
>                     if (!Directory.Exists(destinationDir))
>                     {
>                         Directory.CreateDirectory(destinationDir);
>                     }
>
>                     if (!Directory.Exists(destinationDir + "//" + d.Name))
>                     {
>                         Console.WriteLine("Move Folder  " + d.FullName + " 
> TO " + destinationDir + "//" + d.Name);
>                         Directory.Move(d.FullName, destinationDir + "//" + 
> d.Name);
>                     }
>                 }
>             }
>         }
>
> Here method GetWeekOfYear returns the Week number for a current date or 
> date supplied.
> If any one can help me to achieve this. 
>
> Thanks in advance,
> Mitz.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to