Hi Eli,
That API for getting future fakes sounds great.
Here is Isolate2.cs:
using System;
using System.Diagnostics;
using NUnit.Framework;
using TypeMock.ArrangeActAssert;
[DebuggerStepThrough]
public static class Isolate2
{
public static T Fake<T>(Members members = Members.MustBeSpecified)
{
return Isolate.Fake.Instance<T>(members);
}
public static T FakeNext<T>()
{
return Isolate.Fake.NextInstance<T>(Members.MustBeSpecified);
}
public static T ReturnFakeFromGetter<T>(Func<T> getter)
{
var fakeT = Isolate2.Fake<T>();
Isolate2.Return(fakeT, getter);
return fakeT;
}
public static void ReturnIf<T>(bool doSetReturnValue, T returnValue, Func<T> func)
{
if (doSetReturnValue)
{
Isolate.WhenCalled(func).WillReturn(returnValue);
}
}
public static void FakeStatics(Type type)
{
Isolate.Fake.StaticMethods(type, Members.MustBeSpecified);
}
public static void Return<T>(T returnValue, Func<T> func)
{
Isolate.WhenCalled(func).WillReturn(returnValue);
}
public static void Ignore(Action action)
{
Isolate.WhenCalled(action).IgnoreCall();
}
public static void Ignore<T>(Func<T> action)
{
throw new NotImplementedException("Cannot Ignore() a non-void method");
}
public static void ExactArgs(Action action)
{
Isolate.Verify.WasCalledWithExactArguments(action);
}
public static void ExactArgs<T>(Func<T> func)
{
Isolate.Verify.WasCalledWithExactArguments(func);
}
public static void ExactArgsOnce(Action action)
{
Isolate2.ExactArgsNTimes(1, action);
}
public static void ExactArgsOnce<T>(Func<T> func)
{
Isolate2.ExactArgsNTimes(1, func);
}
public static void ExactArgsOnceIf(bool doAssertExactArgsOnce, Action action)
{
if (doAssertExactArgsOnce)
{
Isolate2.ExactArgsOnce(action);
}
else
{
Isolate2.NotCalled(action);
}
}
public static void ExactArgsNTimes(int n, Action action)
{
if (n > 0)
{
Isolate.Verify.WasCalledWithExactArguments(action);
}
Assert.AreEqual(n, Isolate2.GetTimesCalled(action), "Times called");
}
public static void ExactArgsNTimes<T>(int n, Func<T> func)
{
if (n > 0)
{
Isolate.Verify.WasCalledWithExactArguments(func);
}
Assert.AreEqual(n, Isolate2.GetTimesCalled(func), "Times called");
}
public static int GetTimesCalled(Action action)
{
return Isolate.Verify.GetTimesCalled(action);
}
public static int GetTimesCalled<T>(Func<T> func)
{
return Isolate.Verify.GetTimesCalled(func);
}
public static void NotCalled(Action action)
{
Isolate.Verify.WasNotCalled(action);
}
public static void Throw(Exception exception, Action action)
{
Isolate.WhenCalled(action).WillThrow(exception);
}
public static void ThrowIf(bool doThrow, Exception exception, Action action)
{
if (doThrow)
{
Isolate.WhenCalled(action).WillThrow(exception);
}
else
{
Isolate.WhenCalled(action).IgnoreCall();
}
}
public static void TimesCalled(int expectedTimesCalled, Action action)
{
Assert.AreEqual(expectedTimesCalled, Isolate2.GetTimesCalled(action));
}
public static void TimesCalled<T>(int expectedTimesCalled, Func<T> func)
{
Assert.AreEqual(expectedTimesCalled, Isolate2.GetTimesCalled(func));
}
public static void CallOriginal(Action action)
{
Isolate.WhenCalled(action).CallOriginal();
}
}