简体   繁体   中英

Does Moq mocking library for .NET 3.5 work with mono?

I'm trying to use Moq on a Mono / .NET 3.5 Project using MonoDevelop for MacOS X

I've tried the sample C# code:

var mock = new Mock<IFoo>();
mock.Setup((foo => foo.DoSomething("ping"))).Returns(true);

With IFoo beeing:

public interface IFoo
{
    bool DoSomething(string a);
}

But I keep getting the following compiler errors on the mock.Setup line:

    Error CS1660: Cannot convert `lambda expression' to non-delegate type `System.Linq.Expressions.Expression<System.Action<Test.IFoo>>' (CS1660) (Test)
    Error CS1502: The best overloaded method match for `Moq.Mock<Test.IFoo>.Setup(System.Linq.Expressions.Expression<System.Action<Test.IFoo>>)' has some invalid arguments (CS1502) (Test)
    Error CS1503: Argument `#1' cannot convert `anonymous method' expression to type `System.Linq.Expressions.Expression<System.Action<Test.IFoo>>' (CS1503) (Test)

Am I doing something wrong or it´s just that Mono is not yet ready for Moq?

Like said in Preet Sangha 's comment:

Add a reference to System.Core

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM