You just need to call repositoryIntance.ReplayAll(); before calling
tested method.

        [Test]
        public void this_test_fails()
        {
            var repositoryIntance = new MockRepository();

            var test= repositoryIntance.Stub<ITest>();
            test.Stub(t => t.GetInt()).Return(1);

            //move to act mode
            repositoryIntance.ReplayAll();

            var id = test.GetInt();
            Assert.That(id, Is.EqualTo(1));  //Fails id is 0!
        }

On 4 Lis, 18:53, kbaltrinic <[email protected]> wrote:
> I just started to use the new AAA approach with a new project that I
> am on and spent some time distilling down why my first AAA unit tests
> was failing.  It appears that something is wrong with the Stub()
> method when used on a instance of MockRepository (as opposed to the
> static MockRepository.GenerateStub()).  Is this just me or can others
> reproduce the following results (Rhino 3.6 and NUnit 2.5.2)
>
>         public interface ITest { int GetInt(); }
>
>         [Test]
>         public void this_test_fails()
>         {
>             var repositoryIntance = new MockRepository();
>
>             var test= repositoryIntance.Stub<ITest>();
>             test.Stub(t => t.GetInt()).Return(1);
>
>             var id = test.GetInt();
>             Assert.That(id, Is.EqualTo(1));  //Fails id is 0!
>         }
>
>         [Test]
>         public void this_test_passes()
>         {
>             var test= MockRepository.GenerateStub<ITest>();
>             test.Stub(s => s.GetInt()).Return(1);
>
>             var id = test.GetInt();
>             Assert.That(id, Is.EqualTo(1));
>         }
>
> --Ken

--

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