2016-01-20 22 views
0

我試圖使用Autofixture使用此代碼來測試我的mvc控制器: -Autofixture - fixture.CreateAnonymous <myController的>()的非法請求異常失敗的測試

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)); 

Hoever這個現在拋出一個新的異常

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. 

我現在似乎被卡住。

有沒有其他人來解決這個問題並解決它?或者知道一種不同的方式來輕鬆地固定我的控制器?

感謝

+1

您需要自定義'ViewDataDictionary' _and_ ControllerContext'。所以基本上你需要保持兩條線。請參閱以下答案以供參考:http://stackoverflow.com/a/14989866/26396和http://stackoverflow.com/a/6592112/26396 –

+0

@EnricoCampidoglio據我所知,定製應該足夠了。 –

+0

我剛剛嘗試過,但我無法用AutoFixture 3.39.0和Microsoft.AspNet.Mvc 5.2.3重現此行爲。我們如何重現這個問題? –

回答

0

這是記在我的。包裝文件告訴我,我是用Autofixture 3.39.0,但測試項目實際參考2.0.0。

卸載舊版本並從解決方案中刪除並重新添加解決了問題。

相關問題