Mock in Nemerle

43 views
Skip to first unread message

SergXIIIth

unread,
Feb 8, 2010, 12:07:35 PM2/8/10
to Nemerle Forum
Hi.

I use Moq. But I can not use with Nemerle.

public interface IBudgetRepo
{
List(): IEnumerable[string];
}

[Test]
public Tes1(): void
{
def repo = Mock.[IBudgetRepo]();
repo.Setup(r=>r.List()).Return(null);
}

Compiler error

Error each overload has an error during call: Overload #1, method
Moq.Mock.Setup(expression :
System.Linq.Expressions.Expression[System.Func[T, TResult]]) :
Moq.Language.Flow.ISetup[T, TResult]. In argument #1 (expression) of
repo.Setup.[?], needed a
System.Linq.Expressions.Expression[System.Func[Money.Model.IBudgetRepo, ?]],
got ? -> ?: Money.Model.IBudgetRepo -> ? is not a subtype of
System.Linq.Expressions.Expression[System.Func[Money.Model.IBudgetRepo, ?]]
[simple require]. Overload #2, method Moq.Mock.Setup(expression :
System.Linq.Expressions.Expression[System.Action[T]]) :
Moq.Language.Flow.ISetup[T]. In argument #1 (expression) of
repo.Setup, needed a
System.Linq.Expressions.Expression[System.Action[Money.Model.IBudgetRepo]],
got ? -> ?: Money.Model.IBudgetRepo -> void is not a subtype of
System.Linq.Expressions.Expression[System.Action[Money.Model.IBudgetRepo]]
[simple require]


How can I use Moq?

emp...@gmail.com

unread,
Feb 9, 2010, 5:17:11 PM2/9/10
to Nemerle Forum
That's the ambiguity of C# for lambda expressions. In C# lambda
expressions can refer to two things
1st a delegate, 2nd a System.Linq.Expressions.Expression. And compiler
chooses appropriate one. Nemerle does not do this. In nemerle lambda
=> always refers to delegates. That's why you get compile time error.
Moq wants a
System.Linq.Expressions.Expression[System.Func[Money.Model.IBudgetRepo, ?]]
but you sent it a Money.Model.IBudgetRepo -> ?

Though there is a way to convert lambdas to expressions with Vlad's
linq macro which includes ToExpression macro that you use it as

ToExpression( x=>y)

Here's the test code for it :
http://code.google.com/p/nemerle/source/browse/nemerle/trunk/Linq/Testes/Main.n

I hope it helps

SergXIIIth

unread,
Feb 15, 2010, 10:22:47 AM2/15/10
to Nemerle Forum
Thanks it work!

using Nemerle.Data.Linq;

...

def mock = Mock.[IMvcCtrl]();
_ = mock.Setup(ToExpression(c=>c.CurrentUser)).Returns(currentUsr);
_ = mock.Setup(ToExpression(c=>c.TimeZoneOffset)).Returns(0);

MvcCtrlWrap(mock.Object);

Kamil Skalski

unread,
Sep 15, 2013, 6:43:57 AM9/15/13
to nemer...@googlegroups.com
Hi,
I am trying some examples using Moq and type inference is failing in
following example
using Moq;

class Foo {
public virtual Bar() : bool { true }
}

def mock = Mock.[Foo]();
_ = mock.Setup(x => x.Bar()).Returns(false);

error : there is no member named `Returns' in
Moq.Language.Flow.ISetup[Foo] with type ?

I need to do it like
_ = mock.Setup(fun(x) : bool { x.Bar() }).Returns(false);

doing
_ = mock.Setup(x => x.Bar() : bool).Returns(false);
compiles, but fails in runtime as Moq expects pure method call in
lambda expression, not method call + cast

I'm using ncc
1.1.1046.0
maybe it works better on trunk

NN

unread,
Sep 16, 2013, 4:11:16 PM9/16/13
to nemer...@googlegroups.com, smk...@gmail.com
The reason for this is that compiling everything as expression not fast at all .
And it is not needed everyday.
Reply all
Reply to author
Forward
0 new messages