I wouldn't mock NH. it's more trouble than it's worth. use a sqlite
memory database and the real NH objects. remember, you should be
testing that your code works, not that NH and RC works. that's already
proven.


On Oct 19, 6:13 pm, "Stephen Bohlen" <[email protected]> wrote:
> Not at a PC so cannot say for certain but wouldn't you just set an 
> expectation on theStubUnitOfWork such that the call to BeginTransaction() 
> returns the mocked RhinoTransaction instance--?
>
> That said, this feels like an over-specification anti-pattern to me -- this 
> test feels like its operating at a much lower level than I would bother 
> testing in most cases.  What exactly is the (eventual) pass/fail you would be 
> intending to assert against --?
>
> My initial impression of this is that its dangerously close to being just a 
> cross between a test that RhinoCommons functions as expected and a test that 
> try-catch isn't broken :)
>
> That said, I'm sitting in a conference session right now and so haven't taken 
> a (very) close look at the code.
>
> Hope this helps,
>
> -Steve B.
>
> -----Original Message-----
> From: Beto <[email protected]>
> Sender: [email protected]
> Date: Tue, 19 Oct 2010 15:00:36
> To: Rhino Tools Dev<[email protected]>
> Reply-To: [email protected]
> Subject: [rhino-tools-dev] How do I mock 
> UnitOfWork.Current.BeginTransaction() ?
>
> Hi Everyone,
> Not sure if it belongs here or on the Rhino.Mocks group.  I’m using
> rhino.commons and would like to test the following piece of
> code below but I’m having trouble Mokin
> UnitOfWork.Current.BeginTransaction().  I was able to mock the unit of
> work doing the following:
> var theStubUnitOfWork = MockRepository.GenerateMock<IUnitOfWork>();
>            UnitOfWork.RegisterGlobalUnitOfWork(theStubUnitOfWork);
>
> But I want to be able to do something similar with RhinoTransaction, I
> have tried this: var tx =
> MockRepository.GenerateMock<RhinoTransaction>();
>
> But how do I register it as a global.  Any help would be appreciated
> and thanks in advanced.
> if (isAllowedToRemove && hasAccessOnOrg)
>            {
>                RhinoTransaction tx =
> UnitOfWork.Current.BeginTransaction();
>                try
>                {
>                    //do stuff
>                    tx.Commit();
>                }
>                catch
>                {
>                    tx.Rollback();
>                }
>                finally
>                {
>                    tx.Dispose();
>                }
>            }
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Rhino Tools Dev" 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 
> athttp://groups.google.com/group/rhino-tools-dev?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" 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/rhino-tools-dev?hl=en.

Reply via email to