Moq を使用して、Activator.CreateInstance を介して動的に作成したいデータ クラスをスタブ化しようとしています (Moq がスタブ インスタンスである Moq.Object.GetType() を介して) その型を渡しますが、取得しますSystem.MissingMethodException {"No parameterless constructor defined for this object."}
私は何を間違っていますか?Moq に対応するためにサブジェクト コードを変更したくありません。
テスト
private Test() ...
{
var recordStub = new Mock<IRecord>();
var record = recordStub.Object;
var recordDefinition = new RecordDefinition()
{ MappedRecordClassType = record.GetType(), ...
var newRecord = CreateDataRecord(recordDefinition);
...
}
主題
private IRecord CreateDataRecord(RecordDefinition recordDefinition)
{
var result = Activator.CreateInstance(recordDefinition.MappedRecordClassType)
as IRecord;
return result;
}