Stubbing property getter prior to method on the same object

12 views
Skip to first unread message

Sean

unread,
Feb 3, 2009, 1:07:50 PM2/3/09
to Rhino.Mocks, dmorg...@cortex.net, sfel...@cortex.net
Hi,
We run into an issue with the following code. If Line A and B are
switched, it works as expected, and the stubbed property is returning
the value it was given. If the original code is left (first Line A,
then Line B), the stubbed property is returning the default value and
not what was given to it during context establishment. Is this a bug
or something we are missing?
Thank you

Sean

-------------------------Code-------------------------

namespace QTUS.Server.Task
{
[Concern(typeof (GetVersionsTask))]
public abstract class GetVersionsTask_Specs :
ContextSpecification<IGetVersionsTask>
{
protected override void establish_context()
{
system_under_test = create_system_under_test();
}

protected override IGetVersionsTask create_system_under_test()
{
return new GetVersionsTask();
}
}

public class When_GetVersionsTask_is_asked_to_GetOutputXML :
GetVersionsTask_Specs
{
private QuikTikitUser quikTikitUser;
private Application application;
private const bool isActive = true;
private readonly ReadOnlyCollection<string>
userErrorCollection = new ReadOnlyCollection<string>(new List<string>
{"user error"});
private readonly ReadOnlyCollection<string> appErrorCollection
= new ReadOnlyCollection<string>(new List<string>{"app error"});
private string result;
private const string dataVersion = "1";
private const string appVersion = "1.1.1.1";

protected override void establish_context()
{
quikTikitUser = dependency<QuikTikitUser>();
application = dependency<Application>();

quikTikitUser.setup_result(x => x.GetErrors()).Return
(userErrorCollection);
quikTikitUser.IsActive =
isActive; //
<--- ISSUE (Line A)
quikTikitUser.setup_result(x => x.GetDataVersion()).Return
(dataVersion); // (Line B)

application.setup_result(x => x.GetErrors())
.Return(appErrorCollection);
application.Version = appVersion;

base.establish_context();
}

protected override void because()
{
result = system_under_test.CreateXMLOutput(quikTikitUser,
application);
}

[Observation]
public void
Should_ask_the_user_and_the_application_for_any_errors()
{
quikTikitUser.was_told_to(x => x.GetErrors());
application.was_told_to(x => x.GetErrors());
}

[Observation]
public void Should_ask_the_user_for_its_dataversion()
{
quikTikitUser.was_told_to(x => x.GetDataVersion());
}


private const string outputXML =
@"<reply>
<error>{0}</error>
<user>
<active>{1}</active>
</user>
<app>
<version>{2}</version>
</app>
<data>
<version>{3}</version>
</data>
</reply>";

[Observation]
public void Should_create_valid_xml()
{
var validXML = string.Format(outputXML, "user error - app
error", isActive, appVersion, dataVersion);
result.should_be_equal_to(validXML);
}
}
}

FrankM

unread,
Feb 6, 2009, 3:18:18 PM2/6/09
to Rhino.Mocks
I got similar problem before, and it was a bug in version 3.5.0.2 from
RC1(?), it has been fixed in the latest release.
Reply all
Reply to author
Forward
0 new messages