Question: Parallel integration tests
See original GitHub issueHello,
my app is a simple (ASP.NET Core) Web Api. I’m using the AuditApiAttribute
to decorate endpoints that should log audit events. This works totally fine and as expected.
Sadly I cannot test these logs in my integration/unit test due to the nature of Audit.NET: A singleton implementation. I tried to look into the implementation details of AuditApiAttribute
but I saw it uses simple constructor calls (new X()
) instead of dependency injection. I currently don’t see how I can replace the default audit scope creation on a per request/app basis.
Most of my integration/unit tests are run in parallel so the global data provider cannot be used. If I use it it is replaced in every test setup which causes the audit logs to go to any collection (it’s random basically). I do want my tests to be isolated and do not want all of them to write to a big collection.
I saw talks about this issue in the past (#315) but I’m not really sure how it was resolved. I don’t want to write my own api attribute if possible. I also do not want to use the middleware if possible because I want a whitelist approach. Not a blacklist approach 😃
Any ideas?
Issue Analytics
- State:
- Created 9 months ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
This fix was included in version 20.1.3, please upgrade your references and re-test
https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WebApi/README.md#output
Thank you! I think this a big quality improvement overall. Thanks for your work and response time 😃
My tests all turned green now. No more randomness 😄