rama creada apartir de master en j

This commit is contained in:
jrojas
2026-06-26 10:29:23 +02:00
parent 319fd3dfb0
commit c1517fda87
2810 changed files with 1927392 additions and 25392 deletions
@@ -12,47 +12,50 @@ namespace adas_core.Test.Repositories;
[Category("Integration")]
public class DiagnosisRepositoryTest
{
/// <summary>
/// One-time test setup that prepares the integration database for patient diagnosis tests by dropping and recreating the diagnoses collection, inserting three sample <see cref="PatientDiagnosis"/> records (one with predefined test identifiers and two with auto-generated identifiers), and initializing the <see cref="DiagnosisRepository"/> under test.
/// </summary>
[OneTimeSetUp]
public async Task Init()
{
_optionsApiSettings = Options.Create(_apiSettings);
var patientDiagnosis1 = new PatientDiagnosis
public async Task Init()
{
Id = Id,
PatientId = PatientId,
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
var patientDiagnosis2 = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code2",
DiagnosisSystem = "diagnosisSystem"
};
var patientDiagnosis3 = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code3",
DiagnosisSystem = "diagnosisSystem"
};
await IntegrationDb.Database.DropCollectionAsync("patients_diagnosis");
await IntegrationDb.Database.CreateCollectionAsync("patients_diagnosis");
_repository = new DiagnosisRepository(_optionsApiSettings, IntegrationDb.Database);
await _repository.InsertOneAsync(patientDiagnosis1);
await _repository.InsertOneAsync(patientDiagnosis2);
await _repository.InsertOneAsync(patientDiagnosis3);
}
_optionsApiSettings = Options.Create(_apiSettings);
var patientDiagnosis1 = new PatientDiagnosis
{
Id = Id,
PatientId = PatientId,
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
var patientDiagnosis2 = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code2",
DiagnosisSystem = "diagnosisSystem"
};
var patientDiagnosis3 = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code3",
DiagnosisSystem = "diagnosisSystem"
};
await IntegrationDb.Database.DropCollectionAsync("patients_diagnosis");
await IntegrationDb.Database.CreateCollectionAsync("patients_diagnosis");
_repository = new DiagnosisRepository(_optionsApiSettings, IntegrationDb.Database);
await _repository.InsertOneAsync(patientDiagnosis1);
await _repository.InsertOneAsync(patientDiagnosis2);
await _repository.InsertOneAsync(patientDiagnosis3);
}
private DiagnosisRepository _repository;
@@ -68,130 +71,162 @@ public class DiagnosisRepositoryTest
private static readonly ObjectId Id = ObjectId.GenerateNewId();
/// <summary>
/// Verifies that the repository returns a non-null and non-empty collection when retrieving records for an existing patient.
/// </summary>
[Test]
public async Task GetByPatient_Find_Patient_Return_List()
{
var result = await _repository.GetByPatient(PatientId);
Assert.That(result, Is.Not.Null);
Assert.That(result, Is.Not.Empty);
}
[Test]
public async Task GetByPatient_not_Find_Patient_Return_Empty_List()
{
var result = await _repository.GetByPatient(ObjectId.GenerateNewId());
Assert.That(result, Is.Not.Null);
Assert.That(result, Is.Empty);
}
[Test]
public async Task FindByPatientIdAndCode_Find_Patient_Return_Diagnois()
{
var result = await _repository.FindByPatientIdAndCode(PatientId, "code1", "diagnosisSystem");
Assert.That(result, Is.Not.Null);
}
[Test]
public async Task FindByPatientIdAndCode_not_Find_Patient_Return_null()
{
var result = await _repository.FindByPatientIdAndCode(ObjectId.GenerateNewId(), "code4", "diagnosisSystem");
Assert.That(result, Is.Null);
}
[Test]
public async Task FindByPatientIdAsync_Find_Patient_Return_List()
{
var result = await _repository.FindByPatientIdAsync(PatientId);
Assert.That(result, Is.Not.Null);
Assert.That(result.ToList(), Is.Not.Empty);
}
[Test]
public async Task FindByPatientIdAsync_not_Find_Patient_Return_Empty_List()
{
var result = await _repository.FindByPatientIdAsync(ObjectId.GenerateNewId());
Assert.That(result, Is.Not.Null);
Assert.That(result.ToList(), Is.Empty);
}
[Test]
public async Task DeleteAsync_Find_id()
{
var patientDiagnosis = new PatientDiagnosis
public async Task GetByPatient_Find_Patient_Return_List()
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
await _repository.InsertOneAsync(patientDiagnosis);
var result = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(result.ToList(), Has.Count.EqualTo(1));
await _repository.DeleteAsync(patientDiagnosis.Id);
var resultDelete = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(resultDelete.ToList(), Is.Empty);
}
var result = await _repository.GetByPatient(PatientId);
Assert.That(result, Is.Not.Null);
Assert.That(result, Is.Not.Empty);
}
/// <summary>
/// Verifies that <see cref="DiagnosisRepository.GetByPatient"/> returns an empty list when no records are found for the specified patient identifier.
/// </summary>
[Test]
public async Task DeleteByPatientId_Find_patientId()
{
var patientDiagnosis = new PatientDiagnosis
public async Task GetByPatient_not_Find_Patient_Return_Empty_List()
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
await _repository.InsertOneAsync(patientDiagnosis);
var result = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(result.ToList(), Has.Count.EqualTo(1));
await _repository.DeleteByPatientId(patientDiagnosis.PatientId);
var resultDelete = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(resultDelete.ToList(), Is.Empty);
}
var result = await _repository.GetByPatient(ObjectId.GenerateNewId());
Assert.That(result, Is.Not.Null);
Assert.That(result, Is.Empty);
}
/// <summary>
/// Verifies that <see cref="DiagnosisRepository.FindByPatientIdAndCode"/> successfully retrieves a diagnosis for an existing patient using the provided patient identifier, diagnosis code, and diagnosis system.
/// </summary>
/// <returns>A task that represents the asynchronous test execution.</returns>
[Test]
public async Task UpdateManyObjectId_With_base_UpdateManyObjectIdAsync()
{
var patientDiagnosis = new PatientDiagnosis
public async Task FindByPatientIdAndCode_Find_Patient_Return_Diagnois()
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
var result = await _repository.FindByPatientIdAndCode(PatientId, "code1", "diagnosisSystem");
Assert.That(result, Is.Not.Null);
}
await _repository.InsertOneAsync(patientDiagnosis);
/// <summary>
/// Verifies that <see cref="DiagnosisRepository.FindByPatientIdAndCode"/> returns <c>null</c> when no patient is found
/// for the provided patient identifier, code, and diagnosis system.
/// </summary>
[Test]
public async Task FindByPatientIdAndCode_not_Find_Patient_Return_null()
{
var result = await _repository.FindByPatientIdAndCode(ObjectId.GenerateNewId(), "code4", "diagnosisSystem");
Assert.That(result, Is.Null);
}
var resultInsert = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
/// <summary>
/// Verifies that <see cref="DiagnosisRepository.FindByPatientIdAsync"/> returns a non-null, non-empty list when looking up an existing patient by their identifier.
/// </summary>
[Test]
public async Task FindByPatientIdAsync_Find_Patient_Return_List()
{
var result = await _repository.FindByPatientIdAsync(PatientId);
Assert.That(result, Is.Not.Null);
Assert.That(result.ToList(), Is.Not.Empty);
}
var resultList = resultInsert.ToList();
/// <summary>
/// Verifies that <c>FindByPatientIdAsync</c> returns a non-null empty list when no patient matches the provided patient ID.
/// </summary>
[Test]
public async Task FindByPatientIdAsync_not_Find_Patient_Return_Empty_List()
{
var result = await _repository.FindByPatientIdAsync(ObjectId.GenerateNewId());
Assert.That(result, Is.Not.Null);
Assert.That(result.ToList(), Is.Empty);
}
Assert.That(resultList, Has.Count.EqualTo(1));
/// <summary>
/// Verifies that <c>DeleteAsync</c> removes a patient diagnosis record by its identifier: after insertion, the record is retrievable by patient id, and once deleted, the search by patient id returns no results.
/// </summary>
[Test]
public async Task DeleteAsync_Find_id()
{
var patientDiagnosis = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
await _repository.InsertOneAsync(patientDiagnosis);
var result = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(result.ToList(), Has.Count.EqualTo(1));
await _repository.DeleteAsync(patientDiagnosis.Id);
var resultDelete = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(resultDelete.ToList(), Is.Empty);
}
var newPatientId = ObjectId.GenerateNewId();
/// <summary>
/// Verifies that <c>DeleteByPatientId</c> removes all diagnoses associated with the specified patient
/// by inserting a diagnosis, confirming it can be found, deleting it by patient id, and then
/// asserting that no diagnoses remain for that patient.
/// </summary>
[Test]
public async Task DeleteByPatientId_Find_patientId()
{
var patientDiagnosis = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
await _repository.InsertOneAsync(patientDiagnosis);
var result = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(result.ToList(), Has.Count.EqualTo(1));
await _repository.DeleteByPatientId(patientDiagnosis.PatientId);
var resultDelete = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
Assert.That(resultDelete.ToList(), Is.Empty);
}
await _repository.UpdateManyObjectId("patientId", newPatientId, patientDiagnosis.PatientId);
var resultUpdate = await _repository.FindByPatientIdAsync(newPatientId);
Assert.That(resultUpdate, Is.Not.Null);
Assert.That(resultUpdate.ToList().Count(f => f.PatientId == newPatientId), Is.EqualTo(1));
}
/// <summary>
/// Tests that <c>UpdateManyObjectId</c> correctly updates the <c>PatientId</c> field across all matching <see cref="PatientDiagnosis"/> documents by replacing the original ObjectId with a new one.
/// Verifies that after the update, the document can be retrieved using the new patient identifier.
/// </summary>
[Test]
public async Task UpdateManyObjectId_With_base_UpdateManyObjectIdAsync()
{
var patientDiagnosis = new PatientDiagnosis
{
Id = ObjectId.GenerateNewId(),
PatientId = ObjectId.GenerateNewId(),
Time = Now,
Code = "code1",
DiagnosisSystem = "diagnosisSystem"
};
await _repository.InsertOneAsync(patientDiagnosis);
var resultInsert = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
var resultList = resultInsert.ToList();
Assert.That(resultList, Has.Count.EqualTo(1));
var newPatientId = ObjectId.GenerateNewId();
await _repository.UpdateManyObjectId("patientId", newPatientId, patientDiagnosis.PatientId);
var resultUpdate = await _repository.FindByPatientIdAsync(newPatientId);
Assert.That(resultUpdate, Is.Not.Null);
Assert.That(resultUpdate.ToList().Count(f => f.PatientId == newPatientId), Is.EqualTo(1));
}
}