I had understood that the private method was part of your system under test, and therefore not on a Fake. If it's on a class that's the base type of a Fake, I'm afraid you cannot configure the method. As noted in What can be faked, only certain methods can be configured.
How is your method creating the "property as faked automatically"? Without seeing some code, and ideally your failures, I'm really working blind here, and don't think I'm going to be able to help you.
Hey all, trying to mock a call to a dbcontext (need a .Count to return 0/1) and seem to be getting this error:
The DbContextOptions passed to the AppContextContextProxy constructor must be a DbContextOptions<AppContextContextProxy>.
And in my code I'm faking it like:
var fakeDbContext = A.Fake<AppContext>();
Just wondering what the correct way around this is? (I can't seem to find any docs in such a scenario)
Yeah, this is for EF. I have a feeling I may need to create a service to put the context inside of and then fake the service instead, though reading a blog post online it appears the author did manage to get it working and basically looks the same as mine
The stack trace is the following:
Failed to create fake of type Project_API.Data.App_PortalContext:
Below is a list of reasons for failure per attempted constructor: Constructor with signature (Microsoft.EntityFrameworkCore.DbContextOptions`1[Project_API.Data.App_PortalContext]) failed: No constructor matches the passed arguments for constructor. An exception of type System.InvalidOperationException was caught during this call. Its message was: The DbContextOptions passed to the App_PortalContextProxy constructor must be a DbContextOptions<App_PortalContextProxy>. When registering multiple DbContext types, make sure that the constructor for each context type has a DbContextOptions<TContext> parameter rather than a non-generic DbContextOptions parameter. at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options) at Project_API.Data.App_PortalContext..ctor(DbContextOptions`1 options) in C:\Users\\source\repos\Project-API\\Data\App_PortalContext.cs:line 14 at Castle.Proxies.App_PortalContextProxy..ctor(IInterceptor , DbContextOptions`1 options)
FailedCreationResult.get_Result() line 82
FakeAndDummyManager.CreateFake(Type typeOfFake, Action`1 optionsBuilder, LoopDetectingResolutionContext resolutionContext) line 42
FakeAndDummyManager.CreateFake(Type typeOfFake, LoopDetectingResolutionContext resolutionContext) line 28
A.FakeT line 31
UnitTest1.ProcessObjectTest() line 54
I think you just expanded our scope. Was there a DI mentioned before? I think we can ignore that for now.
Let's assume that real empty options are fine. Can you try using them? Something like
A.Fake<App_PortalContext>(options => options.WithArgumentsForConstructor(new DbContextOptions<App_PortalContext>()))