chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I found that TypeMock is not able to verify arguments when my static method returns ReadOnlyCollection. When I change the type to List verification succeed.

Example:

Isolate.WhenCalled(() => FileLoader.GetFiles(null, null)).WillReturn(files);

ReadOnlyCollection<String> files = FileLoader.GetFiles("C:Temp", "*.dll");

Isolate.Verify.WasCalledWithExactArguments(() => FileLoader.GetFiles("C:Temp", "*.dll"));


If the FileLoader.GetFiles() returns ReadOnlyCollection<String> I will get the error saying

"System.ArgumentNullException: Value cannot be null.
Parameter name: list
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.ObjectModel.ReadOnlyCollection`1..ctor(IList`1 list)
at b2.a(Object A_0, MethodBase A_1, Object A_2, Boolean A_3)
at f7.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Object p1, Object p2)
at FileLoader.GetFiles(String path, String searchPattern) in FileLoader.cs: line 36"

but when it returns List<String> it works.

I'm using TypeMock version 5.4.2.0
asked by JK (3.1k points)

4 Answers

0 votes
Intresting, I didn't see this sort of behavior yet.

Can you post the FileLoader class definition here?

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
public static class FileLoader
{
        public static ReadOnlyCollection<String> GetFiles(String path, String searchPattern)
        {
            List<String> fileList = new List<String>();

            String[] files = Directory.GetFiles(path, searchPattern);

            foreach (string file in files)
            {
                fileList.Add(file);
            }

            return fileList.AsReadOnly();
        }
}
answered by JK (3.1k points)
0 votes
JK,

This is indeed a bug :(. I'm logging this and we'll fix it in an upcoming version.

As a work around you can use the non public API like this:
Isolate.Verify.NonPublic.WasCalled(typeof(FileLoader), "GetFiles").WithArguments("a", "b");

It's string based so it's not type safe, but it works around the bug. Please let me know if the work around works for you.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
The work around works.
answered by JK (3.1k points)
...