I'd agree wholeheartedly.  Introducing your own abstraction is (often) the
more time-consuming choice, but its also the only of the several choices
that will contribute positively to the increased flexibility and decreased
coupling/rigidity of your codebase.

Steve Bohlen
sboh...@gmail.com
http://blog.unhandled-exceptions.com
http://twitter.com/sbohlen


On Mon, Aug 5, 2013 at 9:32 AM, Reginald Blue <reginald.b...@gmail.com>wrote:

> Just wanted to add (I agree with everything that Stephen said) that from
> the perspective of IoC/Dependency injection, creating your own wrapper is
> the way to go.  It allows you to perform overrides on behavior (e.g.
> logging, auditing, unified exception handling, whatever), plus it enables
> Mocking the code for unit testing.  If you needed to, for some strange
> reason, use a new file system implementation (maybe you wanted to port your
> code to a netduino or something), then it allows for that possibility as
> well.
>
> So, if it were me, that's the path I would take.
>
>
>
> On Mon, Aug 5, 2013 at 7:58 AM, Stephen Bohlen <sboh...@gmail.com> wrote:
>
>>
>> Those types aren't possible to mock using RhinoMocks. RhinoMocks
>> functions by creating its own impl of interfaces at runtime. If you've
>> not got an interface for your mocked type, RhinoMocks can still mock
>> your concrete type, but it must do so by deriving from it and
>> overriding its method implementations.
>>
>> Given this technique, RhinoMocks (and all the other non-commercial
>> mocking tools in the .net space) can't mock any concrete type with a
>> design that prevents this derive-and-override approach. Static types,
>> sealed types, and non-virtual methods are all class design choices that
>> effectively prevent RhinoMocks from mocking a type.
>>
>> Unfortunately, the types you're attempting to mock here have most of
>> those poor design characteristics (as do a large percentage of the .net
>> base class libraries).
>>
>> You have several choices to resolve this problem, which you choose
>> depends on your needs and your financial resources:
>>
>> 1) design your own abstractions (usually interfaces that can easily be
>> mocked) around file/directory IO and mock them instead (e.g,
>> IFileSystemManipulator)
>>
>> 2) purchase a commercial mocking tool that uses other techniques to
>> circumvent the constraints that RhinoMocks has re: statics, sealed,
>> non-virtual, etc.
>>
>> 3) use the Microsoft Fakes framework available with VS2012 Premium or
>> Ultimate (if you have it). This provides compile -time vs run-time
>> creation of 'mocks' where what it calls 'stubs' are more akin to
>> the 'mocks' in RhinoMocks but what it calls 'shims' may be used to
>> substitute for static, sealed, non-virtual, etc. types that cannot be
>> handled by RhinoMocks.
>>
>> Hope this helps!
>>
>> -Steve B. From: Mitesh Agrawal
>> Sent: =E2=80=8E8/=E2=80=8E5/=E2=80=8E2013 6:06 AM
>> To: rhinomocks@googlegroups.com
>> Subject: [RhinoMocks] Mocking System.IO.Directory operations in Nunit
>> using Rhino mocks
>> Hi I have following method in my class and I want to write unit test for
>> it=
>> =20
>> using nunit and rhino mocks. My method moves all the folders from
>> source=20
>> path to destination path, I am new to NUnit and Rhinomocks and I dont
>> know=
>> =20
>> how to mock System.IO.Directory or System.IO.DirectoryInfo objects. I
>> have=
>> =20
>> tried everything on google.
>>
>>         public void MoveDirectories()=20
>>         {
>>             var dirList =3D (from f in new=20
>> DirectoryInfo(sourceDir).EnumerateDirectories("*")
>>                            select f).ToList();
>>
>>             destinationDir =3D destinationDir + "//" + newDir;
>>
>>             foreach (var d in dirList)
>>             {
>>                 if (GetWeekOfYear(d.CreationTime) =3D=3D weekNo)
>>                 {
>>                     if (!Directory.Exists(destinationDir))
>>                     {
>>                         Directory.CreateDirectory(destinationDir);
>>                     }
>>
>>                     if (!Directory.Exists(destinationDir + "//" + d.Name))
>>                     {
>>                         Console.WriteLine("Move Folder  " + d.FullName +
>> "=
>> =20
>> TO " + destinationDir + "//" + d.Name);
>>                         Directory.Move(d.FullName, destinationDir + "//"
>> +=
>> =20
>> d.Name);
>>                     }
>>                 }
>>             }
>>         }
>>
>> Here method GetWeekOfYear returns the Week number for a current date or=20
>> date supplied.
>> If any one can help me to achieve this.=20
>>
>> 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 rhinomocks+unsubscr...@googlegroups.com.
>
> To post to this group, send email to rhinomocks@googlegroups.com.
> Visit this group at http://groups.google.com/group/rhinomocks.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 rhinomocks+unsubscr...@googlegroups.com.
To post to this group, send email to rhinomocks@googlegroups.com.
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