File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,24 @@ protected override void ConfigureDbContext(DbContextOptionsBuilder builder)
193193
194194This beahvior WILL drop your database after each test !
195195
196+ ### Cleaning the ChangeTracker
197+
198+ When running normally, dotnet web applications will use a different scoped
199+ instance of the DbContext for each HTTP request. The test library uses a
200+ singleton instance, otherwise it would not be possible to access the same
201+ instance from within the test context. As a consequence, any call to the
202+ DbContext during the arrange phase (including calls to the HttpClient) might
203+ clogger the Change Tracker with existing entities. In this situation the
204+ DbContext's ChangeTracker might not be empty when the system under test is
205+ called. This may in turn cause attaching entities to fail, whereas it would
206+ have worked in a real request.
207+
208+ The most common pattern for this is when arranging some entities in the
209+ database then calling an update entity operation.
210+
211+ In such case, the test writer should call ` Database.ChangeTracker.Clear() `
212+ at the end of the arrange phase.
213+
196214## OpenTelemetry integration
197215
198216The library provides specific support for otel. You can achieve this
You can’t perform that action at this time.
0 commit comments