I am trying to write a unit test of a repository implementation. The repository uses RavenDB as a database. For unit tests, I would like to make fun of parts of RavenDB. To create fakes, I use FakeItEasy. I figured there would be no taunting / falsification problems, as the RavenDB API is accessible through interfaces.
I have a problem while trying to instantiate a specific layout. The relevant parts of my unit test code are as follows:
[Fact] public void Test() { UserDocument doc = ...; IQueryable<UserDocument> where = A.Fake<IQueryable<UserDocument>>(); A.CallTo(() => where.First()).Returns(doc); IRavenQueryable<UserDocument> query = A.Fake<IRavenQueryable<UserDocument>>(); IDocumentSession session = A.Fake<IDocumentSession>(); A.CallTo(() => session.Query<UserDocument>()).Returns(query); IDocumentStore store = A.Fake<IDocumentStore>(); A.CallTo(() => store.OpenSession()).Returns(session); . . . }
When creating an instance of IRavenQueryable, I get an exception. This is the magazine from runner Xunit.net:
UnitTest.Test : FakeItEasy.Core.FakeCreationException : Failed to create fake of type "System.Linq.IQueryable`1[UserDocument]". Below is a list of reasons for failure per attempted constructor: No constructor arguments failed: No default constructor was found on the type System.Linq.IQueryable`1[UserDocument]. Stack Trace: vid FakeItEasy.Core.DefaultExceptionThrower.ThrowFailedToGenerateProxyWithResolvedConstructors(Type typeOfFake, String reasonForFailureOfUnspecifiedConstructor, IEnumerable`1 resolvedConstructors) vid FakeItEasy.Creation.FakeObjectCreator.TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, FakeOptions fakeOptions, IDummyValueCreationSession session, String failReasonForDefaultConstructor, Boolean throwOnFailure) vid FakeItEasy.Creation.FakeObjectCreator.CreateFake(Type typeOfFake, FakeOptions fakeOptions, IDummyValueCreationSession session, Boolean throwOnFailure) vid FakeItEasy.Creation.DefaultFakeAndDummyManager.CreateFake(Type typeOfFake, FakeOptions options) vid FakeItEasy.Creation.DefaultFakeCreatorFacade.CreateFake[T](Action`1 options)
A “constructor without a default constructor” makes no sense, because what I'm trying to fake is an interface. Does anyone have a suggestion what could be the problem?
David nordvall
source share