Autofixture - fixture.CreateAnonymous<MyController>() 测试失败并出现非法请求异常
Autofixture - fixture.CreateAnonymous<MyController>() failing test with illegal request exception
我正在尝试使用 Autofixture 通过以下代码测试我的 Mvc 控制器:-
var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.Customize<ViewDataDictionary>(vdd => vdd.Without(x => x.ModelMetadata));
var sut = fixture.CreateAnonymous<MyController>();
抛出以下异常
Exception has been thrown by the target of an invocation.
The method or operation is not implemented.
经过一些谷歌搜索后,这似乎归结为使用 MVc4 及更高版本,解决方法是将自定义行更改为
fixture.Customize<ControllerContext>(vdd => vdd.Without(x => x.DisplayMode));
但是这现在抛出一个新的异常
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<T> or Action<T>. If this is the case, the expected
workaround is to Customize (Register or Inject) the offending type by
specifying a proper creational strategy.
我现在好像卡住了
有没有其他人遇到过这个问题并解决了它?或者知道可以轻松固定我的控制器的不同方法吗?
谢谢
这是因为我的 .package 文件告诉我我使用的是 Autofixture 3.39.0,但测试项目实际上引用的是 2.0.0。
卸载旧版本并从解决方案中删除并重新添加解决了问题。
我正在尝试使用 Autofixture 通过以下代码测试我的 Mvc 控制器:-
var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.Customize<ViewDataDictionary>(vdd => vdd.Without(x => x.ModelMetadata));
var sut = fixture.CreateAnonymous<MyController>();
抛出以下异常
Exception has been thrown by the target of an invocation.
The method or operation is not implemented.
经过一些谷歌搜索后,这似乎归结为使用 MVc4 及更高版本,解决方法是将自定义行更改为
fixture.Customize<ControllerContext>(vdd => vdd.Without(x => x.DisplayMode));
但是这现在抛出一个新的异常
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<T> or Action<T>. If this is the case, the expected
workaround is to Customize (Register or Inject) the offending type by
specifying a proper creational strategy.
我现在好像卡住了
有没有其他人遇到过这个问题并解决了它?或者知道可以轻松固定我的控制器的不同方法吗?
谢谢
这是因为我的 .package 文件告诉我我使用的是 Autofixture 3.39.0,但测试项目实际上引用的是 2.0.0。
卸载旧版本并从解决方案中删除并重新添加解决了问题。