7 Answers, 1 is accepted
Thanks for the post, i tested your code , yes there were some issue with Justmock setting up null value for List/Dictionary. You can tell me your email address i can send you a build personally if it is too urgent for you.
However, i would like to inform you that returning null for list is a design violation according to frameowrk design guidelines. You might like to check this:
http://stackoverflow.com/questions/1969993/is-it-better-to-return-null-or-empty-collection
Also, you can't return null directly like one you mentioned:
Mock.Arrange(() => stubExampleClass.GetMeAllThyeBobs(Arg.Any<
ISomeParameter
>()).Returns(null);
Rather you will have to do:
Mock.Arrange(() => stubExampleClass.GetMeAllThyeBobs(Arg.Any<
ISomeParameter
>()).Returns((IList<
Bob
>)null);
The previous one acutally wont build as there are other overloads and you need to tell the compiler what overload you acutally want to pick up and set null. Our of curiousity, i found an interesting issue simiilar posted in a forum at google groups for Moq.
http://code.google.com/p/moq/issues/detail?id=167
Hope that helps,
Mehfuz

The build / release is scheduled for early july. Of course in between, if you find more issues just let us know or shoot me an email at mehfuz.hossain@telerik.com
Regards,
Mehfuz
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

I've tried various other ways to mock the return but nothing seems to work other than changing the return type of the method. The method returns an object array. If I change the return type to something like an IList(of Object), Mock.Arrange seems to let me return null, but this isn't really a change I want to make. Any ideas?
Mock.Arrange(OfObject
())(
Function
() mockedInstance.Read()).Returns(
DirectCast
(
Nothing
,
Object
()))
Assert.IsNull(mockedInstance.GetValues())
Thanks again for sending the issue.
Yes we realized that it should not return default value when set explicitly. However it is fixed now and should you require an internal build please let me know. (In that regard, please open up s support ticket since we can't send internal builds on public forum).
Alternatively, we are planning for a patch on this coming Monday which also contains the fix.
Finally about the empty array, we follow framework design guidelines for returning default value for collection or array:
From the Framework Design Guidelines 2nd Edition [1] (pg. 256):
DO NOT return null values from collection properties or from methods returning collections. Return an empty collection or an empty array instead.
Kind Regards,
Mehfuz
the Telerik team

I had this situation. I needed to test the managing that I was doing to null responses and I had something like this:
ObjectDto objDto =
null
;
Mock.Arrange(() => _service.GetObjDto(someParameter, _cancellationToken))<br> .Returns(Task.FromResult(objDto));
But with, still is returning an instance of ObjectDto.
I solvedtryed to use
Mock.Arrange(() => _service.GetLockAsync(Guid.NewGuid(), _cancellationToken)) .Returns(Task.FromResult<ObjectLockDto>(
null
));
but still getting me the empty instance instead the null so I changed for
Mock.Arrange(() => _service.GetLockAsync(Arg.IsAny<Guid>(), Arg.IsAny<CancellationToken>())) .Returns(Task.FromResult<ObjectLockDto>(
null
));
Hello Nicolas,
The arrangements you are using should behave in the same way, the only difference is the scope that they are applicable to - the first two of them are applicable if there is an exact match of the given parameters in the arrangement expression, the last one - for any possible values of the parameters. I have made a sample project and played a little bit with this use case, but I am unable to observe such a problem, probably I have missed something. Please use the attached sample and modify it to match the issue and send it back to us for further investigation.
Regards,
Ivo
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.