Thanks for the response thats the code I had started with almost.
I had tried that code the error that code produces.
System.InvalidOperationException : You are trying to set an
expectation on a property that was defined to use PropertyBehavior.
Instead of writing code such as this: mockObject.Stub(x =>
x.SomeProperty).Return(42);
You can use the property directly to achieve the same result:
mockObject.SomeProperty = 42;
Which is why I ended up where i was in initial post.
I was hoping I could get closer to the form you present as i find it
much easier to read.
If I convert as per the error message I post above.
var mockContext =
MockRepository.GenerateStub<ICommunicationContext>();
var mockPrincipal =
MockRepository.GenerateStub<IPrincipal>();
var mockIdentity =
MockRepository.GenerateStub<IIdentity>();
mockIdentity.Name = testUserName;
mockPrincipal.Identity = mockIdentity;
mockContext.User = mockPrincipal;
In this case the Name, Identity and Request fields are all reported as
not having a Setter.
Property or indexer 'System.Security.Principal.IPrincipal.Identity'
cannot be assigned to -- it is read only
I am using Rhino Mopcks 3.6 with VS2010, Resharper 5.1 and in .Net 4
mode. Though I dont believe that matters much.
I did try disabling Resharper just in case it was doing something to
muck up but had no change to behaviour.
On Mar 11, 3:18 am, Patrick Steele <[email protected]> wrote:
> var context = MockRepository.GenerateStub<ICommunicationContext>();
> var principal = MockRepository.GenerateStub<IPrincipal>();
> var identity = MockRepository.GenerateStub<IIdentity>();
>
> identity.Stub(i => i.Name).Return(testUserName);
> principal.Stub(p => p.Identity).Return(identity);
> context.Stub(c => c.User).Return(principal);
--
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.