Maybe don't use rhino here...create a test specific subclass of User for this particular test.
I'll have to dig into this later as to why this doesn't work (am away from a computer right now) Tim On 6/7/09, Peter Morris <[email protected]> wrote: > > Here is my test... > > [TestMethod] > public void ReturnsRequired_ForEmailAddress_WhenNull() > { > User mockUser = MockRepository.GenerateStub<User>(""); > mockUser.Stub(x => x.EmailAddress).Return(null); > Validator.GetErrors(mockUser) > .Where(e => e.FieldName == "EmailAddress" && e.Error == > "Required").Single(); > } > > Results in this exception: > > Test method > TaskSmart.DomainClasses.Tests.UserValidatorTests.ReturnsRequired_ForEmailAddress_WhenNull > threw exception: 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;. > > I think the error message is incorrect. I cannot set the property > because it has a private setter... > > namespace TaskSmart.DomainClasses > { > public class User > { > public virtual string Title { get; set; } > public virtual string GivenName { get; set; } > public virtual string FamilyName { get; set; } > public virtual string EmailAddress { get; private set; } > > public User(string emailAddress) > { > EmailAddress = emailAddress; > } > } > } > > So how should I get this test to work? I don't want to have to define > interfaces for my domain objects just to achieve testing. > > > Thanks > > Pete > > > -- Sent from my mobile device Tim Barcz ASPInsider http://timbarcz.devlicio.us http://www.twitter.com/timbarcz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
