RE: [Moq] Linq to Mocks return null

115 views
Skip to first unread message

Vicenç Garcia

unread,
Feb 13, 2014, 1:38:22 PM2/13/14
to moq...@googlegroups.com
Try creating a variable, assign it to null, and use it in the mock.

Sent from my Windows Phone

From: Jozef Krchňavý
Sent: ‎13/‎02/‎2014 18:31
To: moq...@googlegroups.com
Subject: [Moq] Linq to Mocks return null

Hello,
is it possible to mock null as return value using Linq to Mocks?

something like this:

public class IMyClass
{
  string MyMethod(int a);
}

// following line doesn't work:
var mock = Mock.Of<IMyClass>(c=> c.MyMethod(5) == null);

// neither this one
var mock = Mock.Of<IMyClass>(c=> c.MyMethod(5) == (string)null);

// only without Linq to Mocks
var mock = new Mock<IMyClass>();

mock.Setup(m=>m.MyMethod(5)).Returns((string)null);

Thank you!
Jozef

--
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Moq Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moqdisc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Daniel Cazzulino

unread,
Feb 18, 2014, 1:29:36 PM2/18/14
to moqdisc

Sounds like this should be supported. Can you create an issue in github please? (Moq4 project)

/kzu from mobile

Reply all
Reply to author
Forward
0 new messages