chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
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();
    }
}
asked by kkilton (2.4k points)

1 Answer

0 votes
This is a duplicate post - see the original at:
https://www.typemock.com/community/viewt ... k+property
answered by dhelper (11.9k points)
...