I was wondering if anyone had a similar example to this post for FakeItEasy (original post is here. I have been trying to find the correct setup, but could not get it right. I could not find any examples online. I am beginning to teach myself unit testing and I decided to use FakeItEasy. All my projects so far use the entity framework and do not use the Repository/UOW pattern since I consider DbSet and DbContext good enough for my small scale applications. I understand there are pros/cons with EF and unit testing, but I would still like to figure this out. I am pretty sure I am way off with my attempt (see below) since the error I get is
System.NotImplementedException: The member 'IQueryable.Provider' has not been implemented on type 'DbSet
1Proxy' which inherits from 'DbSet
1'. Test doubles for 'DbSet`1' must provide implementations of methods and properties that are used.
Any direction will be very helpful. Thank you.
var data = new List<Request>
{
request1,
request2,
request3
}.AsQueryable();
var fakeDbSet = A.Fake<DbSet<Request>>();
A.CallTo(() => ((IQueryable<Request>)fakeDbSet).Provider).Returns(data.Provider);
A.CallTo(() => ((IQueryable<Request>)fakeDbSet).Expression).Returns(data.Expression);
A.CallTo(() => ((IQueryable<Request>)fakeDbSet).ElementType).Returns(data.ElementType);
A.CallTo(() => ((IQueryable<Request>)fakeDbSet).GetEnumerator()).Returns(data.GetEnumerator());
var fakeContext = A.Fake<RequestPortalContext>();
A.CallTo(() => fakeContext.Requests).Returns(fakeDbSet);
var service = new RequestReadService(fakeContext);
var requests = service.GetAllRequests();
Assert.AreEqual(3, requests.Count);
Assert.AreEqual("Test1", requests[0].Name);
Assert.AreEqual("Test2", requests[1].Name);
Assert.AreEqual("Test3", requests[2].Name);