A while back, I added an example of this here:
http://hibernatingrhinos.com/open-source/rhino-mocks/mocking-a-read-only-property

What are some other commonly asked questions that I should add to this list?
http://hibernatingrhinos.com/open-source/rhino-mocks/code-examples



On Thu, Jan 21, 2010 at 6:25 AM, Kai <[email protected]> wrote:

> Thanks.
>
> Just what I was looking for :o)
>
>
>
> On 21 Jan, 09:42, Alex McMahon <[email protected]> wrote:
> > Off the top of my head I think if you want to stub a read-only property
> you
> > need to use the Stub method:
> >
> > alarmPropertyStub.Stub(x=>x.Value).Return(1);
> >
> > 2010/1/21 Kai <[email protected]>
> >
> >
> >
> > > Hello.
> >
> > > I have just started using Rhino mocks and have a little question. Many
> > > of our interfaces have properties, but the set method is omitted. The
> > > properties are set in the class that implements the interface. Is
> > > there a way to use Rhino Mocks to stub interface like that?
> >
> > > I keep gettign this compilation error.
> > > error CS0200: Property or indexer IManagedAlarmProperty.DataType'
> > > cannot be assigned to -- it is read only
> >
> > > Here is my interface:
> > >  public interface IManagedAlarmProperty
> > >    {
> > >        /// <summary>
> > >        /// Property value
> > >        /// </summary>
> > >        object Value { get; }
> >
> > >        /// <summary>
> > >        /// datatype of property
> > >        /// </summary>
> > >        Type DataType { get; }
> > >    }
> >
> > > Here is my method that stubs this interface.
> > >        static IManagedOskAlarmProperty CreateAlarmProperty(string
> > > property)
> > >        {
> > >            IManagedOskAlarmProperty alarmPropertyStub =
> > > MockRepository.GenerateStub<IManagedOskAlarmProperty>();
> > >            alarmPropertyStub.DataType = typeof(double);       <---
> > > compilation error.
> > >            alarmPropertyStub.Value = 1;
> > > <-- compilation error.
> > > return alarmPropertyStub;
> > >        }
> >
> > > Thanks,
> > > Kai
> >
> > > --
> > > 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]<rhinomocks%[email protected]>
> <rhinomocks%2bunsubscr...@googlegrou­ps.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/rhinomocks?hl=en.– Skjul sitert tekst –
> >
> > – Vis sitert tekst –
>
> --
> 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]<rhinomocks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rhinomocks?hl=en.
>
>
>
>


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

Reply via email to