-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange exceptions when using AutoMock w/ AddDbContext #49
Comments
@cyungmann I suspect there's some static internal logging state, that gets properly initialized in the working case (because container is actually built, including logger), so by the time it gets to the not working scenario - it now works. But running in reverse will throw because container is not built. EDIT: this assumption might be wrong, i overlooked the fact that automock is instantiated from a container, which is probably being built. But again, the fact that order matters tells me there's some static factory isn't getting initialized in a second case |
The difference i see is in Automock's case - LoggerFactory is created with CastleProxy provider that eventually leads to null logger instance. In regular working case - LoggerFactory is created without any providers (collection is empty). EDIT:
you'll get same issue. It's possible this registration source has a bug for your case |
Describe the Bug
Get exceptions when using
AutoMock
w/AddDbContext
upon trying to resolve theDbContext
class.Steps to Reproduce
Download and run AutoMockTest.zip
If you switch the order of calling
WorksAsync
andDoesNotWorkAsync
in Program.cs so thatWorksAsync
comes first, things suddenly and unexpectedly start working for both methods. If you only callWorksAsync
things also work.Program.cs
WidgetContext.cs
Widget.cs
AutoMockTest.csproj
Expected Behavior
No exceptions should be thrown.
Exception with Stack Trace
For some reason
Exception.StackTrace
only has the following short stacktrace:Here is a more complete callstack:
Dependency Versions
Autofac: 8.1.0
Autofac.Extras.Moq: 6.1.1
Autofac.Extensions.DependencyInjection: 10.0.0
Microsoft.EntityFrameworkCore.Sqlite: 8.0.8
Microsoft.Extensions.Logging: 8.0.0
Additional Info
The fact that things work when not using AutoMock suggests to me that the problem is in AutoMock somehow. It's also completely possible that I'm doing something wrong.
The text was updated successfully, but these errors were encountered: