Mock a Linq to Sql EntityRef using Moq?
- by Jeremy Holt
My datacontext contains a table named Userlog with a one to many relationship with table UserProfile.
In class UserLog
public UserProfile UserProfile
{
get {return this._UserProfile.Entity;}
}
In class UserProfile
public EntitySet<UserLog> UserLogs
{
get{return this._UserLogs;}
}
{
set {this._UserLogs.Assign(value);
}
How would I go about mocking (using Moq) UserLog.UserProfile without changing the autogenerated code?
What I would like to do is something like:
var mockUserLog = new Mock<UserLog>();
mockUserLog.Setup(c=>c.UserProfile.FirstName).Returns("Fred");
etc
I can do this if I go into the designer.cs and make FirstName and UserProfile virtual, however I would like to do this in the partial class.
Any ideas?
Thanks
Jeremy