MockQueryable icon indicating copy to clipboard operation
MockQueryable copied to clipboard

Does mocking SingleOrDefaultAsync not work for FakeItEasy ?

Open doddi321 opened this issue 2 years ago • 0 comments

I'm trying to mock the SingleOrDefaultAsync method with FakeItEasy but I get the error:

"FakeItEasy0002: Member SingleOrDefaultAsync can not be intercepted. Only interface members and virtual, overriding, and abstract members can be intercepted."

Here is the my code:

        var claimants = fixture.CreateMany<Claimant>();
        var claimantsDbSet = claimants.AsQueryable().BuildMockDbSet();
        A.CallTo(() => claimantsDbSet.SingleOrDefaultAsync(A<Expression<Func<Claimant, bool>>>.Ignored, A<CancellationToken>.Ignored))
            .Returns(claimant);

Is this not possible with FakeItEasy?

doddi321 avatar Jul 13 '23 09:07 doddi321