I'm trialing the product and im also very new to mocking frameworks. Below is a simple example of something I'm trying to acheive in a much bigger project.
I'm trying to write a unit test for the protected method in an abstract class. I was hoping that the below code would inject a mock "Search" interface object that I had arrange to return a know value. But it doesnt!
What have I missed? Note: I actually want the code instead BaseClass.GetString to execute (that's the test) but I want the Search interface it uses to be a mock.
public interface ISearch
{
string GetString(int type);
}
public abstract class BaseClass
{
public ISearch Search { get; set; }
protected string GetString(int type)
{
return Search.GetString(type);
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var mock = Isolate.Fake.Instance<BaseClass>();
Isolate.WhenCalled(() => mock.Search.GetString(1)).WithExactArguments().WillReturn("one");
string s = Isolate.Invoke.Method(mock, "GetString", 1) as string;
Isolate.Verify.WasCalledWithExactArguments(() => mock.Search.GetString(1));
Assert.IsNotNull(s);
Assert.Equals(s, "one");
}
}