jjzjj

SetupGet

全部标签

c# - 我如何在我的单元测试中模拟 Controller 上下文,以便我对字符串函数的部分 View 起作用?

我正在尝试为我的Controller创建一个单元测试,但我正在测试的操作使用部分View来字符串函数,它不想在我的测试中工作。privatestringRenderPartialViewToString(stringviewName,objectmodel=null){if(string.IsNullOrEmpty(viewName))viewName=ControllerContext.RouteData.GetRequiredString("action");ViewData.Model=model;using(System.IO.StringWritersw=newSystem.

c# - 使用 SetupGet 和 SetupSet 模拟属性 - 这可行,但为什么呢?

使用Moq我正在模拟一个属性,ReportTheReport{get;放;在接口(interface)ISessionData上,以便我可以检查在此属性上设置的值。为此,我使用了SetupGet和SetupSet,如下所示://class-levelfieldsprotectedReport_sessionReport;protectedMockSessionData{get;privateset;}在我的设置方法中...SessionData=newMock();SessionData.SetupSet(s=>s.TheReport=It.IsAny()).Callback(r=>{

c# - 最小起订量、SetupGet、模拟属性

我正在尝试模拟一个名为UserInputEntity的类,其中包含一个名为ColumnNames的属性:(它确实包含其他属性,我只是针对问题对其进行了简化)namespaceCsvImporter.Entity{publicinterfaceIUserInputEntity{ListColumnNames{get;set;}}publicclassUserInputEntity:IUserInputEntity{publicUserInputEntity(ListcolumnNameInputs){ColumnNames=columnNameInputs;}publicListColu