Autofixture strange error

坚强是说给别人听的谎言 提交于 2019-12-13 14:29:51

问题


I'm getting this error.

Ploeh.AutoFixture.Kernel.IllegalRequestException : A request for an IntPtr was detected. This is an unsafe resource that will crash the process if used, so the request is denied. A common source of IntPtr requests are requests for delegates such as Func or Action. If this is the case, the expected workaround is to Customize (Register or Inject) the offending type by specifying a proper creational strategy.

This is my test code.I'm using autofac and one of the dependencies is an aggregate service.

var fixture = new Fixture().Customize(new AutoMoqCustomization());

var moq = new Mock<ITaskReadService>();
moq.Setup(x => x.GetFormItems(1)).Returns(GetDataTable());

IIcpServiceAggregate aggregate = _container.Resolve<IIcpServiceAggregate>();

fixture.Freeze(aggregate);
fixture.Freeze(moq.Object);

var c = fixture.CreateAnonymous<TaskController>();

回答1:


Assuming that TaskController is an ASP.NET MVC 3 Controller, you should be able to fix this particular issue by doing this:

fixture.Customize<ViewDataDictionary>(c =>
    c.Without(vdd => vdd.ModelMetadata));

since ViewDataDictionary.ModelMetadata is a Func of sorts (can't remember exactly which one).

OOB support for delegates is coming in a future version of AutoFixture.



来源:https://stackoverflow.com/questions/6582711/autofixture-strange-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!