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