In justmock we can return mocked instances instead of actual instances by Arranging the constructor call like
Mock.Arragne(()=>new MyClass(Arg.IsAny<string>())).IgnoreInstance().Returns(Mock.Create<MyClass>());
but when I tried the same with UrlHelper
class, instead of mocked type, actual type is getting instantiated. Can anybody tell if there's any mistake in this:
UrlModel class
public class UrlModel
{
private UrlHelper url;
public UrlModel()
{
url = new UrlHelper(HttpContext.Current.Request.RequestContext);
}
}
Test method :
public void UrlTest()
{
Mock.Arrange(() => HttpContext.Current.Request.RequestContext).Returns(Mock.Create<RequestContext>());
var mockedUrl = Mock.Create<UrlHelper>();
Mock.Arrange(() => new UrlHelper(Arg.IsAny<RequestContext>()))
.IgnoreArguments()
.IgnoreInstance()
.Returns(mockedUrl);
//Here url will have actual instance instead of mocked instance
var model = new UrlModel();
//Assert is ommitted for bravity ..
}