我正在读这个How to make Entity Framework Data Context Readonly,因为我有一个只使用SQL视图作为实体的只读上下文。是否可以伪造DbQuery
以便我可以测试我的其他逻辑? FakeItEasy返回这些错误:
var _fakeRequestList = A.Fake<DbQuery<RequestList>>(opt => opt
.Implements(typeof(IQueryable<RequestList>)));
Result Message:
Initialization method Test.QueryTests.Initialize threw exception. FakeItEasy.Core.FakeCreationException: FakeItEasy.Core.FakeCreationException:
Failed to create fake of type "System.Data.Entity.Infrastructure.DbQuery`1[DAL.QueryContext.Model.RequestList]".
Below is a list of reasons for failure per attempted constructor:
No constructor arguments failed:
No usable default constructor was found on the type System.Data.Entity.Infrastructure.DbQuery`1[DAL.QueryContext.Model.RequestList].
An exception was caught during this call. Its message was:
Parent does not have a default constructor. The default constructor must be explicitly defined.
The following constructors were not tried:
(*System.Data.Entity.Internal.Linq.IInternalQuery`1[DAL.QueryContext.Model.RequestList])
Types marked with * could not be resolved, register them in the current
IFakeObjectContainer to enable these constructors.
Result StackTrace:
at FakeItEasy.Core.DefaultExceptionThrower.ThrowFailedToGenerateProxyWithResolvedConstructors(Type typeOfFake, String reasonForFailureOfUnspecifiedConstructor, IEnumerable`1 resolvedConstructors)
at FakeItEasy.Creation.FakeObjectCreator.TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, FakeOptions fakeOptions, IDummyValueCreationSession session, String failReasonForDefaultConstructor, Boolean throwOnFailure)
at FakeItEasy.Creation.FakeObjectCreator.CreateFake(Type typeOfFake, FakeOptions fakeOptions, IDummyValueCreationSession session, Boolean throwOnFailure)
at FakeItEasy.Creation.DefaultFakeAndDummyManager.CreateFake(Type typeOfFake, FakeOptions options)
at FakeItEasy.Creation.DefaultFakeCreatorFacade.CreateFake[T](Action`1 options)
at FakeItEasy.A.Fake[T](Action`1 options)
at Test.QueryTests.Initialize() in c:\SourceCode\Portal\Main\Portal\UnitTest\QueryTests.cs:line 25