问题
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