eugeneK
eugeneK

Reputation: 11146

How to setup specific call to for mocks?

I'm using FakeItEasy to mock stuff within unit tests but somehow i fail to setup pretty basic scenario. ie. i want to throw exception when specific user accesses a method. Help would be nice... thanks

A.CallTo(() => m_fancyRepository
                .CanIDoFancyThings(A<User>
                    .That
                    .Matches(u => u.Id.Equals(m_user.Id)))
                .Verify())
                .Throws(new Exception("omg !!! ???!"));

Upvotes: 1

Views: 42

Answers (1)

Joel R Michaliszen
Joel R Michaliszen

Reputation: 4222

Try to remove the Verify() method after the stub, like this:

A.CallTo(() => m_fancyRepository.CanIDoFancyThings(
            A<User>.That.Matches(u => u.Id.Equals(m_user.Id))))
            .Throws(new Exception("omg !!! ???!"));

Upvotes: 2

Related Questions