KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to write a unit test of a repository implementation. The repository uses RavenDB as a database. For the unit tests, I would like to mock the RavenDB parts. In order to create the mocks (fakes) I'm using FakeItEasy. I figured there wouldn't be any problems with the mocking/faking since the RavenDB API is accessed through interfaces. I do however have a problem when trying to instantiate a specific mock. The relevant parts of my unit test code looks like this: [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 instantiating the IRavenQueryable fake I get an exception. This is the log from the Xunit.net runner: 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)
Tags (comma-separated)
Save Edits
Cancel