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 have a method:
public string GetDefaultPath()
{
        return Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments, Environment.SpecialFolderOption.DoNotVerify);
}

Which I am trying to mock in my test as follows:

Isolate.WhenCalled(() => target.GetDefaultPath()).WillReturn(DefaultPath);

When I run my test, at the line where I call Isolate.WhenCalled I am getting the following error:

Test method MyNameSpace.MyClassTests.TestSetOptionsMethodSetsProperties threw exception:
System.MissingMethodException: Method not found: 'System.String TypeMock.Interceptors.EnvironmentInterceptor.GetFolderPath(SpecialFolder, SpecialFolderOption)'.
at MyNameSpace.MyClass.GetDefaultPath()
at MyNameSpace.MyClassTests.<>c__DisplayClass1.<TestSetOptionsMethodSetsProperties>b__0() in MyClassUnderTest.cs: line 45
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 MyNameSpace.MyClassTests.TestSetOptionsMethodSetsProperties() in MyClassUnderTest.cs: line 0

I've written a small example class and test which demonstrates the problem. I'm wondering if I am missing a step or whether this is a possible bug in typemock. Any suggestions on how to workaround this issue?

namespace MyNameSpace
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using TypeMock.ArrangeActAssert;

    internal class MyClass
    {
        private string _path = String.Empty;

        public string MyPath
        {
            get { return _path; }
            private set { _path = value; }
        }

        public string GetDefaultPath()
        {
            return Environment.GetFolderPath(
                Environment.SpecialFolder.CommonDocuments, Environment.SpecialFolderOption.DoNotVerify);
        }

        public void SetProperties_MethodUnderTest()
        {
            MyPath = GetDefaultPath() + @"ExtraPathDetail";
        }
    }


    [TestClass]
    public class MyClassTests
    {
        [TestMethod, Isolated]
        public void TestSetOptionsMethodSetsProperties()
        {
            var target = Isolate.Fake.Instance<MyClass>(Members.ReturnRecursiveFakes);
            const string DefaultPath = @"C:MyDefaultPath";
            Isolate.WhenCalled(() => target.GetDefaultPath()).WillReturn(DefaultPath);

            // Act
            Isolate.Invoke.Method(target, "SetProperties_MethodUnderTest");

            // Assert
            Assert.AreEqual(target.GetDefaultPath(), DefaultPath + @"ExtraPathDetail");
        }
    }
}
asked by astrid2000 (640 points)

2 Answers

0 votes
Hi,

Thank you for the code, it reproduced bug.
We'll fix this issue in future versions.
Until we fix it you can use the following workaround :

Locate Namespaces.dat in Typemock installation directory and write in it the name of your test dll.

Let me know if it helps.
answered by alex (17k points)
0 votes
Thanks Alex.

This workaround resolved the issue for us.
answered by astrid2000 (640 points)
...