jeudi 28 avril 2016

FakeItEasy - Retrieve Faked object

Is there any way to retrieve the fake objects which were inserted into a faked class?

E.g.

Let's say I have the following interface + class;

public interface IFakeable
{
    void FakeYou();
}

public class SomeClass
{
    private readonly IFakeable _fake;

    public SomeClass(IFakeable fake)
    {
        _fake = fake;
    }

    public void FakeCall()
    {
        _fake.FakeYou();
    }
}

And wanted to test something like the following:

[TestFixture]
public class SomeClassTests
{
    [Test]
    public void FakeCall_CallsIFakeabl_FakeYou()
    {
        var subject = A.Fake<SomeClass>();

        subject.FakeCall();

        A.CallTo(() => A.Fake<IFakeable>().FakeYou()).MustHaveHappened();
    }
}

Is this possible without exposing the SomeClass._fake field?

Is there somewhere I can specify to use Singletons for Fakes?

Aucun commentaire:

Enregistrer un commentaire