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
0 votes
Hello,

I have an exception when I mock a static class (with TypeMock 7.1.1 and VS 2012 RTM) like this:
var spListItem = Isolate.Fake.Instance<SPListItem>();

Isolate.Fake.StaticMethods<A>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => A.Method("1", "2"))
          .WithExactArguments()
          .WillReturnCollectionValuesOf(new[] { spListItem });

or like this
var spListItem = Isolate.Fake.Instance<SPListItem>();

Isolate.Fake.StaticMethods<A>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled((string s1, string s2) => A.Method(s1, s2))
          .AndArgumentsMatch((s1, s2) => s1.Equals("1") && s2.Equals("2"))
          .WillReturnCollectionValuesOf(new[] { spListItem });

The static class is:
public class A
     {
          public static SPListItemCollection Method(string string1, string string2)
          {
               return null;
          }
     }

When running the code, I get this exception:
TypeMock.TypeMockException
*** Can not fake methods defined in mscorlib, try faking the defining type
     à ik.b(Object A_0)
     à ik.d(Object A_0)
     à TypeMock.ArrangeActAssert.ExpectationEngine`1.<>c__DisplayClass22.b()
     à ik.a(Object A_0, Boolean A_1, Func`1 A_2, Action A_3, Action A_4, Action A_5, Boolean A_6)
     à TypeMock.ArrangeActAssert.ExpectationEngine`1.a(IEnumerable A_0)
asked by julien.binet (1.1k points)

4 Answers

0 votes
Hi,

Is it happening only when SharePoint objects are involved?

1. Are you using MSTest to execute the tests? If so, are you linked with any other profiler? Are you running with Coverage or Test-Impact (can be checked in TestSettings file)?
2. Is it happening only in Visual-Studio 2012 projects? Does it work in Visual-Studio 2010 too?

I'll check this issue and try to provide a solution quickly.
answered by Elisha (12k points)
0 votes
Hi,

I use xUnit for the test framework, I also try with NUnit and MSTest but it also fails.

I not use other profile.

I execute the tests in a different way from VS 2010 and VS 2012 :
- with extension xUnit Runner
- with Test Driven .NET
- with Resharper
In all cases, the test fails.

I also try with xUnit GUI Test Runner for testing with xUnit (run from TMockRunner.exe) and I get the same exception.

I try to change the value returned by the static class, and the test fails only when the returned value is a collection object Sharepoint.

For example, the test pass when I return an IEnumerable <string>, string or SPList, but fails when I return a SPListCollection or SPListItemCollection

I think the problem comes from the use of WillReturnCollectionValuesOf with TypeMock.

Best regards,
Julien
answered by julien.binet (1.1k points)
0 votes
Thanks,

I'm trying to reproduce it and I'll update soon.
answered by Elisha (12k points)
0 votes
Hi Julien,

We have a reproduction of this issue and we are working on it.
I'll update you when there's progress.
answered by NofarC (4k points)
...