I have the following simplified code that describes my problem:
public interface IMyUser
{
int Id { get; set; }
string Name { get; set; }
}
Used in the dataccess layer as follows:
public interface IData
{
T GetUserById<T>(int id) where T : IMyUser, new();
}
The userlogic class is defined as follows:
public class UserLogic
{
private IData da;
public UserLogic(IData da)
{
this.da = da;
}
public IMyUser GetMyUserById(int id)
{
return da.GetUserById<MyUser>(id);
}
}
User logic uses the MyUSer class , which is displayed only internally.
I want to use Moq to make fun of a call at the dataaccess level . But since I cannot access the MyUser class from my unit test code (which is also designed), I don’t know how to configure moq? A.
Moq code should look something like this:
var data = new Mock<IData>();
data.Setup(d => d.GetUserById<MyUser ???>(1)).Returns(???);
var logic = new UserLogic(data.Object);
var result = logic.GetMyUserById(1);
How to solve this?
source
share