Mock a Linq to Sql EntityRef using Moq?
Posted
by Jeremy Holt
on Stack Overflow
See other posts from Stack Overflow
or by Jeremy Holt
Published on 2010-04-21T01:46:07Z
Indexed on
2010/04/21
1:53 UTC
Read the original article
Hit count: 1046
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
© Stack Overflow or respective owner