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
Try the below test:
       [Test, Isolated]
        public void DtMock1()
        {
            Isolate.Swap.NextInstance<DateTime>().With(Isolate.Fake.Instance<DateTime>(Members.ReturnRecursiveFakes));
        }


You will get :
TestCase 'DtMock1'
failed: TypeMock.TypeMockException : 
*** In order to perform swapping the call to NextInstance<T>() must be completed by a call to With()
   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)


But if I run this test
  [Test, Isolated]
        public void DtMock2()
        {
            DateTime dt = Isolate.Fake.Instance<DateTime>(Members.ReturnRecursiveFakes);
            Isolate.Swap.NextInstance<DateTime>().With(dt);
        }


I will get a cannot create mockobejct of struct kind of error.

I think the first error should be the same as the second one.
asked by nsoonhui (59.1k points)

1 Answer

0 votes
I agree the errors are a bit confusing and we will fix this in the next version.

The problem with the test is that you cannot fake DateTime because it is part of MsCorLib.

Hopefully Isolator will be able to fake DateTime in the future but until then you need to wrap it with another class and fake it instead.
answered by dhelper (11.9k points)
...