Stub() method broken in v3.6? (GenerateStub() still works)

13 views
Skip to first unread message

kbaltrinic

unread,
Nov 4, 2009, 12:53:19 PM11/4/09
to Rhino.Mocks, ken.ba...@inforeliance.com
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

Tim Barcz

unread,
Nov 4, 2009, 1:20:32 PM11/4/09
to rhino...@googlegroups.com
You're mixing record/replay (new MockRepository()) and AAA modes.
--
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

ap

unread,
Nov 26, 2009, 5:57:36 AM11/26/09
to Rhino.Mocks
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!
}

Reply all
Reply to author
Forward
0 new messages