Comments (8)
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
from audit.net.
@thepirat000 please look at my PR which is linked above your message (#559). It's basically your idea. But just for WebApi attributes. It works. The first commit adds a test for that which fails. The second one uses the DI container for injecting the provider and thus fixes the tests.
Feel free to give feedback. I'm willing to help your project :)
from audit.net.
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 :D
from audit.net.
If you are testing whether the audit for an action is generated, you could setup an in-memory data provider for your tests (just like you would do to test an Entity Framework context)
I guess you can act on an action method and test whether the audit logs were saved as expected or not.
// Arrange
Audit.Core.Configuration.Setup().UseInMemoryProvider();
// Act
CallControllerMethod();
// Assert
var events = (Audit.Core.Configuration.DataProvider as InMemoryDataProvider).GetAllEvents();
Assert.AreEqual(1, events.Count);
Also, the InMemoryDataProvider
is thread-safe so it should work fine with parallel tests
from audit.net.
This does not work as this just puts all messages in the same collection and I would have to pick my logs out of it. This is not good if u want to run isolated tests.
I set up a repo to reproduce this issue. Just run dotnet test
and you will get The collection was expected to contain a single element, but it contained 4 elements.
for all cases.
from audit.net.
This was most likely not noticed as NUnit does not run tests in parallel at all by default. However XUnit does this on a per class basis per default.
from audit.net.
I have an idea to allow injecting the AuditDataProvider
from the service collection for Audit.WebApi.
Of course, I need to test it and see if it is compatible with the other use cases, but if it is, you should be able to test it like this afterward:
// In your Program.cs:
builder.Services.AddSingleton<AuditDataProvider>(new InMemoryDataProvider());
// In your unit test, assert like this:
var dp = testApp.Services.GetRequiredService<AuditDataProvider>() as InMemoryDataProvider;
Assert.Single(dp.GetAllEvents());
So the AuditApi
attribute and the middleware will honor the AuditDataProvider from the service collection and use the static
configuration only if the data provider was not found in the registered services.
from audit.net.
Awesome, thanks!
Yes, the same idea. I'll also add it to the middleware and run some more tests.
from audit.net.
Related Issues (20)
- Override feature doesn't work. HOT 2
- EventEntry.EntityType is null HOT 2
- If EF Core configures different column name for a entity property , the corresponding value of audit property is null HOT 2
- EF Interceptor should not crash the workflow if something fails during audit HOT 5
- I need help with EF Core HOT 9
- UseElasticsearch entity update issue HOT 8
- Is there a UI code to show these logs? HOT 1
- ElasticSearch provider create json file in working directory HOT 8
- Migration doesn't create Audit_ tables HOT 4
- Support CancellationToken on all async methods HOT 3
- I get a missing method Exception when saving HOT 11
- Response content not capturing correctly when Exception Handlers is used HOT 1
- [AuditApi] - override middleware settings with controller attributes HOT 3
- Error on inserting Audit Data HOT 2
- EF Core value updates not audited HOT 3
- EF Core value updates are not audited HOT 13
- Custom field empty in Entries Array HOT 3
- Bump Microsoft.Bcl.AsyncInterfaces HOT 1
- Limited configuration of MongoDB provider HOT 1
- Related object causes multiple audit entries HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audit.net.