1
如何爲WcfOperationLifestyle容器單元測試注射?我在我的MyBootstrapper類WcfOperationLifestyle簡單注射器單元測試
container = new Container();
container.Options.DefaultScopedLifestyle = new WcfOperationLifestyle();
...
container.Register<IService, Service>(Lifestyle.Scoped);
根據
http://simpleinjector.readthedocs.io/en/latest/wcfintegration.html
,但是當我的單元測試
var actual = MyBootstrapper.Container.GetInstance<IService>();
我得到
的IService被註冊爲 'WCF操作' 的生活方式,但實例在WCF操作的範圍之外被請求。 這是完全合理的,因爲測試運行不是WCF環境。
我在另一個單元測試中使用Verify方法。當前的單元測試用於檢查裝飾注入是否在特定環境下正確完成(例如UAT中的假實現,產品中的真實實現等)。謝謝,我會按照你的建議。 – kord