C# 使用Mock.of的对象的最小起订量返回值?

C# 使用Mock.of的对象的最小起订量返回值?,c#,unit-testing,moq,C#,Unit Testing,Moq,我需要模拟对象中方法的返回值。我有这样的想法: var mock = Mock.Of<IExample>( x => x.GetAll() == new List<IOtherExample>()) ; mock.Setup(x => x.GetAll()).Returns(new List<IOtherExample>()); Expression of type 'System.Collections.Generic.List' cann

我需要模拟对象中方法的返回值。我有这样的想法:

var mock = Mock.Of<IExample>( x => x.GetAll() == new List<IOtherExample>()) ;
mock.Setup(x => x.GetAll()).Returns(new List<IOtherExample>());
 Expression of type 'System.Collections.Generic.List' cannot be used for parameter of type 'System.Collections.Generic.IList' of method 'Moq.Language.Flow.IReturnsResult' Returns(System.Collections.Generic.IList)'
再次请记住,如果GetAll是一个属性,那么它是有效的

多谢各位

public interface IExample : IGenericExample<IOtherExample>
{

}

public interface IGenericExample<T>
{
   IList<T> GetAll()
}
公共接口示例:IGenerice示例
{
}
公共接口IGenerice示例
{
IList GetAll()
}

由于代码格式问题,无法将此作为注释发布:

void Main()
{   
    var t = Mock.Of<IExample>(x => x.GetAll() == new List<IOtherExample>());
    t.GetAll().Dump();
}

// Define other methods and classes here
public interface IOtherExample
{
}

public interface IExample : IGenericExample<IOtherExample>
{

}

public interface IGenericExample<T>
{
   IList<T> GetAll();
}
void Main()
{   
var t=Mock.Of(x=>x.GetAll()==newlist());
t、 GetAll().Dump();
}
//在此处定义其他方法和类
公共接口IoThere示例
{
}
公共接口示例:IGenerice示例
{
}
公共接口IGenerice示例
{
IList GetAll();
}

这在我的LINQPad中有效,我使用的是MOQ4.0。我遗漏了什么吗?

也许如果你粘贴了一个完整的代码示例会有所帮助,在LINQPad中尝试一个简单但类似的东西对我来说很有用。我猜
x=…
是一个输入错误,因为它应该是
x=>…
。我已经添加了界面的外观。除此之外,似乎没有更多的代码相关。我修正了你提到的打字错误。LINQ表达式在编译时是有效的。它在运行时失败。
void Main()
{   
    var t = Mock.Of<IExample>(x => x.GetAll() == new List<IOtherExample>());
    t.GetAll().Dump();
}

// Define other methods and classes here
public interface IOtherExample
{
}

public interface IExample : IGenericExample<IOtherExample>
{

}

public interface IGenericExample<T>
{
   IList<T> GetAll();
}