Correct Mark, I should have used a Stub call instead of the Expect
call.
On Jul 8, 7:20 pm, Mark <[email protected]> wrote:
> I think
>
> // Arrange
> ...
> session.Stub(x => x.BeginTransaction()).Return(tx);
>
> Would do the same thing - does that help clarify the usage? Stub so you set
> up the return value (in Arrange) and AssertWasCalled to verify the test...
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On
>
> Behalf Of Berryl Hesh
> Sent: Thursday, 9 July 2009 12:00 p.m.
> To: Rhino.Mocks
> Subject: [RhinoMocks] Re: can I do this AAA style?
>
> Hi Adam:
>
> Basically, kind of. Its really the conditions that cause _hasSession
> to be true or false that I'm testing, with the call to
> session.BeginTransaction() being all I need to verify. So I have
> transaction as a stub and session as a mock.
>
> Maybe I'm not totally understanding this the way Expect should be used
> with a mock. I'm thinking that if the session is the mocked object,
> then
>
> session.Expect(x => x.BeginTransaction()) // .Return(tx);
>
> creates an expectation of a call to be verified (ie, later, as in
> session.VerifyAllExpectations), just as AssertWasCalled
> (x=>x.BeginTransaction) does in one line. I'm further thinking that
> the .Return(tx) is a convenience to return the stubbed value, and if
> that works on Expect, why shouldn't it work as a method option also.
>
> Does that make sense?
>
> Thx,
> Berryl
>
> > public void TestNoExistingSessionBeginsNewTransaction()
> > {
> > // Arrange
> > var session = MockRepository.GenerateMock<ISession>();
> > var tx = MockRepository.GenerateMock<ITransaction>();
> > var sut = new Sut(session);
> > sut.HasExistingSession = false;
> > session.Expect(x => x.BeginTransaction()).Return(tx);
>
> > // Act
> > sut.TransactionSave("foo");
>
> > // Assert
> > session.AssertWasCalled(x => x.Save("foo");
> > session.AssertWasCalled(x => x.BeginTransaction());
> > tx.AssertWasCalled(x => x.Commit());
>
> > }- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" 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/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---