OK - I found the problem. I just would like to know why it caused me so much heart-ache. This code compiles but it will not run - the Exception caused me a lot of grief also - italicized below. As soon as I change the FakeAnother property to a member instead of a property, everything works happily.
TypeMock.TypeMockException occurred
Message="
*** No method with name Setup>b__1 in type GenericBaseClassTest exists."
It looks like the "Setup>b__1 in type GenericBaseClassTest" has overwritten the real missing method name.
using System;
using System.Reflection;
using NUnit.Framework;
using TypeMock;
using TypeMock.ArrangeActAssert;
[TestFixture]
[ClearMocks]
public class GenericBaseClassTest : TestBaseClass<TestController>
{
private IAnother _another;
protected IAnother FakeAnother
{
get { return _another; }
set { _another = value; }
}
[SetUp]
public void Setup()
{
FakeAnother = Isolate.Fake.Instance<IAnother>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => ServiceFactory.CreateInstance()).WillReturn(FakeSvcFactory);
Isolate.WhenCalled(() => FakeSvcFactory.ReturnAnother()).WillReturn(FakeAnother);
Isolate.WhenCalled(() => FakeAnother.GetObject()).WillReturn(null);
}
[Test]
[Isolated]
[VerifyMocks]
public void Test1()
{
Controller.DoSomething();
}
}
public interface IAnother
{
object GetObject();
}
public class Another : IAnother
{
public object GetObject()
{
return new object();
}
}
public class ServiceFactory
{
public static ServiceFactory CreateInstance()
{
return new ServiceFactory();
}
public IAnother ReturnAnother()
{
return new Another();
}
}
public class TestBaseClass<C> where C : TestController
{
protected F FakeSvcFactory;
protected C Controller;
protected TestBaseClass()
{
//create a factory instance
FakeSvcFactory = Isolate.Fake.Instance<F>();
Isolate.Fake.StaticMethods<F>(Members.ReturnRecursiveFakes);
//create the controller
ConstructorInfo ci = typeof (C).GetConstructor(new Type[] {typeof (F)});
//inject the factory into the controller
Controller = ci.Invoke(new object[] {FakeSvcFactory}) as C;
}
}
public class TestController
{
private ServiceFactory _sf;
public TestController()
{}
public TestController(ServiceFactory sf)
{ _sf = sf; }
public void DoSomething()
{
IAnother a = _sf.ReturnAnother();
}
}