test: create test for concurrency
This commit is contained in:
@@ -232,7 +232,20 @@ public class PatientService : IPatientService
|
||||
CreatedAt = DateTimeOffset.UtcNow
|
||||
});
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
try
|
||||
{
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
when (ex.InnerException is Npgsql.PostgresException { SqlState: "23505" } pg
|
||||
&& pg.ConstraintName == "ix_encounters_patient_active_type")
|
||||
{
|
||||
_db.ChangeTracker.Clear();
|
||||
throw new ConflictException(
|
||||
"Patient already has an active encounter of this type.",
|
||||
"DUPLICATE_ACTIVE_ENCOUNTER");
|
||||
}
|
||||
|
||||
return encounter;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user