Try the below production code:
public interface ISess
{
}
public class UselessSess : ISess
{
}
public interface IInstance
{
ISess Session { get; }
}
public class InstanceJob : IInstance
{
#region IInstance Members
public ISess Session
{
get { throw new NotImplementedException(); }
}
#endregion
}
public class NHiber
{
private static IInstance instance;
public static IInstance Instance
{
get
{
if (instance == null)
instance = new InstanceJob();
return instance;
}
}
}
And here's the test code:
[Test]
public void RunInstanceSingleton_Failed()
{
var uselessSess = new UselessSess();
Isolate.WhenCalled(() => NHiber.Instance.Session)
.WillReturn(uselessSess);
Assert.IsInstanceOfType(typeof(InstanceJob), NHiber.Instance);
}
[Test]
public void RunInstanceSingleton_Pass()
{
var uselessSess = new UselessSess();
var instance = NHiber.Instance;
Isolate.WhenCalled(() => instance.Session)
.WillReturn(uselessSess);
Assert.IsInstanceOfType(typeof(InstanceJob), NHiber.Instance);
}
One test passes and another fails-- and both of them should pass.
I think this is a bug, and I think the reason behind this is that Typemock doesn't have the object in the chain properly, i.e., it should always try to return true object as far as it can, instead of assigning a mock value the moment it sees that it's inside the WhenCalled.
________
Genetically Modified Food