I am using Moq and I realize In this situation I got the Ambiguous match found
exception that I need help:
Here is my models:
public class User
{
}
public class CustomUser
{
}
Some classes:
public class BaseClass
{
public virtual User User { get; set; }
}
public class Father : BaseClass
{
public virtual new CustomUser User { get; set; }
}
public class Child : Father
{
}
And finally:
void Main()
{
var user = new Mock<CustomUser>();
var child = new Mock<Child>();
child.SetupGet(x=>x.User).Returns (user.Object); // Ambiguous match found.
}
Update:
Why am I using this?!
Because I'm coding MVC-WebAPI
and I have a BaseController
which inherits the ApiController
.
OK, in the ApiController
we have a IPrincipal User
property that I overrided it with my ICustomPrinciple
implementation (this link).
Now I want to mock for example ProductController : BaseController
.
var controller = new Mock<ProductController>();
var user = new Mock<CustomPrincipal>();
user.SetupGet(x => x.FullName).Returns("some full name");
controller.SetupGet(x => x.UserRoleID).Returns(81);// UserRoleID is getter and I do some stuff here.
controller.SetupGet(x => x.User).Returns(user.Object);
Any help will be appreciated.