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");
}
}
}