我正在尝试模拟一个名为 的类UserInputEntity
,其中包含一个名为ColumnNames
: 的属性(它确实包含其他属性,我只是针对问题对其进行了简化)
namespace CsvImporter.Entity
{
public interface IUserInputEntity
{
List<String> ColumnNames { get; set; }
}
public class UserInputEntity : IUserInputEntity
{
public UserInputEntity(List<String> columnNameInputs)
{
ColumnNames = columnNameInputs;
}
public List<String> ColumnNames { get; set; }
}
}
我有一个演示者课程:
namespace CsvImporter.UserInterface
{
public interface IMainPresenterHelper
{
//...
}
public class MainPresenterHelper:IMainPresenterHelper
{
//....
}
public class MainPresenter
{
UserInputEntity inputs;
IFileDialog _dialog;
IMainForm _view;
IMainPresenterHelper _helper;
public MainPresenter(IMainForm view, IFileDialog dialog, IMainPresenterHelper helper)
{
_view = view;
_dialog = dialog;
_helper = helper;
view.ComposeCollectionOfControls += ComposeCollectionOfControls;
view.SelectCsvFilePath += SelectCsvFilePath;
view.SelectErrorLogFilePath += SelectErrorLogFilePath;
view.DataVerification += DataVerification;
}
public bool testMethod(IUserInputEntity input)
{
if (inputs.ColumnNames[0] == "testing")
{
return true;
}
else
{
return false;
}
}
}
}
我尝试了以下测试,在其中模拟实体,尝试获取ColumnNames
属性以返回初始化List<string>()
但它不起作用:
[Test]
public void TestMethod_ReturnsTrue()
{
Mock<IMainForm> view = new Mock<IMainForm>();
Mock<IFileDialog> dialog = new Mock<IFileDialog>();
Mock<IMainPresenterHelper> helper = new Mock<IMainPresenterHelper>();
MainPresenter presenter = new MainPresenter(view.Object, dialog.Object, helper.Object);
List<String> temp = new List<string>();
temp.Add("testing");
Mock<IUserInputEntity> input = new Mock<IUserInputEntity>();
//Errors occur on the below line.
input.SetupGet(x => x.ColumnNames).Returns(temp[0]);
bool testing = presenter.testMethod(input.Object);
Assert.AreEqual(testing, true);
}
我得到的错误表明存在一些无效参数 + 参数 1 无法从字符串转换为
System.Func<System.Collection.Generic.List<string>>
任何帮助,将不胜感激。