Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are NSubstitute limitations, specially vs MOQ?

I'm about to take a decision about the mocking library for my next project.

and because I'm new to those libraries I made a quick search

I found that MOQ is much popular than NSubstitute and I expect more help from the community specially here at SO

But I liked NSubstitute syntax more, also it has a nice docs.

So my question is "Is there any thing that I can achieve using MOQ I cant achieve using NSubstitute?"

like image 243
George Botros Avatar asked Jan 18 '16 09:01

George Botros


2 Answers

I am not aware of any limitation of nsubstitute

Few years ago I was an adept of moq, and now I have a preference for nsubstitute. I like the syntax (you call directly the method vs setup.), I think NSubstitute has the best syntax and is the most readable of all the frameworks (but this is a subjective assertion ^^).

Oh maybe one thing : NSubstitute don't have a strict mock mode (but I always thought it was a bad idea, so I never saw it as a limitation)

like image 106
rad Avatar answered Oct 04 '22 19:10

rad


I noticed that when trying to mock a call to a method in NSubstitute by using .Do(), you can use the parameters only as an array of objects. In Moq you can force the number, types and names of parameters.

For example:

  • NSubstitute: .Do(param => new ExObject{ s = (string) param[0], i = (int) param[1] })
  • Moq: .Callback< string, int>((text, nb) => new ExObject{ s = text, i = nb })

I found it easier to understand in Moq, as you can read more easily the parameters, rather than to have to count which one is it.

like image 34
Cosmin Avatar answered Oct 04 '22 17:10

Cosmin