You can get the behavior you're looking for by using the Record/Replay model
and using "CreateMock()" which will create a strict mock as Alex has pointed
out.  I tend to agree with Alex's proposal to use AssertWasNotCalled,
because I favor the AAA syntax.  However you should know that what you want
is available using Record/Replay.

Note however that this may be an "overspecification" which is one of the
reasons I don't particularly care for strict mocks and should be used with
caution.  I don't want to speak for Oren but I believe that is why the
default is now a dynamic mock....too many people fell into the over
specification trap and paid dearly for it later with failing tests.

Tim

On Tue, Jun 23, 2009 at 11:49 AM, Alex McMahon <[email protected]> wrote:

>
> GenerateMock will return a dynamicMock, i.e. It will allow unspecified
> calls to be made on it. So the behaviour you're seeing is correct
>
> If you wanted the test to fail you could either explicitly create a
> strict mock or use mockConsole.AssertWasNotCalled(x=>x.Print("b"));
>
> 2009/6/23 Kedar <[email protected]>:
> >
> >    public interface IConsole  {
> >        void Print(string s);
> >    }
> >
> >    [TestFixture]
> >    public class SomeTestFixture
> >    {
> >        public void MethodToTest(IConsole console)
> >        {
> >            console.Print("a");
> >            console.Print("b");
> >        }
> >
> >        [Test]
> >        public void Test()
> >        {
> >            var mockConsole = MockRepository.GenerateMock<IConsole>();
> >            mockConsole.Expect(x => x.Print("a"));
> >            MethodToTest(mockConsole);
> >            mockConsole.VerifyAllExpectations();
> >        }
> >    }
> >
> > In this example, the only expectation I have is to call Print with
> > argument "a". But the code under test calls it with "a" and then with
> > "b". I thought that the VerifyAllExpectations assertion would fail.
> > But it does not. Is this a problem or am I doing something wrong ?
> >
> > >
> >
>
> >
>


-- 
Tim Barcz
ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to