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 Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!
0 votes

When I have TypeMock Suggest and Save tests for a small test project I've created I get the error below.  If I create the same tests manually in a separate project then the tests work.  Any ideas?

Initialization method UnitTestMovieRatings.PriceTests.Setup_RunBeforeEachTest threw exception. TypeMock.TypeMockException: TypeMock.TypeMockException: 
*** *** To protect you from disk deletions and registry corruptions this test class may only run using Typemock SmartRunner.
    at TypeMock.ArrangeActAssert.Suggest.TestUtil.AssertRunningInSandbox()
   at UnitTestMovieRatings.PriceTests.Setup_RunBeforeEachTest() in C:\Users\christian.king\documents\visual studio 2015\Projects\MovieRatings\TypeMockGeneratedTests\MovieRatingsUnitTests\PriceTests.cs:line 59
   at TypeMock.MockManager.getReturn(Object context, String typeName, String methodName, Object methodGenericParams, Boolean isDecorated, Boolean isInterceptedType, Object[] methodArguments)
   at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
   at UnitTestMovieRatings.PriceTests.Setup_RunBeforeEachTest() in C:\Users\christian.king\documents\visual studio 2015\Projects\MovieRatings\TypeMockGeneratedTests\MovieRatingsUnitTests\PriceTests.cs:line 57
asked by (9.1k points)

1 Answer

0 votes
Hello,

It's likely you had [SafetyNet] attribute on your test class. It protects you from harming your system by smth like Directory.Delete() call etc.

How you tried to run this test?
answered by (1.6k points)

If I comment out these two lines then it works:

  • [SafetyNet(typeof(Index))]
  • TypeMock.ArrangeActAssert.Suggest.AssertRunningInSandbox()

Which doesn't make a whole lot of sense because the method under test is a very simple method:

        private static decimal Price(int age)
        {
            if (age < 12)
            {
                return 5m;
            }
 
            if (age < 18)
            {
                return 10m;
            }
 
            return 14.5m;
        }
It's how Suggest works - it defends each test by SafetyNet attribute. And you can always run it via SmartRunner without any problems.

So you can even run it with SmartRunner, or comment/delete these lines.
...