Are you able to refactor to give it a backing field rather than the private
set? I don't know why that doesn't work, but I know if you remove the
private set and use the following, it works:
private string name;
public virtual string Name
{
get { return name; }
}
On Thu, Aug 20, 2009 at 6:36 PM, Brian Low <[email protected]> wrote:
>
> Hi,
>
> Is it possible to stub a property with a private (or protected)
> setter?
>
> public class Person
> {
> public virtual string Name { get; private set; }
> }
>
> [Test]
> public void CanStub()
> {
> var personStub = MockRepository.GenerateStub<Person>();
> personStub.Stub(p => p.Name).Return("Joe");
> Assert.AreEqual("Joe", personStub.Name);
> }
>
> The above test gives an error "You are trying to set an expectation on
> a property that was defined to use PropertyBehavior." and suggests
> assigning a value directly - which we can't since the setter is
> private.
>
> Thanks!
> Brian
>
> >
>
--
Chris Missal
http://chrismissal.lostechies.com/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---