Skip to content

Instantly share code, notes, and snippets.

@royosherove
Created April 1, 2012 07:46
Show Gist options
  • Save royosherove/2272892 to your computer and use it in GitHub Desktop.
Save royosherove/2272892 to your computer and use it in GitHub Desktop.
Isolator bug with Isolate.nonpublic.wascalled.witharguments
from my tdd class:
[TestFixture, Isolated]
public class LoginManagerWithStaticTestIsolator1
{
[Test]
public void IsLoginOK_LoggerThrowsException_CalledWebService()
{
LoginManagerWithFutureObject lm = new LoginManagerWithFutureObject();
RealLogger fakeLogger = Isolate.Fake.Instance<RealLogger>();
Isolate.WhenCalled(()=>fakeLogger.Write("")).WillThrow(new LoggerException("Stub Message"));
Isolate.Swap.NextInstance<RealLogger>().With(fakeLogger);
Isolate.WhenCalled(()=>Environment.MachineName).WillReturn("MachineName");
//Isolate.NonPublic.WhenCalled(lm, "GetMachineName").DoInstead(context => "MachineName"); // Will work
lm.AddUser("user", "password");
lm.IsLoginOK("user", "password");
/// DOES NOT WORK
Isolate.Verify.NonPublic.WasCalled(lm, "CallWebService").WithArguments("Stub Message MachineName");
//Isolate.Verify.WasCalledWithExactArguments(() => lm.IsLoginOK("user", "password")); // Will work
}
}
using System;
using System.Collections;
namespace MyBillingProduct
{
public class LoginManagerWithFutureObject
{
private Hashtable m_users = new Hashtable();
public bool IsLoginOK(string user, string password)
{
try
{
new RealLogger().Write("blah");
}
catch (LoggerException e)
{
new WebService().Write(e.Message + Environment.MachineName);
}
if (m_users[user] != null &&
m_users[user] == password)
{
return true;
}
return false;
}
public void AddUser(string user, string password)
{
m_users[user] = password;
}
public void ChangePass(string user, string oldPass, string newPassword)
{
m_users[user]= newPassword;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment