rama creada apartir de master en j
This commit is contained in:
@@ -14,26 +14,30 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class AdmissionRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the integration test environment by resetting the admissions collection
|
||||
/// and seeding it with valid admission records to be used across the test fixture.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("admissions");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("admissions");
|
||||
|
||||
_repository = new AdmissionRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
var admissions = new List<Admission>
|
||||
public async Task Init()
|
||||
{
|
||||
TestUtilities.CreateValidAdmission(),
|
||||
TestUtilities.CreateValidAdmission(),
|
||||
TestUtilities.CreateValidAdmission()
|
||||
};
|
||||
|
||||
foreach (var admission in admissions) await _repository.InsertOneAsync(admission);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("admissions");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("admissions");
|
||||
|
||||
_repository = new AdmissionRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
var admissions = new List<Admission>
|
||||
{
|
||||
TestUtilities.CreateValidAdmission(),
|
||||
TestUtilities.CreateValidAdmission(),
|
||||
TestUtilities.CreateValidAdmission()
|
||||
};
|
||||
|
||||
foreach (var admission in admissions) await _repository.InsertOneAsync(admission);
|
||||
}
|
||||
|
||||
private AdmissionRepository _repository;
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
@@ -43,172 +47,206 @@ public class AdmissionRepositoryTest
|
||||
Admissions = "admissions"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository.InsertOneAsync"/> successfully persists a valid admission so that it can subsequently be retrieved by its identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOneAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
|
||||
// Act
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(admission.Id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(admission.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Delete_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
await _repository.Delete(admission.Id);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(admission.Id);
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Modify the admission
|
||||
admission.DiagnosisAux = "Updated value";
|
||||
|
||||
// Act
|
||||
await _repository.Update(admission);
|
||||
|
||||
// Assert
|
||||
var updatedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(updatedAdmission, Is.Not.Null);
|
||||
Assert.That(updatedAdmission?.DiagnosisAux, Is.EqualTo(admission.DiagnosisAux));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateLocation_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
var originalLocationId = ObjectId.GenerateNewId();
|
||||
var newLocationId = ObjectId.GenerateNewId();
|
||||
|
||||
admission.PointOfCareId = originalLocationId;
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
await _repository.UpdateLocation(admission.Id, newLocationId);
|
||||
|
||||
// Assert
|
||||
var updatedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(updatedAdmission, Is.Not.Null);
|
||||
Assert.That(newLocationId, Is.EqualTo(updatedAdmission?.PointOfCareId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdatePatient_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
var newPatient = new Person
|
||||
public async Task InsertOneAsync_Success()
|
||||
{
|
||||
LastName = "Doe",
|
||||
FirstName = "John",
|
||||
BirthDate = new DateTime(1990, 1, 1),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
await _repository.UpdatePatient(admission.Id, newPatient);
|
||||
|
||||
// Assert
|
||||
var updatedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(updatedAdmission, Is.Not.Null);
|
||||
Assert.That(updatedAdmission?.Person, Is.Not.Null);
|
||||
Assert.That(updatedAdmission?.Person?.FirstName, Is.EqualTo(newPatient.FirstName));
|
||||
}
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
|
||||
// Act
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(admission.Id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(admission.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository successfully deletes an admission record, ensuring that the deleted admission can no longer be retrieved by its identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAll_Success()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
// Assert
|
||||
var admissions = result as Admission[] ?? result.ToArray();
|
||||
Assert.That(admissions, Is.Not.Null);
|
||||
Assert.That(admissions, Is.Not.Empty);
|
||||
Assert.That(admissions.Count(), Is.EqualTo(3));
|
||||
}
|
||||
public async Task Delete_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
await _repository.Delete(admission.Id);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(admission.Id);
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="Admission"/> updates are persisted successfully by inserting an admission, modifying one of its fields, and asserting that the updated value is retrieved.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(admission.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(admission.Id, Is.EqualTo(result?.Id));
|
||||
}
|
||||
public async Task Update_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Modify the admission
|
||||
admission.DiagnosisAux = "Updated value";
|
||||
|
||||
// Act
|
||||
await _repository.Update(admission);
|
||||
|
||||
// Assert
|
||||
var updatedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(updatedAdmission, Is.Not.Null);
|
||||
Assert.That(updatedAdmission?.DiagnosisAux, Is.EqualTo(admission.DiagnosisAux));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository.UpdateLocation"/> successfully updates the
|
||||
/// <c>PointOfCareId</c> of an existing admission to the specified new location identifier
|
||||
/// and that the change is persisted in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistingId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(nonExistingId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task UpdateLocation_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
var originalLocationId = ObjectId.GenerateNewId();
|
||||
var newLocationId = ObjectId.GenerateNewId();
|
||||
|
||||
admission.PointOfCareId = originalLocationId;
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
await _repository.UpdateLocation(admission.Id, newLocationId);
|
||||
|
||||
// Assert
|
||||
var updatedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(updatedAdmission, Is.Not.Null);
|
||||
Assert.That(newLocationId, Is.EqualTo(updatedAdmission?.PointOfCareId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository successfully updates the patient information of an existing admission,
|
||||
/// ensuring the updated admission can be retrieved and reflects the new patient's details.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByNhc_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByNhc(admission.Nhc);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(admission.Nhc, Is.EqualTo(result?.Nhc));
|
||||
}
|
||||
public async Task UpdatePatient_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
var newPatient = new Person
|
||||
{
|
||||
LastName = "Doe",
|
||||
FirstName = "John",
|
||||
BirthDate = new DateTime(1990, 1, 1),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
await _repository.UpdatePatient(admission.Id, newPatient);
|
||||
|
||||
// Assert
|
||||
var updatedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(updatedAdmission, Is.Not.Null);
|
||||
Assert.That(updatedAdmission?.Person, Is.Not.Null);
|
||||
Assert.That(updatedAdmission?.Person?.FirstName, Is.EqualTo(newPatient.FirstName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindAll operation successfully retrieves all admissions, returning a non-empty collection of exactly three records.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByNhc_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistingNhc = "non-existing-nhc";
|
||||
public async Task FindAll_Success()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
// Assert
|
||||
var admissions = result as Admission[] ?? result.ToArray();
|
||||
Assert.That(admissions, Is.Not.Null);
|
||||
Assert.That(admissions, Is.Not.Empty);
|
||||
Assert.That(admissions.Count(), Is.EqualTo(3));
|
||||
}
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByNhc(nonExistingNhc);
|
||||
/// <summary>
|
||||
/// Verifies that the repository successfully retrieves an admission by its unique identifier after it has been inserted.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(admission.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(admission.Id, Is.EqualTo(result?.Id));
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindById</c> method returns <c>null</c> when queried with a non-existing identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistingId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(nonExistingId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository.FindByNhc"/> successfully retrieves an admission record from the repository using its NHC identifier.
|
||||
/// Confirms that the returned record is not null and that the NHC of the retrieved admission matches the one used in the lookup.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByNhc_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
await _repository.InsertOneAsync(admission);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByNhc(admission.Nhc);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(admission.Nhc, Is.EqualTo(result?.Nhc));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository"/>.<c>FindByNhc</c> returns <c>null</c> when the provided NHC does not exist in the data source.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByNhc_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistingNhc = "non-existing-nhc";
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByNhc(nonExistingNhc);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task FindByLocation_Success()
|
||||
@@ -271,120 +309,142 @@ public class AdmissionRepositoryTest
|
||||
// Assert.That(resultList?.Count(), Is.EqualTo(2));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that inserting a valid admission through the repository returns the same admission and persists it so it can be retrieved by its identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOneAsyncAndReturn_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
|
||||
// Act
|
||||
var result = await _repository.InsertOneAsyncAndReturn(admission);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.EqualTo(admission));
|
||||
var retrievedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(retrievedAdmission, Is.Not.Null);
|
||||
Assert.That(retrievedAdmission?.Id, Is.EqualTo(admission.Id));
|
||||
}
|
||||
public async Task InsertOneAsyncAndReturn_Success()
|
||||
{
|
||||
// Arrange
|
||||
var admission = TestUtilities.CreateValidAdmission();
|
||||
|
||||
// Act
|
||||
var result = await _repository.InsertOneAsyncAndReturn(admission);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.EqualTo(admission));
|
||||
var retrievedAdmission = await _repository.FindById(admission.Id);
|
||||
Assert.That(retrievedAdmission, Is.Not.Null);
|
||||
Assert.That(retrievedAdmission?.Id, Is.EqualTo(admission.Id));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the repository's <c>GetAdmissionByUnitIdWithOutPoC</c> method returns only the admissions matching the specified unit identifier
|
||||
/// while excluding admissions that have an associated point-of-care identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAdmissionByUnitIdWithOutPoC_Success()
|
||||
{
|
||||
// Arrange
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
var admission1 = TestUtilities.CreateValidAdmission();
|
||||
admission1.UnitId = unitId;
|
||||
admission1.PointOfCareId = null;
|
||||
|
||||
var admission2 = TestUtilities.CreateValidAdmission();
|
||||
admission2.UnitId = ObjectId.GenerateNewId();
|
||||
admission2.PointOfCareId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.InsertOneAsync(admission1);
|
||||
await _repository.InsertOneAsync(admission2);
|
||||
|
||||
// Act
|
||||
var result = await _repository.GetAdmissionByUnitIdWithOutPoC(unitId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(1));
|
||||
Assert.That(result[0].UnitId, Is.EqualTo(unitId));
|
||||
Assert.That(result[0].PointOfCareId, Is.Null);
|
||||
}
|
||||
public async Task GetAdmissionByUnitIdWithOutPoC_Success()
|
||||
{
|
||||
// Arrange
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
var admission1 = TestUtilities.CreateValidAdmission();
|
||||
admission1.UnitId = unitId;
|
||||
admission1.PointOfCareId = null;
|
||||
|
||||
var admission2 = TestUtilities.CreateValidAdmission();
|
||||
admission2.UnitId = ObjectId.GenerateNewId();
|
||||
admission2.PointOfCareId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.InsertOneAsync(admission1);
|
||||
await _repository.InsertOneAsync(admission2);
|
||||
|
||||
// Act
|
||||
var result = await _repository.GetAdmissionByUnitIdWithOutPoC(unitId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(1));
|
||||
Assert.That(result[0].UnitId, Is.EqualTo(unitId));
|
||||
Assert.That(result[0].PointOfCareId, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetAdmissionByUnitIdWithOutPoC</c> returns an empty result set (instead of null) when no admissions match the provided unit identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAdmissionByUnitIdWithOutPoC_NoMatch()
|
||||
{
|
||||
// Arrange
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act
|
||||
var result = await _repository.GetAdmissionByUnitIdWithOutPoC(unitId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
public async Task GetAdmissionByUnitIdWithOutPoC_NoMatch()
|
||||
{
|
||||
// Arrange
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act
|
||||
var result = await _repository.GetAdmissionByUnitIdWithOutPoC(unitId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindByPointOfCareId</c> method successfully retrieves the admission matching the specified point of care identifier, returning a single result and excluding admissions associated with different point of care identifiers.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPointOfCareId_Success()
|
||||
{
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
var admission1 = TestUtilities.CreateValidAdmission();
|
||||
admission1.PointOfCareId = pocId;
|
||||
|
||||
var admission2 = TestUtilities.CreateValidAdmission();
|
||||
admission2.PointOfCareId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.InsertOneAsync(admission1);
|
||||
await _repository.InsertOneAsync(admission2);
|
||||
|
||||
var result = await _repository.FindByPointOfCareId(pocId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(1));
|
||||
Assert.That(result[0].PointOfCareId, Is.EqualTo(pocId));
|
||||
}
|
||||
public async Task FindByPointOfCareId_Success()
|
||||
{
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
var admission1 = TestUtilities.CreateValidAdmission();
|
||||
admission1.PointOfCareId = pocId;
|
||||
|
||||
var admission2 = TestUtilities.CreateValidAdmission();
|
||||
admission2.PointOfCareId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.InsertOneAsync(admission1);
|
||||
await _repository.InsertOneAsync(admission2);
|
||||
|
||||
var result = await _repository.FindByPointOfCareId(pocId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(1));
|
||||
Assert.That(result[0].PointOfCareId, Is.EqualTo(pocId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository"/>.FindByPointOfCareId returns a non-null empty collection when no point of care matches the provided identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPointOfCareId_NoMatch()
|
||||
{
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
|
||||
var result = await _repository.FindByPointOfCareId(pocId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
public async Task FindByPointOfCareId_NoMatch()
|
||||
{
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
|
||||
var result = await _repository.FindByPointOfCareId(pocId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository"/>.<c>FindByDiagnosis</c> successfully returns a non-null result when retrieving admissions matching the specified diagnosis value.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDiagnosis_Success()
|
||||
{
|
||||
var diagnosis = "SomeDiagnosis";
|
||||
var admission1 = TestUtilities.CreateValidAdmission();
|
||||
admission1.Diagnosis = TestUtilities.CreateValidOptionList();
|
||||
|
||||
var admission2 = TestUtilities.CreateValidAdmission();
|
||||
admission2.Diagnosis = TestUtilities.CreateValidOptionList();
|
||||
|
||||
await _repository.InsertOneAsync(admission1);
|
||||
await _repository.InsertOneAsync(admission2);
|
||||
|
||||
var result = await _repository.FindByDiagnosis(diagnosis);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
public async Task FindByDiagnosis_Success()
|
||||
{
|
||||
var diagnosis = "SomeDiagnosis";
|
||||
var admission1 = TestUtilities.CreateValidAdmission();
|
||||
admission1.Diagnosis = TestUtilities.CreateValidOptionList();
|
||||
|
||||
var admission2 = TestUtilities.CreateValidAdmission();
|
||||
admission2.Diagnosis = TestUtilities.CreateValidOptionList();
|
||||
|
||||
await _repository.InsertOneAsync(admission1);
|
||||
await _repository.InsertOneAsync(admission2);
|
||||
|
||||
var result = await _repository.FindByDiagnosis(diagnosis);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AdmissionRepository"/>.<c>FindByDiagnosis</c> returns an empty collection when no entity matches the provided diagnosis.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDiagnosis_NoMatch()
|
||||
{
|
||||
var diagnosis = "NonExistentDiagnosis";
|
||||
|
||||
var result = await _repository.FindByDiagnosis(diagnosis);
|
||||
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
public async Task FindByDiagnosis_NoMatch()
|
||||
{
|
||||
var diagnosis = "NonExistentDiagnosis";
|
||||
|
||||
var result = await _repository.FindByDiagnosis(diagnosis);
|
||||
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
}
|
||||
@@ -15,46 +15,51 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class AlarmRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time test setup that initializes the alarm repository with two sample
|
||||
/// <see cref="PatientObservationAlarm"/> records by resetting the target
|
||||
/// collection and inserting the test data for use across the test fixture.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
|
||||
var pObsAlarm1 = new PatientObservationAlarm
|
||||
public async Task Init()
|
||||
{
|
||||
Id = Id,
|
||||
PatientId = PatientId,
|
||||
Code = "code1",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name1",
|
||||
Time = Now,
|
||||
Value = "value1",
|
||||
SystemId = "systemId1"
|
||||
};
|
||||
|
||||
var pObsAlarm2 = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code2",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name2",
|
||||
Time = Now,
|
||||
Value = "value2",
|
||||
SystemId = "systemId2"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_alarms");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_alarms");
|
||||
|
||||
_logger = new Mock<ILogger<AlarmRepository>>();
|
||||
|
||||
_repository = new AlarmRepository(_optionsApiSettings, IntegrationDb.Database, _logger.Object);
|
||||
|
||||
await _repository.InsertOneAsync(pObsAlarm1);
|
||||
await _repository.InsertOneAsync(pObsAlarm2);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
|
||||
var pObsAlarm1 = new PatientObservationAlarm
|
||||
{
|
||||
Id = Id,
|
||||
PatientId = PatientId,
|
||||
Code = "code1",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name1",
|
||||
Time = Now,
|
||||
Value = "value1",
|
||||
SystemId = "systemId1"
|
||||
};
|
||||
|
||||
var pObsAlarm2 = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code2",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name2",
|
||||
Time = Now,
|
||||
Value = "value2",
|
||||
SystemId = "systemId2"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_alarms");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_alarms");
|
||||
|
||||
_logger = new Mock<ILogger<AlarmRepository>>();
|
||||
|
||||
_repository = new AlarmRepository(_optionsApiSettings, IntegrationDb.Database, _logger.Object);
|
||||
|
||||
await _repository.InsertOneAsync(pObsAlarm1);
|
||||
await _repository.InsertOneAsync(pObsAlarm2);
|
||||
}
|
||||
|
||||
private AlarmRepository _repository;
|
||||
|
||||
@@ -70,164 +75,184 @@ public class AlarmRepositoryTest
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
private static readonly ObjectId Id = ObjectId.GenerateNewId();
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AlarmRepository.AggregatedPatientLastObservationsByField"/> returns an empty list when no observations match the provided field filter criteria.
|
||||
/// </summary>
|
||||
/// <param name="filter">The collection of <see cref="Field"/> objects used to filter observations; contains a single non-existent field to ensure no matches are found.</param>
|
||||
/// <returns>A task that completes after asserting the repository returns a non-null but empty result.</returns>
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_Not_Found_Returns_Empty_List()
|
||||
{
|
||||
var filter = new List<Field>
|
||||
public async Task AggregatedPatientLastObservationsByField_Not_Found_Returns_Empty_List()
|
||||
{
|
||||
new()
|
||||
var filter = new List<Field>
|
||||
{
|
||||
Name = "name100",
|
||||
Last = 2,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
new()
|
||||
{
|
||||
Name = "name100",
|
||||
Last = 2,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that AggregatedPatientLastObservationsByField returns exactly one aggregated result when matching last observations are found for the specified patient and field filter.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_Found_Returns_1()
|
||||
{
|
||||
var filter = new List<Field>
|
||||
public async Task AggregatedPatientLastObservationsByField_Found_Returns_1()
|
||||
{
|
||||
new()
|
||||
var filter = new List<Field>
|
||||
{
|
||||
Name = "name1",
|
||||
Last = 2,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
new()
|
||||
{
|
||||
Name = "name1",
|
||||
Last = 2,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AlarmRepository.AggregatedPatientLastObservationsByField"/> returns a non-null collection containing an entry for each matching field in the filter when observations are found for the given patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_Found_Returns_2()
|
||||
{
|
||||
var filter = new List<Field>
|
||||
public async Task AggregatedPatientLastObservationsByField_Found_Returns_2()
|
||||
{
|
||||
new()
|
||||
var filter = new List<Field>
|
||||
{
|
||||
Name = "name1",
|
||||
Last = 1,
|
||||
OnlyExpired = false
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "name2",
|
||||
Last = 1,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(2));
|
||||
}
|
||||
new()
|
||||
{
|
||||
Name = "name1",
|
||||
Last = 1,
|
||||
OnlyExpired = false
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "name2",
|
||||
Last = 1,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns an empty list when querying aggregated patient last observations by field with a filter that specifies OnlyExpired as true, and the matching patient observation alarm is expired.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_AllExpired_Returns_Empty_List()
|
||||
{
|
||||
var expiredTime = Now.AddDays(-1); // Set a time in the past to simulate expiration
|
||||
|
||||
var expiredObs = new PatientObservationAlarm
|
||||
public async Task AggregatedPatientLastObservationsByField_AllExpired_Returns_Empty_List()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code3",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name3",
|
||||
Time = expiredTime,
|
||||
Value = "value3",
|
||||
SystemId = "systemId3",
|
||||
Expired = true
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(expiredObs);
|
||||
|
||||
var filter = new List<Field>
|
||||
{
|
||||
new()
|
||||
var expiredTime = Now.AddDays(-1); // Set a time in the past to simulate expiration
|
||||
|
||||
var expiredObs = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code3",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name3",
|
||||
Last = 2,
|
||||
OnlyExpired = true
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_MultipleObservations_Returns_Most_Recent()
|
||||
{
|
||||
var oldTime = Now.AddMinutes(-10); // Set an older time
|
||||
|
||||
var oldObs = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code4",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name4",
|
||||
Time = oldTime,
|
||||
Value = "value4",
|
||||
SystemId = "systemId4"
|
||||
};
|
||||
|
||||
var newObs = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code4",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name4",
|
||||
Time = Now,
|
||||
Value = "value5",
|
||||
SystemId = "systemId5"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(oldObs);
|
||||
await _repository.InsertOneAsync(newObs);
|
||||
|
||||
var filter = new List<Field>
|
||||
{
|
||||
new()
|
||||
Time = expiredTime,
|
||||
Value = "value3",
|
||||
SystemId = "systemId3",
|
||||
Expired = true
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(expiredObs);
|
||||
|
||||
var filter = new List<Field>
|
||||
{
|
||||
Name = "name4",
|
||||
Last = 1,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
|
||||
Assert.That(result, Has.Count.EqualTo(1));
|
||||
Assert.That(result.First().Value, Is.EqualTo("value5")); // Ensure the most recent observation is returned
|
||||
};
|
||||
}
|
||||
new()
|
||||
{
|
||||
Name = "name3",
|
||||
Last = 2,
|
||||
OnlyExpired = true
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that when multiple observations exist for the same field, the aggregation returns only the most recent observation based on the timestamp.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_FilterObservations_Null_Returns_All()
|
||||
{
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId);
|
||||
public async Task AggregatedPatientLastObservationsByField_MultipleObservations_Returns_Most_Recent()
|
||||
{
|
||||
var oldTime = Now.AddMinutes(-10); // Set an older time
|
||||
|
||||
var oldObs = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code4",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name4",
|
||||
Time = oldTime,
|
||||
Value = "value4",
|
||||
SystemId = "systemId4"
|
||||
};
|
||||
|
||||
var newObs = new PatientObservationAlarm
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Code = "code4",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name4",
|
||||
Time = Now,
|
||||
Value = "value5",
|
||||
SystemId = "systemId5"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(oldObs);
|
||||
await _repository.InsertOneAsync(newObs);
|
||||
|
||||
var filter = new List<Field>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "name4",
|
||||
Last = 1,
|
||||
OnlyExpired = false
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId, filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
|
||||
Assert.That(result, Has.Count.EqualTo(1));
|
||||
Assert.That(result.First().Value, Is.EqualTo("value5")); // Ensure the most recent observation is returned
|
||||
};
|
||||
}
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty); // Ensure it returns all observations for the patient
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AlarmRepository.AggregatedPatientLastObservationsByField"/> returns all of a patient's last observations when no field filter is provided.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AggregatedPatientLastObservationsByField_FilterObservations_Null_Returns_All()
|
||||
{
|
||||
var result = await _repository.AggregatedPatientLastObservationsByField(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty); // Ensure it returns all observations for the patient
|
||||
}
|
||||
}
|
||||
@@ -13,53 +13,61 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class AppointmentArchiveRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time test setup that initializes the appointments archive collection with two seed
|
||||
/// <see cref="PatientAppointment"/> records — a minimal appointment and a fully populated one with
|
||||
/// visit number, reason, and resource group location — for use by integration tests against
|
||||
/// <see cref="AppointmentArchiveRepository"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Task"/> that completes when the collection has been recreated and both
|
||||
/// seed appointments have been inserted.</returns>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient = new Person
|
||||
public async Task Init()
|
||||
{
|
||||
FirstName = "firstName",
|
||||
SecondName = "secondName",
|
||||
BirthDate = Now.AddYears(-10),
|
||||
Gender = PatientEnum.Gender.Female,
|
||||
Ids = new Dictionary<string, string> { { "MR", "123456" }, { "VN", "654321" } }
|
||||
};
|
||||
|
||||
PatientAppointment testPatientAppointment = new()
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-2),
|
||||
UpdateTime = Now.AddHours(-2)
|
||||
};
|
||||
|
||||
PatientAppointment testPatientAppointment2 = new()
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-3),
|
||||
UpdateTime = Now.AddHours(-3),
|
||||
VisitNumber = "654321",
|
||||
AppointmentReason = "appointmentReason",
|
||||
ResourceGroups =
|
||||
[
|
||||
new PatientAppointmentResourceGroup
|
||||
{
|
||||
Locations = [new PatientLocation("UCI5C", "Box4")]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_appointments");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_appointments");
|
||||
|
||||
_repository = new AppointmentArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(testPatientAppointment);
|
||||
await _repository.InsertOneAsync(testPatientAppointment2);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
SecondName = "secondName",
|
||||
BirthDate = Now.AddYears(-10),
|
||||
Gender = PatientEnum.Gender.Female,
|
||||
Ids = new Dictionary<string, string> { { "MR", "123456" }, { "VN", "654321" } }
|
||||
};
|
||||
|
||||
PatientAppointment testPatientAppointment = new()
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-2),
|
||||
UpdateTime = Now.AddHours(-2)
|
||||
};
|
||||
|
||||
PatientAppointment testPatientAppointment2 = new()
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-3),
|
||||
UpdateTime = Now.AddHours(-3),
|
||||
VisitNumber = "654321",
|
||||
AppointmentReason = "appointmentReason",
|
||||
ResourceGroups =
|
||||
[
|
||||
new PatientAppointmentResourceGroup
|
||||
{
|
||||
Locations = [new PatientLocation("UCI5C", "Box4")]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_appointments");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_appointments");
|
||||
|
||||
_repository = new AppointmentArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(testPatientAppointment);
|
||||
await _repository.InsertOneAsync(testPatientAppointment2);
|
||||
}
|
||||
|
||||
private AppointmentArchiveRepository _repository;
|
||||
|
||||
@@ -75,19 +83,24 @@ public class AppointmentArchiveRepositoryTest
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>DeleteBeforeDate</c> method correctly removes all records
|
||||
/// with a timestamp earlier than the specified cutoff date (two hours before the current time),
|
||||
/// while retaining records dated at or after the cutoff for the given patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddHours(-2));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddHours(-2));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -12,53 +12,56 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class AppointmentRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for integration tests by resetting the patients_appointments collection and seeding it with two test patient appointments: one with minimal fields and another extended with visit number, appointment reason, and resource groups.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient = new Person
|
||||
public async Task Init()
|
||||
{
|
||||
FirstName = "firstName",
|
||||
SecondName = "secondName",
|
||||
BirthDate = Now.AddYears(-10),
|
||||
Gender = PatientEnum.Gender.Female,
|
||||
Ids = new Dictionary<string, string> { { "MR", "123456" }, { "VN", "654321" } }
|
||||
};
|
||||
|
||||
var testPatientAppointment = new PatientAppointment
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-2),
|
||||
UpdateTime = Now.AddHours(-2)
|
||||
};
|
||||
|
||||
var testPatientAppointment2 = new PatientAppointment
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-3),
|
||||
UpdateTime = Now.AddHours(-3),
|
||||
VisitNumber = "654321",
|
||||
AppointmentReason = "appointmentReason",
|
||||
ResourceGroups =
|
||||
[
|
||||
new PatientAppointmentResourceGroup
|
||||
{
|
||||
Locations = [new PatientLocation("UCI5C", "Box4")]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_appointments");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_appointments");
|
||||
|
||||
_repository = new AppointmentRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(testPatientAppointment);
|
||||
await _repository.InsertOneAsync(testPatientAppointment2);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
SecondName = "secondName",
|
||||
BirthDate = Now.AddYears(-10),
|
||||
Gender = PatientEnum.Gender.Female,
|
||||
Ids = new Dictionary<string, string> { { "MR", "123456" }, { "VN", "654321" } }
|
||||
};
|
||||
|
||||
var testPatientAppointment = new PatientAppointment
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-2),
|
||||
UpdateTime = Now.AddHours(-2)
|
||||
};
|
||||
|
||||
var testPatientAppointment2 = new PatientAppointment
|
||||
{
|
||||
PatientId = PatientId,
|
||||
Patient = patient,
|
||||
CreateTime = Now.AddHours(-3),
|
||||
UpdateTime = Now.AddHours(-3),
|
||||
VisitNumber = "654321",
|
||||
AppointmentReason = "appointmentReason",
|
||||
ResourceGroups =
|
||||
[
|
||||
new PatientAppointmentResourceGroup
|
||||
{
|
||||
Locations = [new PatientLocation("UCI5C", "Box4")]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_appointments");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_appointments");
|
||||
|
||||
_repository = new AppointmentRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(testPatientAppointment);
|
||||
await _repository.InsertOneAsync(testPatientAppointment2);
|
||||
}
|
||||
|
||||
private AppointmentRepository _repository;
|
||||
|
||||
@@ -72,77 +75,102 @@ public class AppointmentRepositoryTest
|
||||
private static readonly DateTime Now = DateTime.Now;
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AppointmentRepository"/>.GetByPatient returns a non-null, non-empty list when a valid patient identifier is provided.
|
||||
/// </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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AppointmentRepository.GetByPatient"/> returns a non-null, empty list when no records are found for the specified patient identifier.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns <c>null</c> when no patient is found matching the specified patient identifier and visit number.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientAndVisitNumber_Not_Find_Patient_Return_Null()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndVisitNumber(PatientId, "visitNumber");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindByPatientAndVisitNumber_Not_Find_Patient_Return_Null()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndVisitNumber(PatientId, "visitNumber");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindByPatientAndVisitNumber method successfully retrieves
|
||||
/// the corresponding appointment when a valid patient identifier and an existing visit number are supplied.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientAndVisitNumber_Find_Patient_Return_Appointment()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndVisitNumber(PatientId, "654321");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.VisitNumber, Is.EqualTo("654321"));
|
||||
}
|
||||
public async Task FindByPatientAndVisitNumber_Find_Patient_Return_Appointment()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndVisitNumber(PatientId, "654321");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.VisitNumber, Is.EqualTo("654321"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns null when searching for an appointment by patient ID and a reason that does not match any existing appointment.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientAndReason_Not_Find_Patient_Return_Null()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndReason(PatientId, "NotappointmentReason");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindByPatientAndReason_Not_Find_Patient_Return_Null()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndReason(PatientId, "NotappointmentReason");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that FindByPatientAndReason returns a non-null appointment containing the expected AppointmentReason for the specified patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientAndReason_Find_Patient_Return_Appointment()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndReason(PatientId, "appointmentReason");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.AppointmentReason, Is.EqualTo("appointmentReason"));
|
||||
}
|
||||
public async Task FindByPatientAndReason_Find_Patient_Return_Appointment()
|
||||
{
|
||||
var result = await _repository.FindByPatientAndReason(PatientId, "appointmentReason");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.AppointmentReason, Is.EqualTo("appointmentReason"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AppointmentRepository"/>.<c>FindByLocation</c> returns an empty (non-null) collection when no patient is associated with the specified location.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByLocation_Not_Find_Patient_Return_Null()
|
||||
{
|
||||
var location = new PatientLocation("UCI5C", "Box3");
|
||||
|
||||
var result = await _repository.FindByLocation(location);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
}
|
||||
public async Task FindByLocation_Not_Find_Patient_Return_Null()
|
||||
{
|
||||
var location = new PatientLocation("UCI5C", "Box3");
|
||||
|
||||
var result = await _repository.FindByLocation(location);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AppointmentRepository.FindByLocation"/> successfully retrieves the appointment associated with a patient located at the specified <see cref="PatientLocation"/>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByLocation_Find_Patient_Return_Appointment()
|
||||
{
|
||||
var location = new PatientLocation("UCI5C", "Box4");
|
||||
|
||||
var result = await _repository.FindByLocation(location);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
public async Task FindByLocation_Find_Patient_Return_Appointment()
|
||||
{
|
||||
var location = new PatientLocation("UCI5C", "Box4");
|
||||
|
||||
var result = await _repository.FindByLocation(location);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -13,86 +13,93 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class ConfigObservationRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the integration test environment by recreating the "config_observations" MongoDB
|
||||
/// collection and seeding it with sample <see cref="ConfigObservation"/> records that cover
|
||||
/// different configuration scenarios, including coded and uncoded observations, parent coding
|
||||
/// system references, original name mappings, and observations with min/max alert thresholds
|
||||
/// and forced alert behavior.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_id = ObjectId.GenerateNewId();
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
_masterListMock = new Mock<IMasterListServiceFactory>();
|
||||
|
||||
var testConfigObservation = new List<ConfigObservation>
|
||||
public async Task Init()
|
||||
{
|
||||
new()
|
||||
_id = ObjectId.GenerateNewId();
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
_masterListMock = new Mock<IMasterListServiceFactory>();
|
||||
|
||||
var testConfigObservation = new List<ConfigObservation>
|
||||
{
|
||||
Id = _id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
},
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Glucemia",
|
||||
Code = "54321",
|
||||
CodingSystem = "SNM",
|
||||
OriginalName = "GLU"
|
||||
},
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Sodio",
|
||||
OriginalName = "Sodio"
|
||||
},
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "ph",
|
||||
Code = "555",
|
||||
CodingSystem = "MG4",
|
||||
ParentCode = "3333",
|
||||
ParentCodingSystem = "SNM"
|
||||
},
|
||||
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "SOFA",
|
||||
Code = "278061009",
|
||||
OriginalName = "SOFA",
|
||||
CodingSystem = "SNM",
|
||||
MinAlert = 10,
|
||||
MinWarn = 14
|
||||
},
|
||||
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "FC",
|
||||
Code = "147842",
|
||||
//originalName = "MDC_ECG_CARD_BEAT_RATE",
|
||||
CodingSystem = "MDC",
|
||||
ParentCode = "69965",
|
||||
ParentName = "MDC_DEV_MON_PHYSIO_MULTI_PARAM_MDS",
|
||||
MinAlert = 60,
|
||||
MaxAlert = 100,
|
||||
ForceAlert = true
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_observations");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("config_observations");
|
||||
|
||||
_repository =
|
||||
new ConfigObservationRepository(_optionsApiSettings, IntegrationDb.Database, _masterListMock.Object);
|
||||
|
||||
await _repository.InsertManyAsync(testConfigObservation);
|
||||
}
|
||||
new()
|
||||
{
|
||||
Id = _id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
},
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Glucemia",
|
||||
Code = "54321",
|
||||
CodingSystem = "SNM",
|
||||
OriginalName = "GLU"
|
||||
},
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Sodio",
|
||||
OriginalName = "Sodio"
|
||||
},
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "ph",
|
||||
Code = "555",
|
||||
CodingSystem = "MG4",
|
||||
ParentCode = "3333",
|
||||
ParentCodingSystem = "SNM"
|
||||
},
|
||||
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "SOFA",
|
||||
Code = "278061009",
|
||||
OriginalName = "SOFA",
|
||||
CodingSystem = "SNM",
|
||||
MinAlert = 10,
|
||||
MinWarn = 14
|
||||
},
|
||||
|
||||
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "FC",
|
||||
Code = "147842",
|
||||
//originalName = "MDC_ECG_CARD_BEAT_RATE",
|
||||
CodingSystem = "MDC",
|
||||
ParentCode = "69965",
|
||||
ParentName = "MDC_DEV_MON_PHYSIO_MULTI_PARAM_MDS",
|
||||
MinAlert = 60,
|
||||
MaxAlert = 100,
|
||||
ForceAlert = true
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_observations");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("config_observations");
|
||||
|
||||
_repository =
|
||||
new ConfigObservationRepository(_optionsApiSettings, IntegrationDb.Database, _masterListMock.Object);
|
||||
|
||||
await _repository.InsertManyAsync(testConfigObservation);
|
||||
}
|
||||
|
||||
private ConfigObservationRepository _repository;
|
||||
private IMock<IMasterListServiceFactory> _masterListMock;
|
||||
@@ -106,85 +113,101 @@ public class ConfigObservationRepositoryTest
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindById method returns a non-null configuration result when queried with a valid id.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Find_Id_Return_Configs()
|
||||
{
|
||||
var result = await _repository.FindById(_id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindById_Not_Find_Id_Return_Empty()
|
||||
{
|
||||
var result = await _repository.FindById(ObjectId.GenerateNewId());
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_Find_Id_Return_Update_Configs()
|
||||
{
|
||||
var updateConfigObservation = new ConfigObservation
|
||||
public async Task FindById_Find_Id_Return_Configs()
|
||||
{
|
||||
Id = _id,
|
||||
Name = "Hemoglobina 2",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
};
|
||||
|
||||
var result = await _repository.FindById(_id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Name, Is.EqualTo("Hemoglobina"));
|
||||
|
||||
var resultUpdate = await _repository.Update(updateConfigObservation);
|
||||
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.Name, Is.EqualTo("Hemoglobina 2"));
|
||||
}
|
||||
var result = await _repository.FindById(_id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the <c>FindById</c> repository method returns <c>null</c> when invoked with a newly generated, non-existing identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Update_Not_Find_Id_Create_It()
|
||||
{
|
||||
var id2 = ObjectId.GenerateNewId();
|
||||
var updateConfigObservation = new ConfigObservation
|
||||
public async Task FindById_Not_Find_Id_Return_Empty()
|
||||
{
|
||||
Id = id2,
|
||||
Name = "Hemoglobina",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
};
|
||||
|
||||
await _repository.Update(updateConfigObservation);
|
||||
var resultfind = await _repository.FindById(id2);
|
||||
Assert.That(resultfind, Is.Not.Null);
|
||||
}
|
||||
|
||||
var result = await _repository.FindById(ObjectId.GenerateNewId());
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an existing <see cref="ConfigObservation"/> can be retrieved by its identifier and subsequently updated, ensuring the updated entity reflects the new values.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_With_Base_DeleteAsync()
|
||||
{
|
||||
var iid = ObjectId.GenerateNewId();
|
||||
var deleteConfigObservation = new ConfigObservation
|
||||
public async Task Update_Find_Id_Return_Update_Configs()
|
||||
{
|
||||
Id = iid,
|
||||
Name = "Hemoglobina3",
|
||||
Code = "123455",
|
||||
CodingSystem = "SNMM"
|
||||
};
|
||||
var updateConfigObservation = new ConfigObservation
|
||||
{
|
||||
Id = _id,
|
||||
Name = "Hemoglobina 2",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
};
|
||||
|
||||
var result = await _repository.FindById(_id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Name, Is.EqualTo("Hemoglobina"));
|
||||
|
||||
var resultUpdate = await _repository.Update(updateConfigObservation);
|
||||
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.Name, Is.EqualTo("Hemoglobina 2"));
|
||||
}
|
||||
|
||||
var result = await _repository.FindById(iid);
|
||||
Assert.That(result, Is.Null);
|
||||
/// <summary>
|
||||
/// Verifies that the repository's Update operation creates a new record when the provided identifier does not exist in the data store, instead of failing.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Update_Not_Find_Id_Create_It()
|
||||
{
|
||||
var id2 = ObjectId.GenerateNewId();
|
||||
var updateConfigObservation = new ConfigObservation
|
||||
{
|
||||
Id = id2,
|
||||
Name = "Hemoglobina",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
};
|
||||
|
||||
await _repository.Update(updateConfigObservation);
|
||||
var resultfind = await _repository.FindById(id2);
|
||||
Assert.That(resultfind, Is.Not.Null);
|
||||
}
|
||||
|
||||
await _repository.InsertOneAsync(deleteConfigObservation);
|
||||
|
||||
var resultInsert = await _repository.FindById(iid);
|
||||
Assert.That(resultInsert, Is.Not.Null);
|
||||
|
||||
await _repository.Delete(iid);
|
||||
|
||||
var resultDelete = await _repository.FindById(iid);
|
||||
Assert.That(resultDelete, Is.Null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that the base delete operation removes a <see cref="ConfigObservation"/> from the repository.
|
||||
/// The test confirms the entity is absent before insertion, present after insertion, and absent again after deletion.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_With_Base_DeleteAsync()
|
||||
{
|
||||
var iid = ObjectId.GenerateNewId();
|
||||
var deleteConfigObservation = new ConfigObservation
|
||||
{
|
||||
Id = iid,
|
||||
Name = "Hemoglobina3",
|
||||
Code = "123455",
|
||||
CodingSystem = "SNMM"
|
||||
};
|
||||
|
||||
var result = await _repository.FindById(iid);
|
||||
Assert.That(result, Is.Null);
|
||||
|
||||
await _repository.InsertOneAsync(deleteConfigObservation);
|
||||
|
||||
var resultInsert = await _repository.FindById(iid);
|
||||
Assert.That(resultInsert, Is.Not.Null);
|
||||
|
||||
await _repository.Delete(iid);
|
||||
|
||||
var resultDelete = await _repository.FindById(iid);
|
||||
Assert.That(resultDelete, Is.Null);
|
||||
}
|
||||
}
|
||||
@@ -11,27 +11,30 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class ConfigPumpsRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the integration test environment by recreating the config_pumps collection and inserting a single configuration pump containing two empty items for use by subsequent tests.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var configPumpItem1 = new ConfigPumpItem();
|
||||
var configPumpItem2 = new ConfigPumpItem();
|
||||
|
||||
var configPumps = new ConfigPumps
|
||||
public async Task Init()
|
||||
{
|
||||
Id = "PV1",
|
||||
Items = [configPumpItem1, configPumpItem2]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_pumps");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("config_pumps");
|
||||
|
||||
_repository = new ConfigPumpsRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(configPumps);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var configPumpItem1 = new ConfigPumpItem();
|
||||
var configPumpItem2 = new ConfigPumpItem();
|
||||
|
||||
var configPumps = new ConfigPumps
|
||||
{
|
||||
Id = "PV1",
|
||||
Items = [configPumpItem1, configPumpItem2]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_pumps");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("config_pumps");
|
||||
|
||||
_repository = new ConfigPumpsRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(configPumps);
|
||||
}
|
||||
|
||||
private ConfigPumpsRepository _repository;
|
||||
|
||||
@@ -43,46 +46,55 @@ public class ConfigPumpsRepositoryTest
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="ConfigPumpsRepository.FindById"/> returns a non-null result when searching by the identifier "PV1".
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Find_id_Return_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindAsync_not_Find_id_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV2");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Insert_PumpConfig_returns2()
|
||||
{
|
||||
var configPumpItem1 = new ConfigPumpItem();
|
||||
var configPumpItem2 = new ConfigPumpItem();
|
||||
|
||||
var newPumpConfig = new ConfigPumps
|
||||
public async Task FindById_Find_id_Return_List()
|
||||
{
|
||||
Id = "PV2",
|
||||
Items = [configPumpItem1, configPumpItem2]
|
||||
};
|
||||
var result = await _repository.FindById("PV1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
await _repository.InsertOneAsync(newPumpConfig);
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindById method returns null when no entity is found for the specified identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAsync_not_Find_id_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV2");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
var result = await _repository.GetAllConfigs();
|
||||
|
||||
Assert.That(result, Has.Count.EqualTo(2));
|
||||
|
||||
var pumpCfgInserted = await _repository.FindById(newPumpConfig.Id);
|
||||
|
||||
Assert.That(pumpCfgInserted, Is.Not.EqualTo(null));
|
||||
|
||||
Debug.Assert(pumpCfgInserted != null, nameof(pumpCfgInserted) + " != null");
|
||||
|
||||
await _repository.DeleteConfig(pumpCfgInserted);
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests that inserting a new pump configuration with two items increases the total configuration count to two, that the inserted configuration can be retrieved by its identifier, and that the inserted configuration can be successfully deleted.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Insert_PumpConfig_returns2()
|
||||
{
|
||||
var configPumpItem1 = new ConfigPumpItem();
|
||||
var configPumpItem2 = new ConfigPumpItem();
|
||||
|
||||
var newPumpConfig = new ConfigPumps
|
||||
{
|
||||
Id = "PV2",
|
||||
Items = [configPumpItem1, configPumpItem2]
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(newPumpConfig);
|
||||
|
||||
var result = await _repository.GetAllConfigs();
|
||||
|
||||
Assert.That(result, Has.Count.EqualTo(2));
|
||||
|
||||
var pumpCfgInserted = await _repository.FindById(newPumpConfig.Id);
|
||||
|
||||
Assert.That(pumpCfgInserted, Is.Not.EqualTo(null));
|
||||
|
||||
Debug.Assert(pumpCfgInserted != null, nameof(pumpCfgInserted) + " != null");
|
||||
|
||||
await _repository.DeleteConfig(pumpCfgInserted);
|
||||
}
|
||||
}
|
||||
@@ -10,27 +10,30 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class ConfigUnitsRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for integration tests by resetting the <c>config_units</c> collection and seeding it with a single <see cref="ConfigUnits"/> document (Id "PV1") containing two empty <see cref="ConfigUnitItem"/> entries, then initializes the <see cref="ConfigUnitsRepository"/> used by the tests.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var configUnitItem1 = new ConfigUnitItem();
|
||||
var configUnitItem2 = new ConfigUnitItem();
|
||||
|
||||
var configUnits = new ConfigUnits
|
||||
public async Task Init()
|
||||
{
|
||||
Id = "PV1",
|
||||
Items = [configUnitItem1, configUnitItem2]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_units");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("config_units");
|
||||
|
||||
_repository = new ConfigUnitsRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(configUnits);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var configUnitItem1 = new ConfigUnitItem();
|
||||
var configUnitItem2 = new ConfigUnitItem();
|
||||
|
||||
var configUnits = new ConfigUnits
|
||||
{
|
||||
Id = "PV1",
|
||||
Items = [configUnitItem1, configUnitItem2]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_units");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("config_units");
|
||||
|
||||
_repository = new ConfigUnitsRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(configUnits);
|
||||
}
|
||||
|
||||
private ConfigUnitsRepository _repository;
|
||||
|
||||
@@ -42,19 +45,25 @@ public class ConfigUnitsRepositoryTest
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindById</c> method returns a non-null result when searching by the identifier "PV1".
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Find_id_Return_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
public async Task FindById_Find_id_Return_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="ConfigUnitsRepository.FindById"/> returns null when invoked with an identifier ("PV2") that does not exist in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAsync_not_Find_id_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV2");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindAsync_not_Find_id_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.FindById("PV2");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
}
|
||||
@@ -12,47 +12,52 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class DiagnosisArchiveRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the test fixture by creating sample patient diagnosis records, resetting the
|
||||
/// archive collection in the integration database, and configuring the diagnosis archive
|
||||
/// repository used by the test suite.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patientDiagnosis1 = new PatientDiagnosis
|
||||
public async Task Init()
|
||||
{
|
||||
Id = Id,
|
||||
PatientId = PatientId,
|
||||
Time = Now.AddDays(-1),
|
||||
Code = "code1",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
var patientDiagnosis2 = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Time = Now.AddDays(-2),
|
||||
Code = "code2",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
var patientDiagnosis3 = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Time = Now.AddDays(-3),
|
||||
Code = "code3",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_diagnosis");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_diagnosis");
|
||||
|
||||
_repository = new DiagnosisArchiveRepository(_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.AddDays(-1),
|
||||
Code = "code1",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
var patientDiagnosis2 = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Time = Now.AddDays(-2),
|
||||
Code = "code2",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
var patientDiagnosis3 = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
Time = Now.AddDays(-3),
|
||||
Code = "code3",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_diagnosis");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_diagnosis");
|
||||
|
||||
_repository = new DiagnosisArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(patientDiagnosis1);
|
||||
await _repository.InsertOneAsync(patientDiagnosis2);
|
||||
await _repository.InsertOneAsync(patientDiagnosis3);
|
||||
}
|
||||
|
||||
private DiagnosisArchiveRepository _repository;
|
||||
|
||||
@@ -68,19 +73,24 @@ public class DiagnosisArchiveRepositoryTest
|
||||
private static readonly ObjectId Id = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>DeleteBeforeDate</c> operation correctly removes all records
|
||||
/// for a given patient that were created before the specified cutoff date, while preserving records
|
||||
/// created on or after that date.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddDays(-1));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddDays(-1));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -13,69 +13,82 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class DischargeRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time test setup for discharge integration tests by initializing API settings, dropping and recreating the "discharge" collection in the integration database, and instantiating the <see cref="DischargeRepository"/>.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
// Initialize options and repository
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("discharge");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("discharge");
|
||||
|
||||
_dischargeRepository = new DischargeRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
}
|
||||
public async Task Init()
|
||||
{
|
||||
// Initialize options and repository
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("discharge");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("discharge");
|
||||
|
||||
_dischargeRepository = new DischargeRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
}
|
||||
|
||||
private DischargeRepository _dischargeRepository;
|
||||
private readonly ApiSettings _apiSettings = new();
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>InsertOneAsync</c> successfully persists a discharge document and that the
|
||||
/// inserted record can be retrieved by its identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOneAsync_ShouldInsertDischarge()
|
||||
{
|
||||
// Arrange
|
||||
var discharge = TestUtilities.CreateValidDischarge();
|
||||
|
||||
// Act
|
||||
await _dischargeRepository.InsertOneAsync(discharge);
|
||||
|
||||
var result = await _dischargeRepository.FindById(discharge.Id);
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
public async Task InsertOneAsync_ShouldInsertDischarge()
|
||||
{
|
||||
// Arrange
|
||||
var discharge = TestUtilities.CreateValidDischarge();
|
||||
|
||||
// Act
|
||||
await _dischargeRepository.InsertOneAsync(discharge);
|
||||
|
||||
var result = await _dischargeRepository.FindById(discharge.Id);
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the <c>Delete</c> repository operation removes a discharge so that subsequent lookups by its identifier return no result.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_ShouldDeleteDischarge()
|
||||
{
|
||||
// Arrange
|
||||
var discharge = TestUtilities.CreateValidDischarge();
|
||||
await _dischargeRepository.InsertOneAsync(discharge);
|
||||
|
||||
// Act
|
||||
await _dischargeRepository.Delete(discharge.Id);
|
||||
|
||||
var result = await _dischargeRepository.FindById(discharge.Id);
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task Delete_ShouldDeleteDischarge()
|
||||
{
|
||||
// Arrange
|
||||
var discharge = TestUtilities.CreateValidDischarge();
|
||||
await _dischargeRepository.InsertOneAsync(discharge);
|
||||
|
||||
// Act
|
||||
await _dischargeRepository.Delete(discharge.Id);
|
||||
|
||||
var result = await _dischargeRepository.FindById(discharge.Id);
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an existing discharge record is successfully updated in the repository with new field values.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Update_DischargeSuccessfullyUpdated()
|
||||
{
|
||||
// Arrange
|
||||
var pocId = new ObjectId();
|
||||
var discharge = TestUtilities.CreateValidDischarge();
|
||||
discharge.PointOfCareId = pocId;
|
||||
await _dischargeRepository.InsertOneAsync(discharge);
|
||||
|
||||
// Act
|
||||
discharge.Service = "UpdatedService";
|
||||
await _dischargeRepository.Update(discharge);
|
||||
|
||||
// Retrieve the discharge from the database
|
||||
var updatedDischarge = await _dischargeRepository.GetDischargeByPointOfCareId(pocId);
|
||||
|
||||
// Assert
|
||||
Assert.That(updatedDischarge, Is.Not.Null);
|
||||
Assert.That(updatedDischarge?.Service, Is.EqualTo("UpdatedService"));
|
||||
}
|
||||
public async Task Update_DischargeSuccessfullyUpdated()
|
||||
{
|
||||
// Arrange
|
||||
var pocId = new ObjectId();
|
||||
var discharge = TestUtilities.CreateValidDischarge();
|
||||
discharge.PointOfCareId = pocId;
|
||||
await _dischargeRepository.InsertOneAsync(discharge);
|
||||
|
||||
// Act
|
||||
discharge.Service = "UpdatedService";
|
||||
await _dischargeRepository.Update(discharge);
|
||||
|
||||
// Retrieve the discharge from the database
|
||||
var updatedDischarge = await _dischargeRepository.GetDischargeByPointOfCareId(pocId);
|
||||
|
||||
// Assert
|
||||
Assert.That(updatedDischarge, Is.Not.Null);
|
||||
Assert.That(updatedDischarge?.Service, Is.EqualTo("UpdatedService"));
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task UpdateUnit_UnitNameSuccessfullyUpdated()
|
||||
@@ -119,50 +132,59 @@ public class DischargeRepositoryTest
|
||||
// Assert.That(updatedDischarge?.Patient?.Id, Is.EqualTo(updatedPatient.Id));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindAll</c> method returns all discharge records previously inserted via <c>InsertManyAsync</c>, returning a non-null, non-empty collection whose count matches the number of inserted records.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAll_ReturnsAllDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var expectedDischarges = new List<Discharge>
|
||||
public async Task FindAll_ReturnsAllDischarges()
|
||||
{
|
||||
new() { Id = ObjectId.GenerateNewId(), DischargeDate = DateTime.UtcNow },
|
||||
new() { Id = ObjectId.GenerateNewId(), DischargeDate = DateTime.UtcNow },
|
||||
new() { Id = ObjectId.GenerateNewId(), DischargeDate = DateTime.UtcNow }
|
||||
};
|
||||
|
||||
await _dischargeRepository.InsertManyAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindAll();
|
||||
|
||||
var discharges = actualDischarges.ToList();
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges, Is.Not.Empty);
|
||||
Assert.That(discharges.Count(), Is.EqualTo(expectedDischarges.Count()));
|
||||
}
|
||||
// Arrange: Prepare test data
|
||||
var expectedDischarges = new List<Discharge>
|
||||
{
|
||||
new() { Id = ObjectId.GenerateNewId(), DischargeDate = DateTime.UtcNow },
|
||||
new() { Id = ObjectId.GenerateNewId(), DischargeDate = DateTime.UtcNow },
|
||||
new() { Id = ObjectId.GenerateNewId(), DischargeDate = DateTime.UtcNow }
|
||||
};
|
||||
|
||||
await _dischargeRepository.InsertManyAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindAll();
|
||||
|
||||
var discharges = actualDischarges.ToList();
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges, Is.Not.Empty);
|
||||
Assert.That(discharges.Count(), Is.EqualTo(expectedDischarges.Count()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindById</c> method returns the matching <c>Discharge</c> document when queried with an existing identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_ExistingId_ReturnsDischarge()
|
||||
{
|
||||
var id = ObjectId.GenerateNewId();
|
||||
var expectedDischarge = new Discharge { Id = id, DischargeDate = DateTime.UtcNow };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarge);
|
||||
|
||||
var actualDischarge = await _dischargeRepository.FindById(id);
|
||||
|
||||
Assert.That(actualDischarge, Is.Not.Null);
|
||||
Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarge.Id));
|
||||
}
|
||||
public async Task FindById_ExistingId_ReturnsDischarge()
|
||||
{
|
||||
var id = ObjectId.GenerateNewId();
|
||||
var expectedDischarge = new Discharge { Id = id, DischargeDate = DateTime.UtcNow };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarge);
|
||||
|
||||
var actualDischarge = await _dischargeRepository.FindById(id);
|
||||
|
||||
Assert.That(actualDischarge, Is.Not.Null);
|
||||
Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarge.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the discharge repository's FindById method returns <c>null</c> when queried with a non-existent <see cref="ObjectId"/>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_NonExistentId_ReturnsNull()
|
||||
{
|
||||
var id = ObjectId.GenerateNewId();
|
||||
|
||||
var actualDischarge = await _dischargeRepository.FindById(id);
|
||||
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
public async Task FindById_NonExistentId_ReturnsNull()
|
||||
{
|
||||
var id = ObjectId.GenerateNewId();
|
||||
|
||||
var actualDischarge = await _dischargeRepository.FindById(id);
|
||||
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task FindByUnit_ExistingUnit_ReturnsDischarges()
|
||||
@@ -182,101 +204,120 @@ public class DischargeRepositoryTest
|
||||
// Assert.That(actualDischarges?.ToList().First().PatientLocation?.UnitName, Is.EquivalentTo(expectedDischarges.PatientLocation.UnitName));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the discharge repository's FindByDestination method returns the matching discharge records when queried with an existing destination.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDestination_ExistingDestination_ReturnsDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var destination = "TestDestination";
|
||||
var expectedDischarges =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), Destination = destination };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByDestination(destination);
|
||||
|
||||
// Assert: Verify the result
|
||||
var discharges = actualDischarges?.ToList() ?? [];
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges.First().Id, Is.EqualTo(expectedDischarges.Id));
|
||||
}
|
||||
public async Task FindByDestination_ExistingDestination_ReturnsDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var destination = "TestDestination";
|
||||
var expectedDischarges =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), Destination = destination };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByDestination(destination);
|
||||
|
||||
// Assert: Verify the result
|
||||
var discharges = actualDischarges?.ToList() ?? [];
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges.First().Id, Is.EqualTo(expectedDischarges.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDestination</c> returns an empty collection when the provided destination does not match any stored discharge records.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDestination_NonExistentDestination_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange: Use a non-existent destination
|
||||
var destination = "NonExistentDestination";
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByDestination(destination);
|
||||
|
||||
// Assert: Verify that the result is an empty list
|
||||
Assert.That(actualDischarges, Is.Empty);
|
||||
}
|
||||
public async Task FindByDestination_NonExistentDestination_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange: Use a non-existent destination
|
||||
var destination = "NonExistentDestination";
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByDestination(destination);
|
||||
|
||||
// Assert: Verify that the result is an empty list
|
||||
Assert.That(actualDischarges, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DischargeRepository.FindByPoCId"/> returns the matching discharge
|
||||
/// when a discharge is associated with the supplied point-of-care identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPoCId_ExistingPoCId_ReturnsDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
var expectedDischarges =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), PointOfCareId = pocId };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByPoCId(pocId);
|
||||
|
||||
// Assert: Verify the result
|
||||
var discharges = actualDischarges?.ToList() ?? [];
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges.First().Id, Is.EqualTo(expectedDischarges.Id));
|
||||
}
|
||||
public async Task FindByPoCId_ExistingPoCId_ReturnsDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
var expectedDischarges =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), PointOfCareId = pocId };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByPoCId(pocId);
|
||||
|
||||
// Assert: Verify the result
|
||||
var discharges = actualDischarges?.ToList() ?? [];
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges.First().Id, Is.EqualTo(expectedDischarges.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the discharge repository's FindByPoCId method returns an empty list when queried with a non-existent PoCId.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPoCId_NonExistentPoCId_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange: Use a non-existent PoCId
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByPoCId(pocId);
|
||||
|
||||
// Assert: Verify that the result is an empty list
|
||||
Assert.That(actualDischarges, Is.Empty);
|
||||
}
|
||||
public async Task FindByPoCId_NonExistentPoCId_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange: Use a non-existent PoCId
|
||||
var pocId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByPoCId(pocId);
|
||||
|
||||
// Assert: Verify that the result is an empty list
|
||||
Assert.That(actualDischarges, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DischargeRepository.FindByService"/> returns the matching discharge record when a previously inserted discharge exists for the specified service name.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByService_ExistingService_ReturnsDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var service = "TestService";
|
||||
var expectedDischarges =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), Service = service };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByService(service);
|
||||
|
||||
// Assert: Verify the result
|
||||
var discharges = actualDischarges?.ToList() ?? [];
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges.First().Id, Is.EqualTo(expectedDischarges.Id));
|
||||
}
|
||||
public async Task FindByService_ExistingService_ReturnsDischarges()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var service = "TestService";
|
||||
var expectedDischarges =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), Service = service };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarges);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByService(service);
|
||||
|
||||
// Assert: Verify the result
|
||||
var discharges = actualDischarges?.ToList() ?? [];
|
||||
Assert.That(discharges, Is.Not.Null);
|
||||
Assert.That(discharges.First().Id, Is.EqualTo(expectedDischarges.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByService</c> returns an empty list when queried with a service name that does not exist in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByService_NonExistentService_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange: Use a non-existent service
|
||||
var service = "NonExistentService";
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByService(service);
|
||||
|
||||
// Assert: Verify that the result is an empty list
|
||||
Assert.That(actualDischarges, Is.Empty);
|
||||
}
|
||||
public async Task FindByService_NonExistentService_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange: Use a non-existent service
|
||||
var service = "NonExistentService";
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarges = await _dischargeRepository.FindByService(service);
|
||||
|
||||
// Assert: Verify that the result is an empty list
|
||||
Assert.That(actualDischarges, Is.Empty);
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task GetDischargeByLocation_ExistingLocation_ReturnsDischarge()
|
||||
@@ -296,78 +337,96 @@ public class DischargeRepositoryTest
|
||||
// Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarges.Id));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetDischargeByLocation</c> returns <c>null</c> when queried with a location
|
||||
/// that does not exist in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetDischargeByLocation_NonExistentLocation_ReturnsNull()
|
||||
{
|
||||
// Arrange: Use a non-existent location
|
||||
var location = new PatientLocation("NonExistentUnit", "NonExistentBed", "NonExistentRoom");
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetDischargeByLocation(location);
|
||||
|
||||
// Assert: Verify that the result is null
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
public async Task GetDischargeByLocation_NonExistentLocation_ReturnsNull()
|
||||
{
|
||||
// Arrange: Use a non-existent location
|
||||
var location = new PatientLocation("NonExistentUnit", "NonExistentBed", "NonExistentRoom");
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetDischargeByLocation(location);
|
||||
|
||||
// Assert: Verify that the result is null
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetDischargeByPointOfCareId</c> returns the matching <c>Discharge</c> when queried with a point of care ID that already exists in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetDischargeByPointOfCareId_ExistingId_ReturnsDischarge()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var expectedId = ObjectId.GenerateNewId();
|
||||
var expectedDischarge =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), PointOfCareId = expectedId };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarge);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetDischargeByPointOfCareId(expectedId);
|
||||
|
||||
// Assert: Verify the result
|
||||
Assert.That(actualDischarge, Is.Not.Null);
|
||||
Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarge.Id));
|
||||
}
|
||||
public async Task GetDischargeByPointOfCareId_ExistingId_ReturnsDischarge()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var expectedId = ObjectId.GenerateNewId();
|
||||
var expectedDischarge =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), PointOfCareId = expectedId };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarge);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetDischargeByPointOfCareId(expectedId);
|
||||
|
||||
// Assert: Verify the result
|
||||
Assert.That(actualDischarge, Is.Not.Null);
|
||||
Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarge.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetDischargeByPointOfCareId</c> returns <c>null</c> when called with a non-existent point of care ID.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetDischargeByPointOfCareId_NonExistentId_ReturnsNull()
|
||||
{
|
||||
// Arrange: Use a non-existent ID
|
||||
var nonExistentId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetDischargeByPointOfCareId(nonExistentId);
|
||||
|
||||
// Assert: Verify that the result is null
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
public async Task GetDischargeByPointOfCareId_NonExistentId_ReturnsNull()
|
||||
{
|
||||
// Arrange: Use a non-existent ID
|
||||
var nonExistentId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetDischargeByPointOfCareId(nonExistentId);
|
||||
|
||||
// Assert: Verify that the result is null
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetByPatientId</c> returns the matching <see cref="Discharge"/> record
|
||||
/// when a discharge exists for the specified patient identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByPatientId_ExistingPatientId_ReturnsDischarge()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var expectedId = ObjectId.GenerateNewId();
|
||||
var expectedDischarge =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), PatientId = expectedId };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarge);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetByPatientId(expectedId);
|
||||
|
||||
// Assert: Verify the result
|
||||
Assert.That(actualDischarge, Is.Not.Null);
|
||||
Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarge.Id));
|
||||
}
|
||||
public async Task GetByPatientId_ExistingPatientId_ReturnsDischarge()
|
||||
{
|
||||
// Arrange: Prepare test data
|
||||
var expectedId = ObjectId.GenerateNewId();
|
||||
var expectedDischarge =
|
||||
new Discharge
|
||||
{ Id = ObjectId.GenerateNewId(), PatientId = expectedId };
|
||||
await _dischargeRepository.InsertOneAsync(expectedDischarge);
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetByPatientId(expectedId);
|
||||
|
||||
// Assert: Verify the result
|
||||
Assert.That(actualDischarge, Is.Not.Null);
|
||||
Assert.That(actualDischarge?.Id, Is.EqualTo(expectedDischarge.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the <see cref="DischargeRepository.GetByPatientId"/> repository method returns <c>null</c>
|
||||
/// when called with a patient ID that does not exist in the data store.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByPatientId_NonExistentPatientId_ReturnsNull()
|
||||
{
|
||||
// Arrange: Use a non-existent patient ID
|
||||
var nonExistentId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetByPatientId(nonExistentId);
|
||||
|
||||
// Assert: Verify that the result is null
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
public async Task GetByPatientId_NonExistentPatientId_ReturnsNull()
|
||||
{
|
||||
// Arrange: Use a non-existent patient ID
|
||||
var nonExistentId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act: Call the method under test
|
||||
var actualDischarge = await _dischargeRepository.GetByPatientId(nonExistentId);
|
||||
|
||||
// Assert: Verify that the result is null
|
||||
Assert.That(actualDischarge, Is.Null);
|
||||
}
|
||||
}
|
||||
@@ -13,47 +13,53 @@ namespace adas_core.Test.Repositories;
|
||||
[TestFixture]
|
||||
public class DisplayConfigTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for integration tests by initializing the display configuration, card configuration, and detail configuration repositories with test data, including a valid display configuration, a card configuration, and a nurse card details configuration.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task SetUp()
|
||||
{
|
||||
Options.Create(new ApiSettings());
|
||||
_unitRepository = new Mock<IUnitRepository>();
|
||||
_displayCardConfigRepository =
|
||||
new DisplayCardConfigRepository(
|
||||
IntegrationDb.Database,
|
||||
new ApiSettings(),
|
||||
new Mock<ILogger<DisplayCardConfigRepository>>().Object
|
||||
);
|
||||
_displayConfigRepository =
|
||||
new DisplayConfigRepository(
|
||||
IntegrationDb.Database,
|
||||
new ApiSettings(),
|
||||
new Mock<ILogger<DisplayConfigRepository>>().Object,
|
||||
_unitRepository.Object
|
||||
);
|
||||
_displayDetailConfigRepository =
|
||||
new DisplayDetailConfigRepository(
|
||||
IntegrationDb.Database,
|
||||
new ApiSettings(),
|
||||
new Mock<ILogger<DisplayDetailConfigRepository>>().Object
|
||||
);
|
||||
|
||||
await _displayDetailConfigRepository.InsertOneAsync(
|
||||
TestUtilities.CreateValidCardDetailsNurseConfig(_configDisplayCardDetailsId));
|
||||
await _displayCardConfigRepository.InsertOneAsync(TestUtilities.CreateValidCardConfig(_configDisplayCardId));
|
||||
await _displayConfigRepository.InsertOneAsync(TestUtilities.CreateValidDisplayConfig(
|
||||
DisplayConfigEnums.DisplayType.DisplayNurse, _configDisplayId, _configDisplayCardId,
|
||||
_configDisplayCardDetailsId));
|
||||
}
|
||||
public async Task SetUp()
|
||||
{
|
||||
Options.Create(new ApiSettings());
|
||||
_unitRepository = new Mock<IUnitRepository>();
|
||||
_displayCardConfigRepository =
|
||||
new DisplayCardConfigRepository(
|
||||
IntegrationDb.Database,
|
||||
new ApiSettings(),
|
||||
new Mock<ILogger<DisplayCardConfigRepository>>().Object
|
||||
);
|
||||
_displayConfigRepository =
|
||||
new DisplayConfigRepository(
|
||||
IntegrationDb.Database,
|
||||
new ApiSettings(),
|
||||
new Mock<ILogger<DisplayConfigRepository>>().Object,
|
||||
_unitRepository.Object
|
||||
);
|
||||
_displayDetailConfigRepository =
|
||||
new DisplayDetailConfigRepository(
|
||||
IntegrationDb.Database,
|
||||
new ApiSettings(),
|
||||
new Mock<ILogger<DisplayDetailConfigRepository>>().Object
|
||||
);
|
||||
|
||||
await _displayDetailConfigRepository.InsertOneAsync(
|
||||
TestUtilities.CreateValidCardDetailsNurseConfig(_configDisplayCardDetailsId));
|
||||
await _displayCardConfigRepository.InsertOneAsync(TestUtilities.CreateValidCardConfig(_configDisplayCardId));
|
||||
await _displayConfigRepository.InsertOneAsync(TestUtilities.CreateValidDisplayConfig(
|
||||
DisplayConfigEnums.DisplayType.DisplayNurse, _configDisplayId, _configDisplayCardId,
|
||||
_configDisplayCardDetailsId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One-time teardown method that cleans up the integration test database by dropping the display configuration collections created during testing.
|
||||
/// </summary>
|
||||
[OneTimeTearDown]
|
||||
public async Task Cleanup()
|
||||
{
|
||||
// Clean up database after tests
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_displays");
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_displays_card");
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_displays_detail");
|
||||
}
|
||||
public async Task Cleanup()
|
||||
{
|
||||
// Clean up database after tests
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_displays");
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_displays_card");
|
||||
await IntegrationDb.Database.DropCollectionAsync("config_displays_detail");
|
||||
}
|
||||
|
||||
private DisplayConfigRepository _displayConfigRepository;
|
||||
private DisplayCardConfigRepository _displayCardConfigRepository;
|
||||
@@ -63,17 +69,20 @@ public class DisplayConfigTest
|
||||
private readonly ObjectId _configDisplayCardId = ObjectId.GenerateNewId();
|
||||
private readonly ObjectId _configDisplayCardDetailsId = ObjectId.GenerateNewId();
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that retrieving a display configuration by its identifier returns a non-null result with the associated card and detail configurations populated.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByIdShouldReturnAllConfigsAssociated()
|
||||
{
|
||||
var result = await _displayConfigRepository.GetById(_configDisplayId);
|
||||
Assert.That(result, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
public async Task GetByIdShouldReturnAllConfigsAssociated()
|
||||
{
|
||||
Assert.That(result.CardConfigId, Is.Not.Null);
|
||||
Assert.That(result.CardConfig, Is.Not.Null);
|
||||
Assert.That(result.DetailConfigId, Is.Not.Null);
|
||||
Assert.That(result.DetailConfig, Is.Not.Null);
|
||||
};
|
||||
}
|
||||
var result = await _displayConfigRepository.GetById(_configDisplayId);
|
||||
Assert.That(result, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.CardConfigId, Is.Not.Null);
|
||||
Assert.That(result.CardConfig, Is.Not.Null);
|
||||
Assert.That(result.DetailConfigId, Is.Not.Null);
|
||||
Assert.That(result.DetailConfig, Is.Not.Null);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,16 @@ public class DisplayRepisitoryTest
|
||||
//private Mock<ILogger<DisplayRepository>> _mockLogger ;
|
||||
//private Mock<IOptions<ApiSettings>> _mockOptionsApiSettings ;
|
||||
|
||||
/// <summary>
|
||||
/// One-time setup method that resets the "displays" collection in the integration database by dropping and recreating it, ensuring a clean state before integration tests run.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task OneTimeSetUp()
|
||||
{
|
||||
//_mockLogger = new Mock<ILogger<DisplayRepository>>();
|
||||
//_mockOptionsApiSettings = new Mock<IOptions<ApiSettings>>();
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("displays");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("displays");
|
||||
}
|
||||
public async Task OneTimeSetUp()
|
||||
{
|
||||
//_mockLogger = new Mock<ILogger<DisplayRepository>>();
|
||||
//_mockOptionsApiSettings = new Mock<IOptions<ApiSettings>>();
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("displays");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("displays");
|
||||
}
|
||||
}
|
||||
@@ -15,25 +15,31 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class HistoricalConfigChangesRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for the test fixture by initializing configuration options, a mocked logger, and the <see cref="HistoricalConfigChangesRepository"/> instance used across the tests.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public void Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
_logger = new Mock<ILogger<HistoricalConfigChangesRepository>>();
|
||||
|
||||
|
||||
_repository =
|
||||
new HistoricalConfigChangesRepository(_optionsApiSettings, IntegrationDb.Database, _logger.Object);
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
_logger = new Mock<ILogger<HistoricalConfigChangesRepository>>();
|
||||
|
||||
|
||||
_repository =
|
||||
new HistoricalConfigChangesRepository(_optionsApiSettings, IntegrationDb.Database, _logger.Object);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the integration test environment by dropping and recreating the <c>historicalConfigChanges</c> collection and then reinitializing the test data. Used as a teardown step to ensure a clean state between tests.
|
||||
/// </summary>
|
||||
[TearDown]
|
||||
public async Task Cleanup()
|
||||
{
|
||||
await IntegrationDb.Database.DropCollectionAsync("historicalConfigChanges");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("historicalConfigChanges");
|
||||
|
||||
await InitializeData();
|
||||
}
|
||||
public async Task Cleanup()
|
||||
{
|
||||
await IntegrationDb.Database.DropCollectionAsync("historicalConfigChanges");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("historicalConfigChanges");
|
||||
|
||||
await InitializeData();
|
||||
}
|
||||
|
||||
private HistoricalConfigChangesRepository _repository;
|
||||
|
||||
@@ -46,167 +52,183 @@ public class HistoricalConfigChangesRepositoryTest
|
||||
|
||||
private Mock<ILogger<HistoricalConfigChangesRepository>> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Seeds the repository with a series of historical configuration change records for an observation configuration
|
||||
/// (Hemoglobina), illustrating successive code updates from "54321" to "xxxxx" to "11111" to "99999" under the "adas" user.
|
||||
/// </summary>
|
||||
private async Task InitializeData()
|
||||
{
|
||||
var id = ObjectId.GenerateNewId();
|
||||
HistoricalConfigChanges historicalConfigChanges1 = new()
|
||||
{
|
||||
//Id = ObjectId.GenerateNewId(),
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "adas",
|
||||
OldConfig = new ConfigObservation
|
||||
var id = ObjectId.GenerateNewId();
|
||||
HistoricalConfigChanges historicalConfigChanges1 = new()
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "54321",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
//Id = ObjectId.GenerateNewId(),
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "adas",
|
||||
OldConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "54321",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "xxxxx",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(historicalConfigChanges1);
|
||||
|
||||
HistoricalConfigChanges historicalConfigChanges2 = new()
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "xxxxx",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(historicalConfigChanges1);
|
||||
|
||||
HistoricalConfigChanges historicalConfigChanges2 = new()
|
||||
{
|
||||
//Id = ObjectId.GenerateNewId(),
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "adas",
|
||||
OldConfig = new ConfigObservation
|
||||
//Id = ObjectId.GenerateNewId(),
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "adas",
|
||||
OldConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "xxxxx",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "11111",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(historicalConfigChanges2);
|
||||
|
||||
HistoricalConfigChanges historicalConfigChanges3 = new()
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "xxxxx",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "11111",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(historicalConfigChanges2);
|
||||
|
||||
HistoricalConfigChanges historicalConfigChanges3 = new()
|
||||
{
|
||||
//Id = ObjectId.GenerateNewId(),
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "adas",
|
||||
OldConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "111111",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "99999",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(historicalConfigChanges3);
|
||||
}
|
||||
//Id = ObjectId.GenerateNewId(),
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "adas",
|
||||
OldConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "111111",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "99999",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(historicalConfigChanges3);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindAll</c> method returns a non-null collection containing exactly three historical configuration change records after a cleanup operation.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Get_HistoricalConfigChanges_returns_count_3()
|
||||
{
|
||||
await Cleanup();
|
||||
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.EqualTo(3));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task HistoricalConfigChanges_returns_diferent_document()
|
||||
{
|
||||
await Cleanup();
|
||||
var id = ObjectId.GenerateNewId();
|
||||
var resultList = await _repository.FindAll();
|
||||
var result = resultList.FirstOrDefault();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
|
||||
Debug.Assert(result != null, nameof(result) + " != null");
|
||||
HistoricalConfigChanges updatedHistoricalConfigChanges = new()
|
||||
public async Task Get_HistoricalConfigChanges_returns_count_3()
|
||||
{
|
||||
Id = result.Id,
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "admin",
|
||||
OldConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "54321",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
await Cleanup();
|
||||
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.EqualTo(3));
|
||||
}
|
||||
|
||||
|
||||
var updated = await _repository.Update(updatedHistoricalConfigChanges);
|
||||
using (Assert.EnterMultipleScope())
|
||||
/// <summary>
|
||||
/// Verifies that the repository <c>Update</c> operation for a <see cref="HistoricalConfigChanges"/> document returns a non-null result whose properties correspond to the updated record, after cleaning up existing data and retrieving an existing entry to be modified.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task HistoricalConfigChanges_returns_diferent_document()
|
||||
{
|
||||
Assert.That(updated, Is.Not.Null);
|
||||
Assert.That(result.Time, Is.EqualTo(updated?.Time));
|
||||
Assert.That(result.Id, Is.EqualTo(updated?.Id));
|
||||
Assert.That(result.Username, Is.EqualTo(updated?.Username));
|
||||
Assert.That(result.ConfigType, Is.EqualTo(updated?.ConfigType));
|
||||
Assert.That(result.OldConfig, Is.EqualTo(updated?.OldConfig));
|
||||
Assert.That(result.NewConfig, Is.EqualTo(updated?.NewConfig));
|
||||
};
|
||||
}
|
||||
await Cleanup();
|
||||
var id = ObjectId.GenerateNewId();
|
||||
var resultList = await _repository.FindAll();
|
||||
var result = resultList.FirstOrDefault();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
|
||||
Debug.Assert(result != null, nameof(result) + " != null");
|
||||
HistoricalConfigChanges updatedHistoricalConfigChanges = new()
|
||||
{
|
||||
Id = result.Id,
|
||||
ConfigType = DisplayConfigEnums.ConfigTypes.ObservationCfg,
|
||||
Time = DateTime.UtcNow,
|
||||
Username = "admin",
|
||||
OldConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "12345",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson(),
|
||||
NewConfig = new ConfigObservation
|
||||
{
|
||||
Id = id,
|
||||
Name = "Hemoglobina",
|
||||
Code = "54321",
|
||||
CodingSystem = "SNM"
|
||||
}.ToJson()
|
||||
};
|
||||
|
||||
|
||||
var updated = await _repository.Update(updatedHistoricalConfigChanges);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(updated, Is.Not.Null);
|
||||
Assert.That(result.Time, Is.EqualTo(updated?.Time));
|
||||
Assert.That(result.Id, Is.EqualTo(updated?.Id));
|
||||
Assert.That(result.Username, Is.EqualTo(updated?.Username));
|
||||
Assert.That(result.ConfigType, Is.EqualTo(updated?.ConfigType));
|
||||
Assert.That(result.OldConfig, Is.EqualTo(updated?.OldConfig));
|
||||
Assert.That(result.NewConfig, Is.EqualTo(updated?.NewConfig));
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="_repository"/>.FindLastHistoricalConfigChangesByUser returns exactly three historical configuration changes for the user "adas" after cleanup.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindLastHistoricalConfigChangesByUser_returns_3()
|
||||
{
|
||||
await Cleanup();
|
||||
var result = await _repository.FindLastHistoricalConfigChangesByUser("adas");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.EqualTo(3));
|
||||
}
|
||||
public async Task FindLastHistoricalConfigChangesByUser_returns_3()
|
||||
{
|
||||
await Cleanup();
|
||||
var result = await _repository.FindLastHistoricalConfigChangesByUser("adas");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.EqualTo(3));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that deleting a historical config change entry reduces the total count of records from three to two in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_HistoricalConfigChanges_returns_count_2()
|
||||
{
|
||||
await Cleanup();
|
||||
var resultList = await _repository.FindAll();
|
||||
Assert.That(resultList, Has.Count.EqualTo(3));
|
||||
|
||||
var result = resultList.FirstOrDefault();
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Debug.Assert(result != null, nameof(result) + " != null");
|
||||
var deleted = await _repository.DeleteAsync(result.Id);
|
||||
|
||||
Assert.That(deleted, Is.Not.Null);
|
||||
|
||||
var resultAfterDelete = await _repository.FindAll();
|
||||
Assert.That(resultAfterDelete, Has.Count.EqualTo(2));
|
||||
}
|
||||
public async Task Delete_HistoricalConfigChanges_returns_count_2()
|
||||
{
|
||||
await Cleanup();
|
||||
var resultList = await _repository.FindAll();
|
||||
Assert.That(resultList, Has.Count.EqualTo(3));
|
||||
|
||||
var result = resultList.FirstOrDefault();
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Debug.Assert(result != null, nameof(result) + " != null");
|
||||
var deleted = await _repository.DeleteAsync(result.Id);
|
||||
|
||||
Assert.That(deleted, Is.Not.Null);
|
||||
|
||||
var resultAfterDelete = await _repository.FindAll();
|
||||
Assert.That(resultAfterDelete, Has.Count.EqualTo(2));
|
||||
}
|
||||
}
|
||||
@@ -17,48 +17,60 @@ public class IntegrationDb
|
||||
public static IMongoDatabase Database { get; private set; } = null!;
|
||||
public static string DatabaseName { get; } = "IntegrationTestDb";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the MongoDB integration test environment by starting a MongoDB runner, configuring MongoDB conventions and BSON class mappings, establishing a client from the runner's connection string, and obtaining the target database used by integration tests.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public void InitIntegrationTests()
|
||||
{
|
||||
StartMongoDbRunner().Wait();
|
||||
MongoDbHostBuilderExtension.ConfigureMongoDbConventions();
|
||||
MongoDbHostBuilderExtension.ConfigureRegisterMapClass();
|
||||
Client = new MongoClient(Runner?.ConnectionString);
|
||||
Database = Client.GetDatabase(DatabaseName);
|
||||
}
|
||||
public void InitIntegrationTests()
|
||||
{
|
||||
StartMongoDbRunner().Wait();
|
||||
MongoDbHostBuilderExtension.ConfigureMongoDbConventions();
|
||||
MongoDbHostBuilderExtension.ConfigureRegisterMapClass();
|
||||
Client = new MongoClient(Runner?.ConnectionString);
|
||||
Database = Client.GetDatabase(DatabaseName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the MongoDB test runner and waits for the server to become available by issuing a ping command, retrying on failure until the configured timeout is reached.
|
||||
/// If the server does not become available within the timeout, the runner is disposed and a <see cref="TimeoutException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <exception cref="TimeoutException">Thrown when the MongoDB server does not respond within the configured timeout period.</exception>
|
||||
private static async Task StartMongoDbRunner()
|
||||
{
|
||||
Runner = MongoDbRunner.Start();
|
||||
|
||||
// Wait for the MongoDB server to become available or timeout.
|
||||
var startTime = DateTime.UtcNow;
|
||||
while (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(TimeoutInSeconds))
|
||||
try
|
||||
{
|
||||
var testClient = new MongoClient(Runner.ConnectionString);
|
||||
var adminDb = testClient.GetDatabase("admin");
|
||||
await adminDb.RunCommandAsync((Command<BsonDocument>)"{ping:1}");
|
||||
return; // MongoDB server is available, continue.
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Retry after a short delay.
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
// Timeout reached, dispose the runner and throw an exception.
|
||||
Runner.Dispose();
|
||||
throw new TimeoutException("Timeout while starting MongoDB server.");
|
||||
}
|
||||
{
|
||||
Runner = MongoDbRunner.Start();
|
||||
|
||||
// Wait for the MongoDB server to become available or timeout.
|
||||
var startTime = DateTime.UtcNow;
|
||||
while (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(TimeoutInSeconds))
|
||||
try
|
||||
{
|
||||
var testClient = new MongoClient(Runner.ConnectionString);
|
||||
var adminDb = testClient.GetDatabase("admin");
|
||||
await adminDb.RunCommandAsync((Command<BsonDocument>)"{ping:1}");
|
||||
return; // MongoDB server is available, continue.
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Retry after a short delay.
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
// Timeout reached, dispose the runner and throw an exception.
|
||||
Runner.Dispose();
|
||||
throw new TimeoutException("Timeout while starting MongoDB server.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs one-time teardown for integration tests by disposing the <see cref="Client"/> and <see cref="Runner"/> resources.
|
||||
/// Safely handles cases where either resource has not been initialized by using null-conditional disposal.
|
||||
/// </summary>
|
||||
[OneTimeTearDown]
|
||||
public void TeardownIntegrationTests()
|
||||
{
|
||||
Client?.Dispose();
|
||||
Runner?.Dispose();
|
||||
//_runner = null;
|
||||
//_client = null;
|
||||
//_fakeDb = null;
|
||||
}
|
||||
public void TeardownIntegrationTests()
|
||||
{
|
||||
Client?.Dispose();
|
||||
Runner?.Dispose();
|
||||
//_runner = null;
|
||||
//_client = null;
|
||||
//_fakeDb = null;
|
||||
}
|
||||
}
|
||||
@@ -10,129 +10,149 @@ namespace adas_core.Test.Repositories;
|
||||
[TestFixture]
|
||||
public class MasterListRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time initialization for the test fixture by configuring <see cref="ApiSettings"/> with the expected master list property names, resetting the "MasterLists" collection in the integration database, and creating a <see cref="MasterListRepository{MasterList}"/> instance for use across tests.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
// Set up MongoDB connection
|
||||
// var client = new MongoClient("mongodb://localhost:27017");
|
||||
// _database = client.GetDatabase("TestDatabase");
|
||||
|
||||
// Initialize ApiSettings
|
||||
_apiSettings = new ApiSettings
|
||||
public async Task Init()
|
||||
{
|
||||
AltableOptionList = "altableOptionList",
|
||||
AllergyList = "allergyList",
|
||||
DestinationList = "destinationList",
|
||||
DiagnosisList = "diagnosisList",
|
||||
DischargeStatusList = "dischargeStatusList",
|
||||
DoctorList = "doctorList",
|
||||
DoctorTypeList = "doctorTypeList",
|
||||
InternalDestinationList = "internalDestinationList",
|
||||
InsulationList = "insulationList",
|
||||
LanguageBarrierList = "languageBarrierList",
|
||||
MobilityOptionList = "mobilityOptionList",
|
||||
OriginList = "originList",
|
||||
PatientStatusList = "patientStatusList",
|
||||
ProcedureList = "procedureList",
|
||||
TestList = "testList",
|
||||
ServiceList = "serviceList",
|
||||
TherapeuticCeilingList = "therapeuticCeilingList",
|
||||
TreatmentList = "treatmentList",
|
||||
VisitOptionList = "visitOptionList",
|
||||
AccessControlList = "accessControlList"
|
||||
};
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
|
||||
// Insert sample data
|
||||
await IntegrationDb.Database.DropCollectionAsync("MasterLists");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("MasterLists");
|
||||
|
||||
// Create the repository instance
|
||||
_repository = new MasterListRepository<MasterList>(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
// var masterListCollection = _database.GetCollection<MasterList>("MasterLists");
|
||||
// var sampleData = new List<MasterList>
|
||||
// {
|
||||
// new MasterList { Id = ObjectId.GenerateNewId(), Name = "Sample MasterList 1" },
|
||||
// new MasterList { Id = ObjectId.GenerateNewId(), Name = "Sample MasterList 2" }
|
||||
// };
|
||||
// await masterListCollection.InsertManyAsync(sampleData);
|
||||
}
|
||||
// Set up MongoDB connection
|
||||
// var client = new MongoClient("mongodb://localhost:27017");
|
||||
// _database = client.GetDatabase("TestDatabase");
|
||||
|
||||
// Initialize ApiSettings
|
||||
_apiSettings = new ApiSettings
|
||||
{
|
||||
AltableOptionList = "altableOptionList",
|
||||
AllergyList = "allergyList",
|
||||
DestinationList = "destinationList",
|
||||
DiagnosisList = "diagnosisList",
|
||||
DischargeStatusList = "dischargeStatusList",
|
||||
DoctorList = "doctorList",
|
||||
DoctorTypeList = "doctorTypeList",
|
||||
InternalDestinationList = "internalDestinationList",
|
||||
InsulationList = "insulationList",
|
||||
LanguageBarrierList = "languageBarrierList",
|
||||
MobilityOptionList = "mobilityOptionList",
|
||||
OriginList = "originList",
|
||||
PatientStatusList = "patientStatusList",
|
||||
ProcedureList = "procedureList",
|
||||
TestList = "testList",
|
||||
ServiceList = "serviceList",
|
||||
TherapeuticCeilingList = "therapeuticCeilingList",
|
||||
TreatmentList = "treatmentList",
|
||||
VisitOptionList = "visitOptionList",
|
||||
AccessControlList = "accessControlList"
|
||||
};
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
|
||||
// Insert sample data
|
||||
await IntegrationDb.Database.DropCollectionAsync("MasterLists");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("MasterLists");
|
||||
|
||||
// Create the repository instance
|
||||
_repository = new MasterListRepository<MasterList>(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
// var masterListCollection = _database.GetCollection<MasterList>("MasterLists");
|
||||
// var sampleData = new List<MasterList>
|
||||
// {
|
||||
// new MasterList { Id = ObjectId.GenerateNewId(), Name = "Sample MasterList 1" },
|
||||
// new MasterList { Id = ObjectId.GenerateNewId(), Name = "Sample MasterList 2" }
|
||||
// };
|
||||
// await masterListCollection.InsertManyAsync(sampleData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs one-time cleanup after integration test execution by dropping the <c>MasterLists</c> collection from the integration test database to ensure a clean state between test runs.
|
||||
/// </summary>
|
||||
[OneTimeTearDown]
|
||||
public async Task Cleanup()
|
||||
{
|
||||
// Clean up database after tests
|
||||
await IntegrationDb.Database.DropCollectionAsync("MasterLists");
|
||||
}
|
||||
public async Task Cleanup()
|
||||
{
|
||||
// Clean up database after tests
|
||||
await IntegrationDb.Database.DropCollectionAsync("MasterLists");
|
||||
}
|
||||
|
||||
private MasterListRepository<MasterList> _repository;
|
||||
private ApiSettings _apiSettings;
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="MasterList"/> entities are correctly persisted in the repository via <c>InsertOneAsync</c>,
|
||||
/// by inserting an entity and confirming it can be retrieved by its identifier using the default locale.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOneAsync_ShouldInsertEntity()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "Test MasterList" };
|
||||
|
||||
// Act
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
await _repository.GetAll();
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("Test MasterList"));
|
||||
}
|
||||
public async Task InsertOneAsync_ShouldInsertEntity()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "Test MasterList" };
|
||||
|
||||
// Act
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
await _repository.GetAll();
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("Test MasterList"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's Delete operation successfully removes a MasterList entity, ensuring that a subsequent lookup by id returns no result.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_ShouldDeleteEntity()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "ToDelete MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
|
||||
// Act
|
||||
await _repository.Delete(masterList.Id);
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task Delete_ShouldDeleteEntity()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "ToDelete MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
|
||||
// Act
|
||||
await _repository.Delete(masterList.Id);
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>Update</c> method successfully persists changes to an existing <see cref="MasterList"/> entity, allowing the modified record to be retrieved by its identifier with the updated values.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Update_ShouldUpdateEntity()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "Original MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
masterList.Name = "Updated MasterList";
|
||||
|
||||
// Act
|
||||
await _repository.Update(masterList);
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("Updated MasterList"));
|
||||
}
|
||||
public async Task Update_ShouldUpdateEntity()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "Original MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
masterList.Name = "Updated MasterList";
|
||||
|
||||
// Act
|
||||
await _repository.Update(masterList);
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("Updated MasterList"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindById method returns the matching entity when a master list with the specified identifier exists in the data store.
|
||||
/// </summary>
|
||||
/// <returns>A task representing the asynchronous test execution.</returns>
|
||||
[Test]
|
||||
public async Task FindById_ShouldReturnEntity_WhenFound()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "FindById MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("FindById MasterList"));
|
||||
}
|
||||
public async Task FindById_ShouldReturnEntity_WhenFound()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "FindById MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(masterList.Id, LocaleEnum.Default);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("FindById MasterList"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindById_WithDifferentLocale_ShouldReturnEntity_WhenFound()
|
||||
@@ -233,30 +253,36 @@ public class MasterListRepositoryTest
|
||||
Assert.That(resultEs?.Options[0].Name, Is.EqualTo("Opción 1"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindByName method returns the matching entity when an entity with the specified name exists in the data store.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByName_ShouldReturnEntity_WhenFound()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "FindByName MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByName(masterList.Name);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("FindByName MasterList"));
|
||||
}
|
||||
public async Task FindByName_ShouldReturnEntity_WhenFound()
|
||||
{
|
||||
// Arrange
|
||||
var masterList = new MasterList { Id = ObjectId.GenerateNewId(), Name = "FindByName MasterList" };
|
||||
await _repository.InsertOneAsync(masterList);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByName(masterList.Name);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo("FindByName MasterList"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's GetAll method returns all entities, ensuring the result contains at least two items.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAll_ShouldReturnAllEntities()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.GetAll();
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Count(), Is.GreaterThanOrEqualTo(2));
|
||||
}
|
||||
public async Task GetAll_ShouldReturnAllEntities()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.GetAll();
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Count(), Is.GreaterThanOrEqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMasterListByIdAndSearchOptiionsByLocale()
|
||||
|
||||
@@ -12,31 +12,34 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class MedicineRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time initialization for integration tests by seeding the medicines collection with a test record and verifying it can be retrieved by code or note.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
_testMedicine = new Medicine
|
||||
public async Task Init()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("medicines");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("medicines");
|
||||
|
||||
_repository = new MedicineRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(_testMedicine);
|
||||
|
||||
var result = _repository.GetMedicineByCodeOrNote(["12345"]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
_testMedicine = new Medicine
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("medicines");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("medicines");
|
||||
|
||||
_repository = new MedicineRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(_testMedicine);
|
||||
|
||||
var result = _repository.GetMedicineByCodeOrNote(["12345"]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
private MedicineRepository _repository = null!;
|
||||
|
||||
@@ -49,14 +52,17 @@ public class MedicineRepositoryTest
|
||||
|
||||
private IOptions<ApiSettings> _optionsApiSettings = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetMedicineByCodeOrNote</c> returns a non-null, empty list when invoked with an array containing an empty string.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Get_Medicines_Of_Treatments_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.GetMedicineByCodeOrNote([""]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
public async Task Get_Medicines_Of_Treatments_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.GetMedicineByCodeOrNote([""]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Medicines_Of_Treatments_By_Code_When_Have_Code_And_Notes_Return_Paracetamol()
|
||||
@@ -83,50 +89,63 @@ public class MedicineRepositoryTest
|
||||
Assert.That(result, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the repository returns a non-null medicine when a valid medicine code is found.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetMedicine_Find_Code_Return_Medicine()
|
||||
{
|
||||
var result = await _repository.GetMedicine("12345");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMedicine_Not_Find_Code_Return_Empty()
|
||||
{
|
||||
var result = await _repository.GetMedicine("123456");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMedicine_Find_Note_Return_Medicine()
|
||||
{
|
||||
var result = await _repository.GetMedicine("note1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateMedicine_Return_Medicine()
|
||||
{
|
||||
var updateMedicine = new Medicine
|
||||
public async Task GetMedicine_Find_Code_Return_Medicine()
|
||||
{
|
||||
Id = _testMedicine.Id,
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1", "note2", "note3"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
var result = await _repository.UpdateMedicine(updateMedicine);
|
||||
var resultUpdate = await _repository.GetMedicineById(_testMedicine.Id);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
|
||||
var result = await _repository.GetMedicine("12345");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate?.Notes != null && resultUpdate.Notes.Contains("note3"), Is.True);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>GetMedicine</c> method returns <c>null</c> when the provided medicine code does not match any existing record.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetMedicine_Not_Find_Code_Return_Empty()
|
||||
{
|
||||
var result = await _repository.GetMedicine("123456");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns a non-null medicine when a medicine is found
|
||||
/// by the supplied note identifier ("note1"), confirming successful lookup by note.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetMedicine_Find_Note_Return_Medicine()
|
||||
{
|
||||
var result = await _repository.GetMedicine("note1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that UpdateMedicine returns the updated medicine and that the changes are persisted and retrievable via GetMedicineById, including the updated notes collection.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateMedicine_Return_Medicine()
|
||||
{
|
||||
var updateMedicine = new Medicine
|
||||
{
|
||||
Id = _testMedicine.Id,
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1", "note2", "note3"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
var result = await _repository.UpdateMedicine(updateMedicine);
|
||||
var resultUpdate = await _repository.GetMedicineById(_testMedicine.Id);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate?.Notes != null && resultUpdate.Notes.Contains("note3"), Is.True);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -27,97 +27,109 @@ public class MongodbMigrationTest
|
||||
private static readonly DateTime Now = DateTime.Now;
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
/// <summary>
|
||||
/// Performs one-time initialization for the test fixture by dropping and recreating the "patients" collection, instantiating the PatientRepository, and seeding it with three test Patient records (one of which has a discharge time set to the current time) to verify they are persisted.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients");
|
||||
|
||||
_repository = new PatientRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
var patients = new List<Patient>
|
||||
public async Task Init()
|
||||
{
|
||||
new ()
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients");
|
||||
|
||||
_repository = new PatientRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
var patients = new List<Patient>
|
||||
{
|
||||
Id = PatientId,
|
||||
PatientId = "patientId1",
|
||||
PointOfCareId = ObjectId.GenerateNewId(),
|
||||
Bed = "bed1",
|
||||
PatientNumber = "patientNumber1",
|
||||
Person = new Person
|
||||
new ()
|
||||
{
|
||||
FirstName = "firstName1",
|
||||
LastName = "lastName1",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
Id = PatientId,
|
||||
PatientId = "patientId1",
|
||||
PointOfCareId = ObjectId.GenerateNewId(),
|
||||
Bed = "bed1",
|
||||
PatientNumber = "patientNumber1",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName1",
|
||||
LastName = "lastName1",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
},
|
||||
DisTime = Now
|
||||
},
|
||||
DisTime = Now
|
||||
},
|
||||
new ()
|
||||
{
|
||||
PatientId = "patientId2",
|
||||
PointOfCareId = ObjectId.GenerateNewId(),
|
||||
Bed = "bed2",
|
||||
PatientNumber = "patientNumber2",
|
||||
Person = new Person
|
||||
new ()
|
||||
{
|
||||
FirstName = "firstName2",
|
||||
LastName = "lastName2",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
},
|
||||
new ()
|
||||
{
|
||||
PatientId = "patientId3",
|
||||
PointOfCareId = ObjectId.GenerateNewId(),
|
||||
Bed = "bed3",
|
||||
PatientNumber = "patientNumber3",
|
||||
Person = new Person
|
||||
PatientId = "patientId2",
|
||||
PointOfCareId = ObjectId.GenerateNewId(),
|
||||
Bed = "bed2",
|
||||
PatientNumber = "patientNumber2",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName2",
|
||||
LastName = "lastName2",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
},
|
||||
new ()
|
||||
{
|
||||
FirstName = "firstName3",
|
||||
LastName = "lastName3",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
PatientId = "patientId3",
|
||||
PointOfCareId = ObjectId.GenerateNewId(),
|
||||
Bed = "bed3",
|
||||
PatientNumber = "patientNumber3",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName3",
|
||||
LastName = "lastName3",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await _repository.InsertManyAsync(patients);
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(3));
|
||||
}
|
||||
};
|
||||
|
||||
await _repository.InsertManyAsync(patients);
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(3));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs one-time cleanup after integration tests by dropping the <c>patients</c> and <c>__migrations</c> collections from the integration database, ensuring a clean state for subsequent test runs.
|
||||
/// </summary>
|
||||
[OneTimeTearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
IntegrationDb.Database.DropCollection("patients");
|
||||
IntegrationDb.Database.DropCollection("__migrations");
|
||||
}
|
||||
public void Teardown()
|
||||
{
|
||||
IntegrationDb.Database.DropCollection("patients");
|
||||
IntegrationDb.Database.DropCollection("__migrations");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the database is detected as outdated by creating a runner and asserting that <c>IsDatabaseUpToDate</c> returns <c>false</c> when using the primary read preference.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[Order(1)]
|
||||
public void IsDatabaseOutdated_ShouldReturnTrue()
|
||||
{
|
||||
var runner = CreateRunner();
|
||||
|
||||
var isUpToDate = runner.IsDatabaseUpToDate(ReadPreference.Primary);
|
||||
|
||||
Assert.That(isUpToDate, Is.False);
|
||||
}
|
||||
[Order(1)]
|
||||
public void IsDatabaseOutdated_ShouldReturnTrue()
|
||||
{
|
||||
var runner = CreateRunner();
|
||||
|
||||
var isUpToDate = runner.IsDatabaseUpToDate(ReadPreference.Primary);
|
||||
|
||||
Assert.That(isUpToDate, Is.False);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that after running the migration update to the latest version, the migration with ID 10 (version 0.1.0) is present among the applied migrations.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[Order(2)]
|
||||
public void AfterUpdateToLatest_MigrationShouldBeApplied()
|
||||
{
|
||||
var runner = CreateRunner();
|
||||
|
||||
runner.UpdateToLatest();
|
||||
var ids = GetAppliedMigrationIds();
|
||||
Assert.That(ids, Does.Contain(10)); // 0.1.0
|
||||
}
|
||||
[Order(2)]
|
||||
public void AfterUpdateToLatest_MigrationShouldBeApplied()
|
||||
{
|
||||
var runner = CreateRunner();
|
||||
|
||||
runner.UpdateToLatest();
|
||||
var ids = GetAppliedMigrationIds();
|
||||
Assert.That(ids, Does.Contain(10)); // 0.1.0
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunningMigrationsTwice_ShouldNotFail()
|
||||
@@ -132,25 +144,33 @@ public class MongodbMigrationTest
|
||||
}
|
||||
|
||||
// Helpers
|
||||
/// <summary>
|
||||
/// Creates and configures a <see cref="MigrationRunner"/> for executing database migrations, using a locator that scans the assembly containing the patient data update migration.
|
||||
/// </summary>
|
||||
/// <returns>A configured <see cref="MigrationRunner"/> bound to the integration database and the migrations collection.</returns>
|
||||
private MigrationRunner CreateRunner()
|
||||
{
|
||||
var locator = new MigrationLocator();
|
||||
locator.LookForMigrationsInAssembly(typeof(U_0_1_0_UpdateDataPatien).Assembly);
|
||||
return new MigrationRunner(
|
||||
IntegrationDb.Database,
|
||||
collectionName: "__migrations",
|
||||
migrationLocator: locator
|
||||
);
|
||||
}
|
||||
{
|
||||
var locator = new MigrationLocator();
|
||||
locator.LookForMigrationsInAssembly(typeof(U_0_1_0_UpdateDataPatien).Assembly);
|
||||
return new MigrationRunner(
|
||||
IntegrationDb.Database,
|
||||
collectionName: "__migrations",
|
||||
migrationLocator: locator
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the identifiers of all applied migrations from the "__migrations" collection in the integration database.
|
||||
/// </summary>
|
||||
/// <returns>A list of migration identifiers extracted from the "_id" field of each migration document.</returns>
|
||||
private List<int> GetAppliedMigrationIds()
|
||||
{
|
||||
var collection = IntegrationDb.Database.GetCollection<BsonDocument>("__migrations");
|
||||
|
||||
return collection
|
||||
.Find(FilterDefinition<BsonDocument>.Empty)
|
||||
.ToList()
|
||||
.Select(d => d["_id"].AsInt32)
|
||||
.ToList();
|
||||
}
|
||||
{
|
||||
var collection = IntegrationDb.Database.GetCollection<BsonDocument>("__migrations");
|
||||
|
||||
return collection
|
||||
.Find(FilterDefinition<BsonDocument>.Empty)
|
||||
.ToList()
|
||||
.Select(d => d["_id"].AsInt32)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -62,21 +62,25 @@ public class ObservationArchiveRepositoryTest
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>DeleteBeforeDate</c> method removes all patient observations
|
||||
/// dated before the specified cutoff, leaving only a single observation remaining in the collection.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var filter = Builders<PatientObservation>.Filter.Eq(p => p.PatientId, PatientId);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(filter);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var filter = Builders<PatientObservation>.Filter.Eq(p => p.PatientId, PatientId);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(filter);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(filter);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,62 +12,66 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class PatientArchiveRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for integration tests by seeding the patient archive collection
|
||||
/// with three predefined <see cref="Patient"/> records after resetting the collection.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient1 = new Patient
|
||||
public async Task Init()
|
||||
{
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed1",
|
||||
PatientNumber = "patientNumber1",
|
||||
Person = new Person
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient1 = new Patient
|
||||
{
|
||||
FirstName = "firstName1",
|
||||
LastName = "lastName1",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patient2 = new Patient
|
||||
{
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed2",
|
||||
PatientNumber = "patientNumber2",
|
||||
Person = new Person
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed1",
|
||||
PatientNumber = "patientNumber1",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName1",
|
||||
LastName = "lastName1",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patient2 = new Patient
|
||||
{
|
||||
FirstName = "firstName2",
|
||||
LastName = "lastName2",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patient3 = new Patient
|
||||
{
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed3",
|
||||
PatientNumber = "patientNumber3",
|
||||
Person = new Person
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed2",
|
||||
PatientNumber = "patientNumber2",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName2",
|
||||
LastName = "lastName2",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patient3 = new Patient
|
||||
{
|
||||
FirstName = "firstName3",
|
||||
LastName = "lastName3",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patient");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patient");
|
||||
|
||||
_repository = new PatientArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(patient1);
|
||||
await _repository.InsertOneAsync(patient2);
|
||||
await _repository.InsertOneAsync(patient3);
|
||||
}
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed3",
|
||||
PatientNumber = "patientNumber3",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName3",
|
||||
LastName = "lastName3",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patient");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patient");
|
||||
|
||||
_repository = new PatientArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(patient1);
|
||||
await _repository.InsertOneAsync(patient2);
|
||||
await _repository.InsertOneAsync(patient3);
|
||||
}
|
||||
|
||||
private PatientArchiveRepository _repository;
|
||||
|
||||
@@ -78,29 +82,40 @@ public class PatientArchiveRepositoryTest
|
||||
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the FindByPatientNumber repository method returns null when no record is found for the provided patient number.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientNumber_Not_Find_Return_null()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindByPatientNumber_Not_Find_Return_null()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindByPatientNumber method successfully retrieves a patient
|
||||
/// matching the provided patient number, ensuring the returned patient is not null and has
|
||||
/// the expected PatientNumber.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientNumber_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("patientNumber1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
}
|
||||
public async Task FindByPatientNumber_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("patientNumber1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindAll</c> method returns a non-null list containing the expected number of patient records.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAll_Return_List_Patients()
|
||||
{
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
}
|
||||
public async Task FindAll_Return_List_Patients()
|
||||
{
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
}
|
||||
}
|
||||
@@ -17,123 +17,130 @@ public class PatientRepositoryTest
|
||||
{
|
||||
//private static readonly ObjectId id = ObjectId.GenerateNewId();
|
||||
|
||||
/// <summary>
|
||||
/// One-time setup that prepares the integration test database by recreating the
|
||||
/// <c>patient</c>, <c>pointOfCares</c>, <c>units</c>, and <c>list_origin</c> collections
|
||||
/// and seeding them with five patients, their associated point of care, unit, and origin
|
||||
/// list records, then verifies that the initial bulk insert yields exactly five patient
|
||||
/// documents.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient1 = new Patient
|
||||
public async Task Init()
|
||||
{
|
||||
Id = PatientId,
|
||||
PatientId = "patientId1",
|
||||
UnitId = _unit1,
|
||||
PointOfCareId = _poc1.Id,
|
||||
PatientNumber = "patientNumber1",
|
||||
Person = new Person
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patient1 = new Patient
|
||||
{
|
||||
FirstName = "firstName1",
|
||||
LastName = "lastName1",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
},
|
||||
DisTime = Now,
|
||||
Origin = new OptionList
|
||||
Id = PatientId,
|
||||
PatientId = "patientId1",
|
||||
UnitId = _unit1,
|
||||
PointOfCareId = _poc1.Id,
|
||||
PatientNumber = "patientNumber1",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName1",
|
||||
LastName = "lastName1",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
},
|
||||
DisTime = Now,
|
||||
Origin = new OptionList
|
||||
{
|
||||
Id = OriginListOptionId,
|
||||
Name = "Urlogy"
|
||||
}
|
||||
};
|
||||
|
||||
var patient2 = new Patient
|
||||
{
|
||||
Id = OriginListOptionId,
|
||||
Name = "Urlogy"
|
||||
}
|
||||
};
|
||||
|
||||
var patient2 = new Patient
|
||||
{
|
||||
UnitId = _unit1,
|
||||
PatientId = "patientId2",
|
||||
PointOfCareId = _poc2.Id,
|
||||
PatientNumber = "patientNumber2",
|
||||
Person = new Person
|
||||
UnitId = _unit1,
|
||||
PatientId = "patientId2",
|
||||
PointOfCareId = _poc2.Id,
|
||||
PatientNumber = "patientNumber2",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName2",
|
||||
LastName = "lastName2",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patient3 = new Patient
|
||||
{
|
||||
FirstName = "firstName2",
|
||||
LastName = "lastName2",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patient3 = new Patient
|
||||
{
|
||||
UnitId = _unit1,
|
||||
PatientId = "patientId3",
|
||||
PointOfCareId = _poc3.Id,
|
||||
PatientNumber = "patientNumber3",
|
||||
Person = new Person
|
||||
UnitId = _unit1,
|
||||
PatientId = "patientId3",
|
||||
PointOfCareId = _poc3.Id,
|
||||
PatientNumber = "patientNumber3",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName3",
|
||||
LastName = "lastName3",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
var patient4 = new Patient
|
||||
{
|
||||
FirstName = "firstName3",
|
||||
LastName = "lastName3",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
var patient4 = new Patient
|
||||
{
|
||||
UnitId = _pocMoved.UnitId,
|
||||
PatientId = "patientId4",
|
||||
PointOfCareId = _pocMoved.Id,
|
||||
PatientNumber = "patientNumber4",
|
||||
Person = new Person
|
||||
UnitId = _pocMoved.UnitId,
|
||||
PatientId = "patientId4",
|
||||
PointOfCareId = _pocMoved.Id,
|
||||
PatientNumber = "patientNumber4",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName4",
|
||||
LastName = "lastName4",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
var patient5 = new Patient
|
||||
{
|
||||
FirstName = "firstName4",
|
||||
LastName = "lastName4",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
var patient5 = new Patient
|
||||
{
|
||||
UnitId = _pocPushed.UnitId,
|
||||
PatientId = "patientId5",
|
||||
PointOfCareId = _pocPushed.Id,
|
||||
PatientNumber = "patientNumber5",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName5",
|
||||
LastName = "lastName5",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patient");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patient");
|
||||
await IntegrationDb.Database.DropCollectionAsync("pointOfCares");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pointOfCares");
|
||||
await IntegrationDb.Database.DropCollectionAsync("units");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("units");
|
||||
await IntegrationDb.Database.DropCollectionAsync("list_origin");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("list_origin");
|
||||
|
||||
_repository = new PatientRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
_repositoryPoc = new PointOfCareRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
_repositoryUnit = new UnitRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
_repositoryList = new MasterListRepository<OriginList>(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repositoryPoc.InsertOneAsync(_poc1);
|
||||
await _repositoryPoc.InsertOneAsync(_poc2);
|
||||
await _repositoryPoc.InsertOneAsync(_poc3);
|
||||
await _repositoryPoc.InsertOneAsync(_pocMoved);
|
||||
await _repositoryPoc.InsertOneAsync(_pocPushed);
|
||||
await _repository.InsertOneAsync(patient1);
|
||||
await _repository.InsertOneAsync(patient2);
|
||||
await _repository.InsertOneAsync(patient3);
|
||||
await _repository.InsertOneAsync(patient4);
|
||||
await _repository.InsertOneAsync(patient5);
|
||||
await _repositoryUnit.InsertOneAsync(_unit);
|
||||
await _repositoryList.InsertOneAsync(_originList);
|
||||
|
||||
await _repository.FindByPatientNumber("patientNumber1");
|
||||
|
||||
await _repository.InsertManyAsync([patient1, patient2, patient3, patient4, patient5]);
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(5));
|
||||
}
|
||||
UnitId = _pocPushed.UnitId,
|
||||
PatientId = "patientId5",
|
||||
PointOfCareId = _pocPushed.Id,
|
||||
PatientNumber = "patientNumber5",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName5",
|
||||
LastName = "lastName5",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patient");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patient");
|
||||
await IntegrationDb.Database.DropCollectionAsync("pointOfCares");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pointOfCares");
|
||||
await IntegrationDb.Database.DropCollectionAsync("units");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("units");
|
||||
await IntegrationDb.Database.DropCollectionAsync("list_origin");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("list_origin");
|
||||
|
||||
_repository = new PatientRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
_repositoryPoc = new PointOfCareRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
_repositoryUnit = new UnitRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
_repositoryList = new MasterListRepository<OriginList>(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repositoryPoc.InsertOneAsync(_poc1);
|
||||
await _repositoryPoc.InsertOneAsync(_poc2);
|
||||
await _repositoryPoc.InsertOneAsync(_poc3);
|
||||
await _repositoryPoc.InsertOneAsync(_pocMoved);
|
||||
await _repositoryPoc.InsertOneAsync(_pocPushed);
|
||||
await _repository.InsertOneAsync(patient1);
|
||||
await _repository.InsertOneAsync(patient2);
|
||||
await _repository.InsertOneAsync(patient3);
|
||||
await _repository.InsertOneAsync(patient4);
|
||||
await _repository.InsertOneAsync(patient5);
|
||||
await _repositoryUnit.InsertOneAsync(_unit);
|
||||
await _repositoryList.InsertOneAsync(_originList);
|
||||
|
||||
await _repository.FindByPatientNumber("patientNumber1");
|
||||
|
||||
await _repository.InsertManyAsync([patient1, patient2, patient3, patient4, patient5]);
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(5));
|
||||
}
|
||||
|
||||
private PatientRepository _repository;
|
||||
private PointOfCareRepository _repositoryPoc;
|
||||
@@ -222,136 +229,167 @@ public class PatientRepositoryTest
|
||||
UnitId = ObjectId.GenerateNewId()
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that _repository.FindInActivePoC returns a non-null result containing exactly three inactive PoC entries.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindInActivePoC()
|
||||
{
|
||||
var result = await _repository.FindInActivePoC();
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindInInactivePoC()
|
||||
{
|
||||
var result = await _repository.FindInInactivePoC();
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindById_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindById(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByPatientNumber_Not_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByPatientNumber_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("patientNumber1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindAll_Return_List_Patients()
|
||||
{
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_with_base_UpdateOneAsync()
|
||||
{
|
||||
var patient = new Patient
|
||||
public async Task FindInActivePoC()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed",
|
||||
PatientNumber = "patientNumber",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patientUpdate = new Patient
|
||||
{
|
||||
Id = patient.Id,
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed",
|
||||
PatientNumber = "patientNumberUpdate",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(patient);
|
||||
|
||||
var result = await _repository.FindByPatientNumber("patientNumberUpdate");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
|
||||
await _repository.Update(patientUpdate);
|
||||
|
||||
var resultUpdate = await _repository.FindByPatientNumber("patientNumberUpdate");
|
||||
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.PatientNumber, Is.EqualTo("patientNumberUpdate"));
|
||||
|
||||
await _repository.Delete(patient.Id);
|
||||
}
|
||||
var result = await _repository.FindInActivePoC();
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that _repository.FindInInactivePoC() returns a non-null collection containing exactly two inactive PoC records.
|
||||
/// </summary>
|
||||
/// <returns>A Task representing the asynchronous test execution.</returns>
|
||||
[Test]
|
||||
public async Task Delete()
|
||||
{
|
||||
var patientDelete = new Patient
|
||||
public async Task FindInInactivePoC()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bedDelete",
|
||||
PatientNumber = "patientNumberDelete",
|
||||
Person = new Person
|
||||
var result = await _repository.FindInInactivePoC();
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that FindById returns the expected <c>Patient</c> when a valid patient identifier is provided, ensuring the result is not null and the <c>PatientNumber</c> matches the expected value.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindById(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindByPatientNumber</c> method returns <c>null</c> when invoked with an empty patient number, confirming the not-found scenario for blank input.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientNumber_Not_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindByPatientNumber</c> method successfully retrieves
|
||||
/// a patient when called with a valid patient number, returning a non-null result
|
||||
/// with a matching <c>PatientNumber</c>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientNumber_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientNumber("patientNumber1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindAll</c> method returns a non-null list containing all expected patient records (five entries).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAll_Return_List_Patients()
|
||||
{
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.EqualTo(5));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>Update</c> method successfully updates an existing patient record
|
||||
/// by confirming that the updated <c>PatientNumber</c> becomes findable after the update, while ensuring
|
||||
/// the new value is not present prior to the update operation. Also validates that the updated record
|
||||
/// is persisted with the modified value and that the patient can be cleaned up via <c>Delete</c>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Update_with_base_UpdateOneAsync()
|
||||
{
|
||||
var patient = new Patient
|
||||
{
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed",
|
||||
PatientNumber = "patientNumber",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
var patientUpdate = new Patient
|
||||
{
|
||||
Id = patient.Id,
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bed",
|
||||
PatientNumber = "patientNumberUpdate",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(patient);
|
||||
|
||||
var result = await _repository.FindByPatientNumber("patientNumberUpdate");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
|
||||
await _repository.Update(patientUpdate);
|
||||
|
||||
var resultUpdate = await _repository.FindByPatientNumber("patientNumberUpdate");
|
||||
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.PatientNumber, Is.EqualTo("patientNumberUpdate"));
|
||||
|
||||
await _repository.Delete(patient.Id);
|
||||
}
|
||||
|
||||
await _repository.InsertOneAsync(patientDelete);
|
||||
|
||||
var result = await _repository.FindByPatientNumber("patientNumberDelete");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
|
||||
await _repository.Delete(patientDelete.Id);
|
||||
|
||||
var resultDelete = await _repository.FindByPatientNumber("patientNumberDelete");
|
||||
|
||||
Assert.That(resultDelete, Is.Null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that a patient can be successfully deleted from the repository by inserting a patient,
|
||||
/// confirming it exists, deleting it, and then confirming it is no longer retrievable.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete()
|
||||
{
|
||||
var patientDelete = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitString = "PointOfCare",
|
||||
Bed = "bedDelete",
|
||||
PatientNumber = "patientNumberDelete",
|
||||
Person = new Person
|
||||
{
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
BirthDate = new DateTime(),
|
||||
Gender = PatientEnum.Gender.Male
|
||||
}
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(patientDelete);
|
||||
|
||||
var result = await _repository.FindByPatientNumber("patientNumberDelete");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
|
||||
await _repository.Delete(patientDelete.Id);
|
||||
|
||||
var resultDelete = await _repository.FindByPatientNumber("patientNumberDelete");
|
||||
|
||||
Assert.That(resultDelete, Is.Null);
|
||||
}
|
||||
|
||||
|
||||
// [Test]
|
||||
@@ -390,25 +428,29 @@ public class PatientRepositoryTest
|
||||
// await _repository.Delete(patient.Id);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the attending doctor of a point of care entry can be successfully updated with a new doctor.
|
||||
/// Verifies that after the update, the entry retrieved by point of care reflects the new attending doctor's information.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateAttendingDoctor()
|
||||
{
|
||||
var doctor = new Person
|
||||
public async Task UpdateAttendingDoctor()
|
||||
{
|
||||
FirstName = "firstNameDoctor2",
|
||||
LastName = "lastNameDoctor2",
|
||||
Gender = PatientEnum.Gender.Female
|
||||
};
|
||||
|
||||
var result = await _repository.FindByPointOfCare(_poc1.Id);
|
||||
|
||||
await _repository.UpdateAttendingDoctor(result.First().Id, doctor);
|
||||
|
||||
var resultUpdate = await _repository.FindByPointOfCare(_poc1.Id);
|
||||
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.First().AttendingDoctor?.FirstName, Is.EqualTo("firstNameDoctor2"));
|
||||
}
|
||||
var doctor = new Person
|
||||
{
|
||||
FirstName = "firstNameDoctor2",
|
||||
LastName = "lastNameDoctor2",
|
||||
Gender = PatientEnum.Gender.Female
|
||||
};
|
||||
|
||||
var result = await _repository.FindByPointOfCare(_poc1.Id);
|
||||
|
||||
await _repository.UpdateAttendingDoctor(result.First().Id, doctor);
|
||||
|
||||
var resultUpdate = await _repository.FindByPointOfCare(_poc1.Id);
|
||||
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.First().AttendingDoctor?.FirstName, Is.EqualTo("firstNameDoctor2"));
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task UpdatePatientData_UpdatePatientNumber_true()
|
||||
@@ -577,13 +619,16 @@ public class PatientRepositoryTest
|
||||
// await _repository.Delete(patient1.Id);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that _repository.FindByPatientId returns <c>null</c> when no patient is found for the provided patient identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientId_Not_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientId("");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindByPatientId_Not_Find_Return_Patient()
|
||||
{
|
||||
var result = await _repository.FindByPatientId("");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task FindByPatientId_Find_Return_Patient()
|
||||
@@ -594,31 +639,40 @@ public class PatientRepositoryTest
|
||||
// Assert.That(result.PatientNumber, Is.EqualTo("patientNumber1"));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns a non-null and non-empty collection of patients when searching by the identifier of an existing point of care.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPointOfCare_Find_Return_Patients()
|
||||
{
|
||||
var result = await _repository.FindByPointOfCare(_poc1.Id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
// Assert.That(result.Count.Equals(1));
|
||||
}
|
||||
public async Task FindByPointOfCare_Find_Return_Patients()
|
||||
{
|
||||
var result = await _repository.FindByPointOfCare(_poc1.Id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
// Assert.That(result.Count.Equals(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that _repository.FindByPointOfCare returns a non-null empty collection when no patients match the provided point of care identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPointOfCare_Not_Find_Return_Patients()
|
||||
{
|
||||
var result = await _repository.FindByPointOfCare(ObjectId.GenerateNewId());
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
public async Task FindByPointOfCare_Not_Find_Return_Patients()
|
||||
{
|
||||
var result = await _repository.FindByPointOfCare(ObjectId.GenerateNewId());
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns a non-null and non-empty collection of discharged patients when calling <c>FindDischargedPatients</c>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindDischargedPatients_Find_Return_Patients()
|
||||
{
|
||||
var result = await _repository.FindDischargedPatients();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
}
|
||||
public async Task FindDischargedPatients_Find_Return_Patients()
|
||||
{
|
||||
var result = await _repository.FindDischargedPatients();
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class PoCMappingRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for integration tests by seeding the "mappings" collection with a sample <see cref="PoCMapping"/> document, where a single point of care is mapped from an original value to a new one across eleven bed entries, and initializing the <see cref="PoCMappingRepository"/> against the integration database.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
@@ -22,16 +25,16 @@ public class PoCMappingRepositoryTest
|
||||
Beds =
|
||||
[
|
||||
new List<string> { "bed1", "bed 1" },
|
||||
new List<string> { "bed2", "bed 2" },
|
||||
new List<string> { "bed3", "bed 3" },
|
||||
new List<string> { "bed4", "bed 4" },
|
||||
new List<string> { "bed5", "bed 5" },
|
||||
new List<string> { "bed6", "bed 6" },
|
||||
new List<string> { "bed7", "bed 7" },
|
||||
new List<string> { "bed8", "bed 8" },
|
||||
new List<string> { "bed9", "bed 9" },
|
||||
new List<string> { "bed10", "bed 10" },
|
||||
new List<string> { "bed11", "bed 11" }
|
||||
new List<string> { "bed2", "bed 2" },
|
||||
new List<string> { "bed3", "bed 3" },
|
||||
new List<string> { "bed4", "bed 4" },
|
||||
new List<string> { "bed5", "bed 5" },
|
||||
new List<string> { "bed6", "bed 6" },
|
||||
new List<string> { "bed7", "bed 7" },
|
||||
new List<string> { "bed8", "bed 8" },
|
||||
new List<string> { "bed9", "bed 9" },
|
||||
new List<string> { "bed10", "bed 10" },
|
||||
new List<string> { "bed11", "bed 11" }
|
||||
]
|
||||
};
|
||||
|
||||
@@ -58,6 +61,9 @@ public class PoCMappingRepositoryTest
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that finding a mapping by the key "PV1" returns a non-null result containing point of care entries with at least one associated bed.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByKey_Find_Return_Mapping()
|
||||
{
|
||||
@@ -68,6 +74,9 @@ public class PoCMappingRepositoryTest
|
||||
Assert.That(result.PointOfCares[0].Beds, Has.Count.GreaterThan(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindByKey method returns null when the provided key does not correspond to an existing entity, confirming the not-found behavior.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByKey_Not_Find_Return_Mapping()
|
||||
{
|
||||
|
||||
@@ -11,18 +11,21 @@ namespace adas_core.Test.Repositories;
|
||||
[TestFixture]
|
||||
public class PoCSettingsRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time setup that prepares the integration test environment by resetting the PoC settings collection in the integration database, seeding it with test data, and instantiating the <see cref="PoCSettingsRepository"/> used by the test fixture.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync(_apiSettings.PoCSettings);
|
||||
await IntegrationDb.Database.CreateCollectionAsync(_apiSettings.PoCSettings);
|
||||
|
||||
_repository = new PoCSettingsRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(TestPoCSettings);
|
||||
}
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync(_apiSettings.PoCSettings);
|
||||
await IntegrationDb.Database.CreateCollectionAsync(_apiSettings.PoCSettings);
|
||||
|
||||
_repository = new PoCSettingsRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(TestPoCSettings);
|
||||
}
|
||||
|
||||
private PoCSettingsRepository _repository;
|
||||
|
||||
@@ -42,76 +45,92 @@ public class PoCSettingsRepositoryTest
|
||||
PatientLocation = TestLocation
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that calling the Delete method with an existing PoCSettings identifier removes the corresponding record from the repository, resulting in a null lookup via FindById.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_WhenCalled_ShouldRemovePoCSettings()
|
||||
{
|
||||
// Arrange
|
||||
var newObjectId = ObjectId.GenerateNewId();
|
||||
var newPoCSettings = new PoCSettings
|
||||
public async Task Delete_WhenCalled_ShouldRemovePoCSettings()
|
||||
{
|
||||
Id = newObjectId,
|
||||
PatientLocation = new PatientLocation("poc2", "bed2")
|
||||
};
|
||||
await _repository.InsertOneAsync(newPoCSettings);
|
||||
|
||||
// Act
|
||||
await _repository.Delete(newObjectId);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(newObjectId);
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
// Arrange
|
||||
var newObjectId = ObjectId.GenerateNewId();
|
||||
var newPoCSettings = new PoCSettings
|
||||
{
|
||||
Id = newObjectId,
|
||||
PatientLocation = new PatientLocation("poc2", "bed2")
|
||||
};
|
||||
await _repository.InsertOneAsync(newPoCSettings);
|
||||
|
||||
// Act
|
||||
await _repository.Delete(newObjectId);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(newObjectId);
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindAll</c> method returns a non-null and non-empty collection of PoC settings.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAll_WhenCalled_ShouldReturnAllPoCSettings()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindById_WhenCalled_ShouldReturnPoCSettings()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.FindById(TestObjectId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(TestObjectId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByLocation_WhenCalled_ShouldReturnPoCSettings()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.FindByLocation(TestLocation);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.PatientLocation, Is.EqualTo(TestLocation));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_WhenCalled_ShouldUpdatePoCSettings()
|
||||
{
|
||||
// Arrange
|
||||
var updatedPoCSettings = new PoCSettings
|
||||
public async Task FindAll_WhenCalled_ShouldReturnAllPoCSettings()
|
||||
{
|
||||
Id = TestObjectId,
|
||||
PatientLocation = new PatientLocation("POC3", "Bed3")
|
||||
};
|
||||
// Act
|
||||
var result = await _repository.FindAll();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
}
|
||||
|
||||
// Act
|
||||
await _repository.Update(updatedPoCSettings);
|
||||
/// <summary>
|
||||
/// Tests that FindById returns a non-null PoC settings object whose identifier matches the requested value.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_WhenCalled_ShouldReturnPoCSettings()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.FindById(TestObjectId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(TestObjectId));
|
||||
}
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(TestObjectId);
|
||||
Assert.That(result, Is.Not.Null);
|
||||
//Assert.That(result?.PatientLocation?.PointOfCare, Is.EqualTo("POC3"));
|
||||
Assert.That(result?.PatientLocation?.Bed, Is.EqualTo("Bed3"));
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that _repository.FindByLocation returns a PoC settings object matching the requested patient location.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByLocation_WhenCalled_ShouldReturnPoCSettings()
|
||||
{
|
||||
// Act
|
||||
var result = await _repository.FindByLocation(TestLocation);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.PatientLocation, Is.EqualTo(TestLocation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository correctly updates an existing PoCSettings entity, specifically ensuring that the associated PatientLocation properties (such as Bed) are persisted after the update operation.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous test execution.</returns>
|
||||
[Test]
|
||||
public async Task Update_WhenCalled_ShouldUpdatePoCSettings()
|
||||
{
|
||||
// Arrange
|
||||
var updatedPoCSettings = new PoCSettings
|
||||
{
|
||||
Id = TestObjectId,
|
||||
PatientLocation = new PatientLocation("POC3", "Bed3")
|
||||
};
|
||||
|
||||
// Act
|
||||
await _repository.Update(updatedPoCSettings);
|
||||
|
||||
// Assert
|
||||
var result = await _repository.FindById(TestObjectId);
|
||||
Assert.That(result, Is.Not.Null);
|
||||
//Assert.That(result?.PatientLocation?.PointOfCare, Is.EqualTo("POC3"));
|
||||
Assert.That(result?.PatientLocation?.Bed, Is.EqualTo("Bed3"));
|
||||
}
|
||||
}
|
||||
@@ -14,168 +14,199 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class PointOfCareRepositoryTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time setup for integration tests by initializing mock dependencies and resetting the
|
||||
/// "pointOfCares" MongoDB collection before instantiating the <see cref="PointOfCareRepository"/>.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(new ApiSettings());
|
||||
_mockCollection = new Mock<IMongoCollection<PointOfCare>>();
|
||||
_mockDatabase = new Mock<IMongoDatabase>();
|
||||
_mockDatabase.Setup(db => db.GetCollection<PointOfCare>(It.IsAny<string>(), null))
|
||||
.Returns(_mockCollection.Object);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("pointOfCares");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pointOfCares");
|
||||
_repository = new PointOfCareRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
}
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(new ApiSettings());
|
||||
_mockCollection = new Mock<IMongoCollection<PointOfCare>>();
|
||||
_mockDatabase = new Mock<IMongoDatabase>();
|
||||
_mockDatabase.Setup(db => db.GetCollection<PointOfCare>(It.IsAny<string>(), null))
|
||||
.Returns(_mockCollection.Object);
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("pointOfCares");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pointOfCares");
|
||||
_repository = new PointOfCareRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
}
|
||||
|
||||
private PointOfCareRepository _repository;
|
||||
private Mock<IMongoCollection<PointOfCare>> _mockCollection;
|
||||
private Mock<IMongoDatabase> _mockDatabase;
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that InsertOneAsync successfully inserts a valid point of care into the repository and that the record can be retrieved by its identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOneAsync_ValidPointOfCare_InsertsSuccessfully()
|
||||
{
|
||||
// Arrange
|
||||
var pointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
|
||||
// Act
|
||||
await _repository.InsertOneAsync(pointOfCare);
|
||||
|
||||
// Assert
|
||||
var insertedPointOfCare = await _repository.FindById(pointOfCare.Id);
|
||||
Assert.That(insertedPointOfCare, Is.Not.Null, "Inserted point of care should not be null");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Delete_ValidId_DeletesSuccessfully()
|
||||
{
|
||||
var pointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(pointOfCare);
|
||||
|
||||
await _repository.Delete(pointOfCare.Id);
|
||||
|
||||
// Assert
|
||||
var deletedPointOfCare = await _repository.FindById(pointOfCare.Id);
|
||||
Assert.That(deletedPointOfCare, Is.Null, "Deleted point of care should be null");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_ValidPointOfCare_UpdatesSuccessfully()
|
||||
{
|
||||
// Arrange
|
||||
var originalPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(originalPointOfCare); // Insert the original point of care
|
||||
|
||||
// Modify some properties to update
|
||||
originalPointOfCare.Room = "Updated Room";
|
||||
originalPointOfCare.Bed = "Updated Bed";
|
||||
|
||||
// Act
|
||||
await _repository.Update(originalPointOfCare); // Update the point of care
|
||||
|
||||
// Retrieve the updated point of care
|
||||
var updatedPointOfCare = await _repository.FindById(originalPointOfCare.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(updatedPointOfCare, Is.Not.Null, "Updated point of care should not be null");
|
||||
Assert.That(updatedPointOfCare?.Room, Is.EqualTo(originalPointOfCare.Room), "Room should be updated");
|
||||
Assert.That(updatedPointOfCare?.Bed, Is.EqualTo(originalPointOfCare.Bed), "Bed should be updated");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task FindById_ExistingId_ReturnsPointOfCare()
|
||||
{
|
||||
// Arrange
|
||||
var pointOfCareId = ObjectId.GenerateNewId();
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
expectedPointOfCare.Id = pointOfCareId;
|
||||
|
||||
// Insert a PointOfCare document into the database
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(pointOfCareId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null, "Returned PointOfCare should not be null");
|
||||
Assert.That(result!.Id, Is.EqualTo(expectedPointOfCare.Id), "Returned PointOfCare should have the expected ID");
|
||||
// Add additional assertions to compare other properties if needed
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByUnitAndStatus_ExistingUnitAndStatus_ReturnsMatchingPointOfCares()
|
||||
{
|
||||
// Arrange
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
|
||||
// Insert PointOfCare documents into the database with the specified unit ID and status
|
||||
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByUnitAndStatus(expectedPointOfCare.UnitId, expectedPointOfCare.Status);
|
||||
|
||||
var resultList = result.ToList();
|
||||
// Assert
|
||||
Assert.That(resultList, Is.Not.Null, "Returned collection should not be null");
|
||||
Assert.That(resultList.First().Id, Is.EqualTo(expectedPointOfCare.Id),
|
||||
"Returned collection should contain expected PointOfCare object");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByRoom_ValidRoom_ReturnsMatchingPointOfCares()
|
||||
{
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
if (expectedPointOfCare.Unit != null)
|
||||
public async Task InsertOneAsync_ValidPointOfCare_InsertsSuccessfully()
|
||||
{
|
||||
var result = await _repository.FindByRoom(expectedPointOfCare.Room);
|
||||
// Arrange
|
||||
var pointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
|
||||
// Act
|
||||
await _repository.InsertOneAsync(pointOfCare);
|
||||
|
||||
// Assert
|
||||
var insertedPointOfCare = await _repository.FindById(pointOfCare.Id);
|
||||
Assert.That(insertedPointOfCare, Is.Not.Null, "Inserted point of care should not be null");
|
||||
}
|
||||
|
||||
var resultList = result?.ToList();
|
||||
/// <summary>
|
||||
/// Verifies that the Delete method successfully removes a point of care from the repository when given a valid identifier.
|
||||
/// Inserts a point of care, deletes it by its identifier, and asserts that the entity can no longer be retrieved.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Delete_ValidId_DeletesSuccessfully()
|
||||
{
|
||||
var pointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(pointOfCare);
|
||||
|
||||
await _repository.Delete(pointOfCare.Id);
|
||||
|
||||
// Assert
|
||||
var deletedPointOfCare = await _repository.FindById(pointOfCare.Id);
|
||||
Assert.That(deletedPointOfCare, Is.Null, "Deleted point of care should be null");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="PointOfCare"/> entities can be updated successfully when valid data is provided, ensuring that modified properties such as <c>Room</c> and <c>Bed</c> are persisted and retrievable after the update operation.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Update_ValidPointOfCare_UpdatesSuccessfully()
|
||||
{
|
||||
// Arrange
|
||||
var originalPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(originalPointOfCare); // Insert the original point of care
|
||||
|
||||
// Modify some properties to update
|
||||
originalPointOfCare.Room = "Updated Room";
|
||||
originalPointOfCare.Bed = "Updated Bed";
|
||||
|
||||
// Act
|
||||
await _repository.Update(originalPointOfCare); // Update the point of care
|
||||
|
||||
// Retrieve the updated point of care
|
||||
var updatedPointOfCare = await _repository.FindById(originalPointOfCare.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(updatedPointOfCare, Is.Not.Null, "Updated point of care should not be null");
|
||||
Assert.That(updatedPointOfCare?.Room, Is.EqualTo(originalPointOfCare.Room), "Room should be updated");
|
||||
Assert.That(updatedPointOfCare?.Bed, Is.EqualTo(originalPointOfCare.Bed), "Bed should be updated");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindById</c> method returns the correct <c>PointOfCare</c> document when queried with an existing identifier, by inserting a document and asserting that the retrieved entity matches the expected one.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_ExistingId_ReturnsPointOfCare()
|
||||
{
|
||||
// Arrange
|
||||
var pointOfCareId = ObjectId.GenerateNewId();
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
expectedPointOfCare.Id = pointOfCareId;
|
||||
|
||||
// Insert a PointOfCare document into the database
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(pointOfCareId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null, "Returned PointOfCare should not be null");
|
||||
Assert.That(result!.Id, Is.EqualTo(expectedPointOfCare.Id), "Returned PointOfCare should have the expected ID");
|
||||
// Add additional assertions to compare other properties if needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that FindByUnitAndStatus returns the matching <c>PointOfCare</c> documents when queried with an existing unit identifier and status.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByUnitAndStatus_ExistingUnitAndStatus_ReturnsMatchingPointOfCares()
|
||||
{
|
||||
// Arrange
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
|
||||
// Insert PointOfCare documents into the database with the specified unit ID and status
|
||||
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByUnitAndStatus(expectedPointOfCare.UnitId, expectedPointOfCare.Status);
|
||||
|
||||
var resultList = result.ToList();
|
||||
// Assert
|
||||
Assert.That(resultList, Is.Not.Null, "Returned collection should not be null");
|
||||
|
||||
Assert.That(resultList?.Any(p => p.Id == expectedPointOfCare.Id), Is.True,
|
||||
Assert.That(resultList.First().Id, Is.EqualTo(expectedPointOfCare.Id),
|
||||
"Returned collection should contain expected PointOfCare object");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that <c>FindByRoom</c> returns the matching <c>PointOfCare</c> when a valid room is provided.
|
||||
/// Inserts a valid <c>PointOfCare</c> into the repository and verifies the search by room returns a non-null collection
|
||||
/// containing the expected entity. Assertions are only executed when the inserted <c>PointOfCare</c> has a non-null <c>Unit</c>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByBed_ValidBed_ReturnsMatchingPointOfCares()
|
||||
{
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByBed(expectedPointOfCare.Bed);
|
||||
|
||||
// Convert the result to a list or an array
|
||||
var resultList = result?.ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(resultList, Is.Not.Null, "Returned collection should not be null");
|
||||
|
||||
// Check if the expected point of care is contained within the result
|
||||
Assert.That(resultList?.First().Bed, Is.EqualTo(expectedPointOfCare.Bed),
|
||||
"Returned collection should contain expected PointOfCare object");
|
||||
}
|
||||
public async Task FindByRoom_ValidRoom_ReturnsMatchingPointOfCares()
|
||||
{
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
if (expectedPointOfCare.Unit != null)
|
||||
{
|
||||
var result = await _repository.FindByRoom(expectedPointOfCare.Room);
|
||||
|
||||
var resultList = result?.ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(resultList, Is.Not.Null, "Returned collection should not be null");
|
||||
|
||||
Assert.That(resultList?.Any(p => p.Id == expectedPointOfCare.Id), Is.True,
|
||||
"Returned collection should contain expected PointOfCare object");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns the matching PointOfCare when queried with a valid bed identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAll_ReturnsAllPointOfCares()
|
||||
{
|
||||
var poc = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(poc);
|
||||
public async Task FindByBed_ValidBed_ReturnsMatchingPointOfCares()
|
||||
{
|
||||
var expectedPointOfCare = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(expectedPointOfCare);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByBed(expectedPointOfCare.Bed);
|
||||
|
||||
// Convert the result to a list or an array
|
||||
var resultList = result?.ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(resultList, Is.Not.Null, "Returned collection should not be null");
|
||||
|
||||
// Check if the expected point of care is contained within the result
|
||||
Assert.That(resultList?.First().Bed, Is.EqualTo(expectedPointOfCare.Bed),
|
||||
"Returned collection should contain expected PointOfCare object");
|
||||
}
|
||||
|
||||
var result = await _repository.GetAll();
|
||||
|
||||
var resultList = result?.ToList();
|
||||
// Assert
|
||||
Assert.That(resultList?.Any(p => p.Id == poc.Id), Is.True,
|
||||
"Returned collection should contain the expected PointOfCare object with the specified Id");
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that the <c>GetAll</c> repository method returns all stored <c>PointOfCare</c> entries, including a newly inserted one identified by its assigned Id.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAll_ReturnsAllPointOfCares()
|
||||
{
|
||||
var poc = TestUtilities.CreateValidPointOfCare();
|
||||
await _repository.InsertOneAsync(poc);
|
||||
|
||||
var result = await _repository.GetAll();
|
||||
|
||||
var resultList = result?.ToList();
|
||||
// Assert
|
||||
Assert.That(resultList?.Any(p => p.Id == poc.Id), Is.True,
|
||||
"Returned collection should contain the expected PointOfCare object with the specified Id");
|
||||
}
|
||||
}
|
||||
@@ -23,122 +23,140 @@ public class PumpAlarmEventRepositoryTest
|
||||
// -------------------------------------------------------------------
|
||||
// INIT – Setup inicial de colección con índices y datos de prueba
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Performs one-time integration test setup for the pump alarm event repository by configuring API settings,
|
||||
/// resetting the dedicated MongoDB collection, creating required indexes, and seeding it with three initial
|
||||
/// alarm events covering both Device and DeviceB across attention and occlusion
|
||||
/// alarm types. Verifies that exactly three documents are present after seeding.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_apiSettings = Options.Create(new ApiSettings
|
||||
public async Task Init()
|
||||
{
|
||||
PumpAlarmEvent = "pump_alarm_event"
|
||||
});
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("pump_alarm_event");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pump_alarm_event");
|
||||
|
||||
_repo = new PumpAlarmEventRepository(
|
||||
_apiSettings,
|
||||
IntegrationDb.Database
|
||||
);
|
||||
|
||||
await _repo.CreateIndexes();
|
||||
|
||||
var initialEvents = new List<PumpAlarmEvent>
|
||||
{
|
||||
new()
|
||||
_apiSettings = Options.Create(new ApiSettings
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = Now.AddSeconds(-1)
|
||||
},
|
||||
new()
|
||||
PumpAlarmEvent = "pump_alarm_event"
|
||||
});
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("pump_alarm_event");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pump_alarm_event");
|
||||
|
||||
_repo = new PumpAlarmEventRepository(
|
||||
_apiSettings,
|
||||
IntegrationDb.Database
|
||||
);
|
||||
|
||||
await _repo.CreateIndexes();
|
||||
|
||||
var initialEvents = new List<PumpAlarmEvent>
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now.AddSeconds(-3)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceB,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now.AddSeconds(-2)
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database
|
||||
.GetCollection<PumpAlarmEvent>("pump_alarm_event")
|
||||
.InsertManyAsync(initialEvents);
|
||||
|
||||
var count = await _repo.Collection.CountDocumentsAsync(_ => true);
|
||||
Assert.That(count, Is.EqualTo(3));
|
||||
}
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = Now.AddSeconds(-1)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now.AddSeconds(-3)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceB,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now.AddSeconds(-2)
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database
|
||||
.GetCollection<PumpAlarmEvent>("pump_alarm_event")
|
||||
.InsertManyAsync(initialEvents);
|
||||
|
||||
var count = await _repo.Collection.CountDocumentsAsync(_ => true);
|
||||
Assert.That(count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// INSERT
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that InsertAsync correctly persists a <see cref="PumpAlarmEvent"/> to the repository by inserting an event and confirming it can be retrieved by its identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertAsync_Works()
|
||||
{
|
||||
var evt = new PumpAlarmEvent
|
||||
public async Task InsertAsync_Works()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-C",
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.Id == evt.Id);
|
||||
Assert.That(found.FirstOrDefault(), Is.Not.Null);
|
||||
}
|
||||
var evt = new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-C",
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.Id == evt.Id);
|
||||
Assert.That(found.FirstOrDefault(), Is.Not.Null);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// FIND BY DEVICE ID
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> returns a non-empty collection of records for the specified device, ordered by time so that the most recent entry appears first.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_ReturnsOrdered()
|
||||
{
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA);
|
||||
|
||||
var list = result.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
public async Task FindByDeviceIdAsync_ReturnsOrdered()
|
||||
{
|
||||
Assert.That(list, Is.Not.Empty);
|
||||
Assert.That(list.First().Time, Is.GreaterThanOrEqualTo(list.Last().Time));
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA);
|
||||
|
||||
var list = result.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(list, Is.Not.Empty);
|
||||
Assert.That(list.First().Time, Is.GreaterThanOrEqualTo(list.Last().Time));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> returns only pump alarm events whose timestamps fall within the specified date range.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_WithDateRange_Works()
|
||||
{
|
||||
var from = Now.AddSeconds(-2);
|
||||
var to = Now;
|
||||
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA, from, to);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
public async Task FindByDeviceIdAsync_WithDateRange_Works()
|
||||
{
|
||||
var pumpAlarmEvents = result.ToList();
|
||||
Assert.That(pumpAlarmEvents, Is.Not.Empty);
|
||||
Assert.That(pumpAlarmEvents.All(x => x.Time >= from && x.Time <= to), Is.True);
|
||||
var from = Now.AddSeconds(-2);
|
||||
var to = Now;
|
||||
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA, from, to);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
var pumpAlarmEvents = result.ToList();
|
||||
Assert.That(pumpAlarmEvents, Is.Not.Empty);
|
||||
Assert.That(pumpAlarmEvents.All(x => x.Time >= from && x.Time <= to), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> returns at most the specified number of results when a limit is provided.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_WithLimit_Works()
|
||||
{
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA, limit: 1);
|
||||
|
||||
var list = result.ToList();
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task FindByDeviceIdAsync_WithLimit_Works()
|
||||
{
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA, limit: 1);
|
||||
|
||||
var list = result.ToList();
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// FIND LAST BY DEVICE
|
||||
@@ -162,234 +180,270 @@ public class PumpAlarmEventRepositoryTest
|
||||
// -------------------------------------------------------------------
|
||||
// DELETE BY PATIENT ID
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that DeleteByPatientId correctly removes all alarm events associated with a given patient.
|
||||
/// Inserts a sample <c>PumpAlarmEvent</c> for a specific patient, deletes it by patient ID, and asserts that no matching events remain in the collection.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteByPatientId_Works()
|
||||
{
|
||||
var patient2 = ObjectId.GenerateNewId();
|
||||
|
||||
var evt = new PumpAlarmEvent
|
||||
public async Task DeleteByPatientId_Works()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-X",
|
||||
PatientId = patient2,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
await _repo.DeleteByPatientId(patient2);
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.PatientId == patient2);
|
||||
Assert.That(await found.AnyAsync(), Is.False);
|
||||
}
|
||||
var patient2 = ObjectId.GenerateNewId();
|
||||
|
||||
var evt = new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-X",
|
||||
PatientId = patient2,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
await _repo.DeleteByPatientId(patient2);
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.PatientId == patient2);
|
||||
Assert.That(await found.AnyAsync(), Is.False);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// UPDATE MANY (CAMBIO DE PATIENTID O SIMILAR)
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>UpdateManyObjectIdByFiledNameAsync</c> correctly updates documents matching the specified field name and old ObjectId value, replacing it with the new ObjectId, and that the changes are persisted and queryable.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateManyObjectIdByFiledNameAsync_Works()
|
||||
{
|
||||
var oldId = ObjectId.GenerateNewId();
|
||||
var newId = ObjectId.GenerateNewId();
|
||||
|
||||
var evt = new PumpAlarmEvent
|
||||
public async Task UpdateManyObjectIdByFiledNameAsync_Works()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-U",
|
||||
PatientId = oldId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
var updated = await _repo.UpdateManyObjectIdByFiledNameAsync("PatientId", newId, oldId);
|
||||
|
||||
Assert.That(updated, Is.EqualTo(1));
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.PatientId == newId);
|
||||
Assert.That(await found.AnyAsync(), Is.True);
|
||||
}
|
||||
var oldId = ObjectId.GenerateNewId();
|
||||
var newId = ObjectId.GenerateNewId();
|
||||
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_ReturnsEmpty_WhenOutOfRange()
|
||||
{
|
||||
var from = Now.AddYears(-2);
|
||||
var to = Now.AddYears(-2).AddDays(1);
|
||||
|
||||
var result = await _repo.FindByDeviceIdAsync("Device-A", from, to);
|
||||
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
var evt = new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-U",
|
||||
PatientId = oldId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_RespectsLimitAndOrder()
|
||||
{
|
||||
// Semilla adicional para asegurar > 1
|
||||
var events = new[]
|
||||
{
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = DeviceA, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.AirInLine, Time = Now.AddMilliseconds(-10) },
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = DeviceA, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Occlusion, Time = Now.AddMilliseconds(-5) }
|
||||
};
|
||||
await _repo.Collection.InsertManyAsync(events);
|
||||
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA, limit: 1);
|
||||
var list = result.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
var last = await _repo.FindLastByDeviceIdAsync(DeviceA);
|
||||
Assert.That(list[0].Id, Is.EqualTo(last!.Id));
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
var updated = await _repo.UpdateManyObjectIdByFiledNameAsync("PatientId", newId, oldId);
|
||||
|
||||
Assert.That(updated, Is.EqualTo(1));
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.PatientId == newId);
|
||||
Assert.That(await found.AnyAsync(), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> returns an empty result when the queried date range falls outside of the available data window.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertAsync_AllowsNullOptionalFields()
|
||||
{
|
||||
var evt = new PumpAlarmEvent
|
||||
public async Task FindByDeviceIdAsync_ReturnsEmpty_WhenOutOfRange()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Nulls",
|
||||
PatientId = null, // opcional
|
||||
AlarmType = null, // opcional
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.Id == evt.Id);
|
||||
Assert.That(found.FirstOrDefault(), Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteByPatientId_DeletesMany_AndIsIdempotent()
|
||||
{
|
||||
var pid = ObjectId.GenerateNewId();
|
||||
|
||||
var docs = Enumerable.Range(0, 3).Select(i => new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Del",
|
||||
PatientId = pid,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = Now.AddSeconds(-i)
|
||||
});
|
||||
|
||||
await _repo.Collection.InsertManyAsync(docs);
|
||||
|
||||
// Primera vez: borra 3
|
||||
await _repo.DeleteByPatientId(pid);
|
||||
var left = await _repo.Collection.FindAsync(x => x.PatientId == pid);
|
||||
Assert.That(left.ToList(), Is.Empty);
|
||||
|
||||
Func<Task> act = async () => await _repo.DeleteByPatientId(pid);
|
||||
Assert.That(act, Throws.Nothing);
|
||||
}
|
||||
|
||||
var from = Now.AddYears(-2);
|
||||
var to = Now.AddYears(-2).AddDays(1);
|
||||
|
||||
[Test]
|
||||
public async Task UpdateManyObjectIdByFiledNameAsync_UpdatesMultiple()
|
||||
{
|
||||
var oldId = ObjectId.GenerateNewId();
|
||||
var newId = ObjectId.GenerateNewId();
|
||||
|
||||
var events = Enumerable.Range(0, 4).Select(i => new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-U",
|
||||
PatientId = oldId,
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
Time = Now.AddMilliseconds(-i)
|
||||
});
|
||||
|
||||
await _repo.Collection.InsertManyAsync(events);
|
||||
|
||||
var modified = await _repo.UpdateManyObjectIdByFiledNameAsync("PatientId", newId, oldId);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(modified, Is.EqualTo(4));
|
||||
var foundNew = await _repo.Collection.FindAsync(x => x.PatientId == newId);
|
||||
Assert.That(foundNew.ToList(), Has.Count.EqualTo(4));
|
||||
var result = await _repo.FindByDeviceIdAsync("Device-A", from, to);
|
||||
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_InclusiveRange_BoundsRespected()
|
||||
{
|
||||
var start = Now.AddMinutes(-30);
|
||||
var end = Now.AddMinutes(-29);
|
||||
|
||||
var exactEvt = new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Range",
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = end // exactamente igual al to
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(exactEvt);
|
||||
|
||||
var result = await _repo.FindByDeviceIdAsync("Device-Range", from: start, to: end);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
var pumpAlarmEvents = result as PumpAlarmEvent[] ?? result.ToArray();
|
||||
Assert.That(pumpAlarmEvents, Is.Not.Empty);
|
||||
Assert.That(pumpAlarmEvents.All(r => r.Time >= start && r.Time <= end), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> correctly applies the requested limit and orders results so that the most recent alarm event for the given device is returned first.
|
||||
/// Seeds multiple events for the target device, requests a single record, and asserts that the returned entry matches the latest event retrieved by <c>FindLastByDeviceIdAsync</c>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindLastByDeviceIdAsync_TracksNewest()
|
||||
{
|
||||
const string dev = "Device-LastCheck";
|
||||
|
||||
var e1 = new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.AirInLine, Time = Now.AddSeconds(-10) };
|
||||
var e2 = new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Occlusion, Time = Now.AddSeconds(-5) };
|
||||
|
||||
await _repo.Collection.InsertManyAsync([e1, e2]);
|
||||
|
||||
var last1 = await _repo.FindLastByDeviceIdAsync(dev);
|
||||
Assert.That(last1!.Id, Is.EqualTo(e2.Id));
|
||||
|
||||
var e3 = new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Attention, Time = Now };
|
||||
await _repo.InsertAsync(e3);
|
||||
|
||||
var last2 = await _repo.FindLastByDeviceIdAsync(dev);
|
||||
Assert.That(last2!.Id, Is.EqualTo(e3.Id));
|
||||
}
|
||||
public async Task FindByDeviceIdAsync_RespectsLimitAndOrder()
|
||||
{
|
||||
// Semilla adicional para asegurar > 1
|
||||
var events = new[]
|
||||
{
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = DeviceA, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.AirInLine, Time = Now.AddMilliseconds(-10) },
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = DeviceA, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Occlusion, Time = Now.AddMilliseconds(-5) }
|
||||
};
|
||||
await _repo.Collection.InsertManyAsync(events);
|
||||
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_MultipleOverlappingRanges()
|
||||
{
|
||||
const string dev = "Device-Timeline";
|
||||
|
||||
var batch = new[]
|
||||
{
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.AirInLine, Time = Now.AddMinutes(-20) },
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Occlusion, Time = Now.AddMinutes(-10) },
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Attention, Time = Now.AddMinutes(-5) }
|
||||
};
|
||||
|
||||
await _repo.Collection.InsertManyAsync(batch);
|
||||
|
||||
var r1 = await _repo.FindByDeviceIdAsync(dev, from: Now.AddMinutes(-30), to: Now.AddMinutes(-15));
|
||||
var r2 = await _repo.FindByDeviceIdAsync(dev, from: Now.AddMinutes(-12), to: Now.AddMinutes(-8));
|
||||
var r3 = await _repo.FindByDeviceIdAsync(dev, from: Now.AddMinutes(-6), to: Now);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
var r1List = r1.ToList();
|
||||
Assert.That(r1List, Has.Count.EqualTo(1)); // -20
|
||||
var r2List = r2.ToList();
|
||||
Assert.That(r2List, Has.Count.EqualTo(1)); // -10
|
||||
var r3List = r3.ToList();
|
||||
Assert.That(r3List, Has.Count.EqualTo(1)); // -5
|
||||
var result = await _repo.FindByDeviceIdAsync(DeviceA, limit: 1);
|
||||
var list = result.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
var last = await _repo.FindLastByDeviceIdAsync(DeviceA);
|
||||
Assert.That(list[0].Id, Is.EqualTo(last!.Id));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that InsertAsync successfully persists a <see cref="PumpAlarmEvent"/> when its optional fields (<c>PatientId</c> and <c>AlarmType</c>) are <c>null</c>, and that the record can be retrieved afterwards.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertAsync_AllowsNullOptionalFields()
|
||||
{
|
||||
var evt = new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Nulls",
|
||||
PatientId = null, // opcional
|
||||
AlarmType = null, // opcional
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(evt);
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.Id == evt.Id);
|
||||
Assert.That(found.FirstOrDefault(), Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>DeleteByPatientId</c> removes all alarm events associated with the given patient and can be invoked repeatedly without throwing once the records no longer exist.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteByPatientId_DeletesMany_AndIsIdempotent()
|
||||
{
|
||||
var pid = ObjectId.GenerateNewId();
|
||||
|
||||
var docs = Enumerable.Range(0, 3).Select(i => new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Del",
|
||||
PatientId = pid,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = Now.AddSeconds(-i)
|
||||
});
|
||||
|
||||
await _repo.Collection.InsertManyAsync(docs);
|
||||
|
||||
// Primera vez: borra 3
|
||||
await _repo.DeleteByPatientId(pid);
|
||||
var left = await _repo.Collection.FindAsync(x => x.PatientId == pid);
|
||||
Assert.That(left.ToList(), Is.Empty);
|
||||
|
||||
Func<Task> act = async () => await _repo.DeleteByPatientId(pid);
|
||||
Assert.That(act, Throws.Nothing);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>UpdateManyObjectIdByFiledNameAsync</c> updates the <c>PatientId</c> field from an old <see cref="ObjectId"/> to a new one across all matching documents, returning the modified count and persisting the new identifier in the collection.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateManyObjectIdByFiledNameAsync_UpdatesMultiple()
|
||||
{
|
||||
var oldId = ObjectId.GenerateNewId();
|
||||
var newId = ObjectId.GenerateNewId();
|
||||
|
||||
var events = Enumerable.Range(0, 4).Select(i => new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-U",
|
||||
PatientId = oldId,
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
Time = Now.AddMilliseconds(-i)
|
||||
});
|
||||
|
||||
await _repo.Collection.InsertManyAsync(events);
|
||||
|
||||
var modified = await _repo.UpdateManyObjectIdByFiledNameAsync("PatientId", newId, oldId);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(modified, Is.EqualTo(4));
|
||||
var foundNew = await _repo.Collection.FindAsync(x => x.PatientId == newId);
|
||||
Assert.That(foundNew.ToList(), Has.Count.EqualTo(4));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> treats the <c>from</c> and <c>to</c> time bounds as inclusive,
|
||||
/// ensuring events whose timestamp matches the upper bound exactly are returned and that all returned
|
||||
/// events fall within the supplied range.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_InclusiveRange_BoundsRespected()
|
||||
{
|
||||
var start = Now.AddMinutes(-30);
|
||||
var end = Now.AddMinutes(-29);
|
||||
|
||||
var exactEvt = new PumpAlarmEvent
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Range",
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
Time = end // exactamente igual al to
|
||||
};
|
||||
|
||||
await _repo.InsertAsync(exactEvt);
|
||||
|
||||
var result = await _repo.FindByDeviceIdAsync("Device-Range", from: start, to: end);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
var pumpAlarmEvents = result as PumpAlarmEvent[] ?? result.ToArray();
|
||||
Assert.That(pumpAlarmEvents, Is.Not.Empty);
|
||||
Assert.That(pumpAlarmEvents.All(r => r.Time >= start && r.Time <= end), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that FindLastByDeviceIdAsync returns the most recent alarm event for a given device and tracks newly inserted events as the latest entry.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindLastByDeviceIdAsync_TracksNewest()
|
||||
{
|
||||
const string dev = "Device-LastCheck";
|
||||
|
||||
var e1 = new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.AirInLine, Time = Now.AddSeconds(-10) };
|
||||
var e2 = new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Occlusion, Time = Now.AddSeconds(-5) };
|
||||
|
||||
await _repo.Collection.InsertManyAsync([e1, e2]);
|
||||
|
||||
var last1 = await _repo.FindLastByDeviceIdAsync(dev);
|
||||
Assert.That(last1!.Id, Is.EqualTo(e2.Id));
|
||||
|
||||
var e3 = new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Attention, Time = Now };
|
||||
await _repo.InsertAsync(e3);
|
||||
|
||||
var last2 = await _repo.FindLastByDeviceIdAsync(dev);
|
||||
Assert.That(last2!.Id, Is.EqualTo(e3.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByDeviceIdAsync</c> correctly filters pump alarm events by device identifier
|
||||
/// and time range when multiple queries are issued against overlapping windows, ensuring each
|
||||
/// range returns only the event that falls within its boundaries.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_MultipleOverlappingRanges()
|
||||
{
|
||||
const string dev = "Device-Timeline";
|
||||
|
||||
var batch = new[]
|
||||
{
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.AirInLine, Time = Now.AddMinutes(-20) },
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Occlusion, Time = Now.AddMinutes(-10) },
|
||||
new PumpAlarmEvent { Id = ObjectId.GenerateNewId(), DeviceId = dev, PatientId = PatientId, AlarmType = PumpEnum.AlarmType.Attention, Time = Now.AddMinutes(-5) }
|
||||
};
|
||||
|
||||
await _repo.Collection.InsertManyAsync(batch);
|
||||
|
||||
var r1 = await _repo.FindByDeviceIdAsync(dev, from: Now.AddMinutes(-30), to: Now.AddMinutes(-15));
|
||||
var r2 = await _repo.FindByDeviceIdAsync(dev, from: Now.AddMinutes(-12), to: Now.AddMinutes(-8));
|
||||
var r3 = await _repo.FindByDeviceIdAsync(dev, from: Now.AddMinutes(-6), to: Now);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
var r1List = r1.ToList();
|
||||
Assert.That(r1List, Has.Count.EqualTo(1)); // -20
|
||||
var r2List = r2.ToList();
|
||||
Assert.That(r2List, Has.Count.EqualTo(1)); // -10
|
||||
var r3List = r3.ToList();
|
||||
Assert.That(r3List, Has.Count.EqualTo(1)); // -5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,108 +23,123 @@ public class PumpAlarmStateRepositoryTest
|
||||
// -------------------------------------------------------------------
|
||||
// INIT: preparar colección, índices y datos iniciales
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// One-time setup that prepares the integration test environment for <see cref="PumpAlarmStateRepository"/>.
|
||||
/// Configures the API settings, drops and recreates the "pump_alarm_state" collection, instantiates the repository with its indexes, and seeds three initial alarm state records across two devices, verifying the seeded count.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_apiSettings = Options.Create(new ApiSettings
|
||||
public async Task Init()
|
||||
{
|
||||
PumpAlarmState = "pump_alarm_state"
|
||||
});
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("pump_alarm_state");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pump_alarm_state");
|
||||
|
||||
_repo = new PumpAlarmStateRepository(
|
||||
_apiSettings,
|
||||
IntegrationDb.Database
|
||||
);
|
||||
|
||||
await _repo.CreateIndexes();
|
||||
|
||||
// datos iniciales
|
||||
var initial = new List<PumpAlarmState>
|
||||
{
|
||||
new()
|
||||
_apiSettings = Options.Create(new ApiSettings
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
AlarmCodeMdc = "AC001",
|
||||
LastUpdated = Now.AddSeconds(-3)
|
||||
},
|
||||
new()
|
||||
PumpAlarmState = "pump_alarm_state"
|
||||
});
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("pump_alarm_state");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("pump_alarm_state");
|
||||
|
||||
_repo = new PumpAlarmStateRepository(
|
||||
_apiSettings,
|
||||
IntegrationDb.Database
|
||||
);
|
||||
|
||||
await _repo.CreateIndexes();
|
||||
|
||||
// datos iniciales
|
||||
var initial = new List<PumpAlarmState>
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "AC002",
|
||||
LastUpdated = Now.AddSeconds(-1)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceB,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "AC003",
|
||||
LastUpdated = Now.AddSeconds(-2)
|
||||
}
|
||||
};
|
||||
|
||||
await _repo.Collection.InsertManyAsync(initial);
|
||||
|
||||
var count = await _repo.Collection.CountDocumentsAsync(_ => true);
|
||||
Assert.That(count, Is.EqualTo(3));
|
||||
}
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
AlarmCodeMdc = "AC001",
|
||||
LastUpdated = Now.AddSeconds(-3)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "AC002",
|
||||
LastUpdated = Now.AddSeconds(-1)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceB,
|
||||
PatientId = PatientId,
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "AC003",
|
||||
LastUpdated = Now.AddSeconds(-2)
|
||||
}
|
||||
};
|
||||
|
||||
await _repo.Collection.InsertManyAsync(initial);
|
||||
|
||||
var count = await _repo.Collection.CountDocumentsAsync(_ => true);
|
||||
Assert.That(count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// FIND ACTIVE
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindActiveAsync</c> returns the correct active alarm matching the specified device identifier, alarm type, and alarm code.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindActiveAsync_ReturnsCorrectAlarm()
|
||||
{
|
||||
var alarm = await _repo.FindActiveAsync(DeviceA, PumpEnum.AlarmType.Occlusion, "AC002");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
public async Task FindActiveAsync_ReturnsCorrectAlarm()
|
||||
{
|
||||
Assert.That(alarm, Is.Not.Null);
|
||||
Assert.That(alarm!.DeviceId, Is.EqualTo(DeviceA));
|
||||
Assert.That(alarm.AlarmType, Is.EqualTo(PumpEnum.AlarmType.Occlusion));
|
||||
Assert.That(alarm.AlarmCodeMdc, Is.EqualTo("AC002"));
|
||||
var alarm = await _repo.FindActiveAsync(DeviceA, PumpEnum.AlarmType.Occlusion, "AC002");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(alarm, Is.Not.Null);
|
||||
Assert.That(alarm!.DeviceId, Is.EqualTo(DeviceA));
|
||||
Assert.That(alarm.AlarmType, Is.EqualTo(PumpEnum.AlarmType.Occlusion));
|
||||
Assert.That(alarm.AlarmCodeMdc, Is.EqualTo("AC002"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindActiveAsync</c> returns <c>null</c> when no active alarm matching the specified device, alarm type, and identifier exists.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindActiveAsync_ReturnsNull_WhenNotFound()
|
||||
{
|
||||
var alarm = await _repo.FindActiveAsync(DeviceA, PumpEnum.AlarmType.Occlusion, "XXX");
|
||||
Assert.That(alarm, Is.Null);
|
||||
}
|
||||
public async Task FindActiveAsync_ReturnsNull_WhenNotFound()
|
||||
{
|
||||
var alarm = await _repo.FindActiveAsync(DeviceA, PumpEnum.AlarmType.Occlusion, "XXX");
|
||||
Assert.That(alarm, Is.Null);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// UPSERT ACTIVE
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>UpsertActiveAsync</c> correctly inserts a new active pump alarm into the repository
|
||||
/// when no existing alarm with the same device, type, and code is found, and that the inserted alarm
|
||||
/// can subsequently be retrieved via <c>FindActiveAsync</c>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpsertActiveAsync_InsertsNew()
|
||||
{
|
||||
var alarm = new PumpAlarmState
|
||||
public async Task UpsertActiveAsync_InsertsNew()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-C",
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
AlarmCodeMdc = "NEW",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
var found = await _repo.FindActiveAsync("Device-C", PumpEnum.AlarmType.Attention, "NEW");
|
||||
|
||||
Assert.That(found, Is.Not.Null);
|
||||
}
|
||||
var alarm = new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-C",
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
AlarmCodeMdc = "NEW",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
var found = await _repo.FindActiveAsync("Device-C", PumpEnum.AlarmType.Attention, "NEW");
|
||||
|
||||
Assert.That(found, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpsertActiveAsync_UpdatesExisting()
|
||||
@@ -150,98 +165,113 @@ public class PumpAlarmStateRepositoryTest
|
||||
// -------------------------------------------------------------------
|
||||
// REMOVE ACTIVE ALARM
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>RemoveAsync</c> correctly deletes an active alarm by device, alarm type, and alarm code, and that a subsequent lookup returns no result.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task RemoveAsync_Works()
|
||||
{
|
||||
var alarm = new PumpAlarmState
|
||||
public async Task RemoveAsync_Works()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-D",
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
AlarmCodeMdc = "D1",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
await _repo.RemoveAsync("Device-D", PumpEnum.AlarmType.Attention, "D1");
|
||||
|
||||
var found = await _repo.FindActiveAsync("Device-D", PumpEnum.AlarmType.Attention, "D1");
|
||||
Assert.That(found, Is.Null);
|
||||
}
|
||||
var alarm = new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-D",
|
||||
AlarmType = PumpEnum.AlarmType.Attention,
|
||||
AlarmCodeMdc = "D1",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
await _repo.RemoveAsync("Device-D", PumpEnum.AlarmType.Attention, "D1");
|
||||
|
||||
var found = await _repo.FindActiveAsync("Device-D", PumpEnum.AlarmType.Attention, "D1");
|
||||
Assert.That(found, Is.Null);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// DELETE BY PATIENT ID
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>DeleteByPatientId</c> method successfully removes a previously upserted
|
||||
/// <see cref="PumpAlarmState"/> for the specified patient, ensuring no matching records remain in the collection.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteByPatientId_Works()
|
||||
{
|
||||
var pid = ObjectId.GenerateNewId();
|
||||
|
||||
var alarm = new PumpAlarmState
|
||||
public async Task DeleteByPatientId_Works()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-E",
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "DDD",
|
||||
PatientId = pid,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
await _repo.DeleteByPatientId(pid);
|
||||
|
||||
var list = await _repo.Collection.FindAsync(x => x.PatientId == pid);
|
||||
Assert.That(await list.AnyAsync(), Is.False);
|
||||
}
|
||||
var pid = ObjectId.GenerateNewId();
|
||||
|
||||
var alarm = new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-E",
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "DDD",
|
||||
PatientId = pid,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
await _repo.DeleteByPatientId(pid);
|
||||
|
||||
var list = await _repo.Collection.FindAsync(x => x.PatientId == pid);
|
||||
Assert.That(await list.AnyAsync(), Is.False);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// FIND ALL ACTIVE BY DEVICE
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindAllActiveByDeviceAsync</c> returns only active pump alarm states that belong to the specified device.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAllActiveByDeviceAsync_ReturnsCorrect()
|
||||
{
|
||||
var result = await _repo.FindAllActiveByDeviceAsync(DeviceA);
|
||||
|
||||
var pumpAlarmStates = result.ToList();
|
||||
Assert.That(pumpAlarmStates, Is.Not.Empty);
|
||||
Assert.That(pumpAlarmStates.All(x => x.DeviceId == DeviceA), Is.True);
|
||||
}
|
||||
public async Task FindAllActiveByDeviceAsync_ReturnsCorrect()
|
||||
{
|
||||
var result = await _repo.FindAllActiveByDeviceAsync(DeviceA);
|
||||
|
||||
var pumpAlarmStates = result.ToList();
|
||||
Assert.That(pumpAlarmStates, Is.Not.Empty);
|
||||
Assert.That(pumpAlarmStates.All(x => x.DeviceId == DeviceA), Is.True);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// UPDATE MANY BY FIELD
|
||||
// -------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>UpdateManyObjectIdByFieldNameAsync</c> successfully updates the <c>PatientId</c> field
|
||||
/// from the old ObjectId to a new ObjectId for matching documents, returning the expected count of
|
||||
/// updated records and making the document retrievable by the new ObjectId.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateManyObjectIdByFieldNameAsync_Works()
|
||||
{
|
||||
var oldId = ObjectId.GenerateNewId();
|
||||
var newId = ObjectId.GenerateNewId();
|
||||
|
||||
// Insert one alarm to update
|
||||
var alarm = new PumpAlarmState
|
||||
public async Task UpdateManyObjectIdByFieldNameAsync_Works()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-F",
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "FFF",
|
||||
PatientId = oldId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
var updated = await _repo.UpdateManyObjectIdByFieldNameAsync("PatientId", newId, oldId);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(updated, Is.EqualTo(1));
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.PatientId == newId);
|
||||
Assert.That(await found.AnyAsync(), Is.True);
|
||||
var oldId = ObjectId.GenerateNewId();
|
||||
var newId = ObjectId.GenerateNewId();
|
||||
|
||||
// Insert one alarm to update
|
||||
var alarm = new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-F",
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = "FFF",
|
||||
PatientId = oldId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
var updated = await _repo.UpdateManyObjectIdByFieldNameAsync("PatientId", newId, oldId);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(updated, Is.EqualTo(1));
|
||||
|
||||
var found = await _repo.Collection.FindAsync(x => x.PatientId == newId);
|
||||
Assert.That(await found.AnyAsync(), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpsertActiveAsync_NoDuplicateOnRepeatedCalls()
|
||||
@@ -264,60 +294,66 @@ public class PumpAlarmStateRepositoryTest
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that UpsertActiveAsync correctly inserts a PumpAlarmState record when the AlarmCodeMdc is null, and that the record can be retrieved via FindActiveAsync using a null alarm code.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpsertActiveAsync_InsertsWhenAlarmCodeIsNull()
|
||||
{
|
||||
var alarm = new PumpAlarmState
|
||||
public async Task UpsertActiveAsync_InsertsWhenAlarmCodeIsNull()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-NullCode",
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = null,
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
var found = await _repo.FindActiveAsync("Device-NullCode", PumpEnum.AlarmType.Occlusion, null);
|
||||
|
||||
Assert.That(found, Is.Not.Null);
|
||||
Assert.That(found!.AlarmCodeMdc, Is.Null);
|
||||
}
|
||||
var alarm = new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-NullCode",
|
||||
AlarmType = PumpEnum.AlarmType.Occlusion,
|
||||
AlarmCodeMdc = null,
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
};
|
||||
|
||||
await _repo.UpsertActiveAsync(alarm);
|
||||
|
||||
var found = await _repo.FindActiveAsync("Device-NullCode", PumpEnum.AlarmType.Occlusion, null);
|
||||
|
||||
Assert.That(found, Is.Not.Null);
|
||||
Assert.That(found!.AlarmCodeMdc, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>RemoveAsync</c> removes every active alarm matching the specified device identifier and alarm type, not just a single record.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task RemoveAsync_RemovesAllMatching()
|
||||
{
|
||||
var alarms = new[]
|
||||
public async Task RemoveAsync_RemovesAllMatching()
|
||||
{
|
||||
new PumpAlarmState
|
||||
var alarms = new[]
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Multi",
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
AlarmCodeMdc = "XX1",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
},
|
||||
new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Multi",
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
AlarmCodeMdc = "XX2",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var a in alarms)
|
||||
await _repo.UpsertActiveAsync(a);
|
||||
|
||||
await _repo.RemoveAsync("Device-Multi", PumpEnum.AlarmType.AirInLine);
|
||||
|
||||
var remaining = await _repo.FindAllActiveByDeviceAsync("Device-Multi");
|
||||
|
||||
Assert.That(remaining, Is.Empty);
|
||||
}
|
||||
new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Multi",
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
AlarmCodeMdc = "XX1",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
},
|
||||
new PumpAlarmState
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = "Device-Multi",
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
AlarmCodeMdc = "XX2",
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var a in alarms)
|
||||
await _repo.UpsertActiveAsync(a);
|
||||
|
||||
await _repo.RemoveAsync("Device-Multi", PumpEnum.AlarmType.AirInLine);
|
||||
|
||||
var remaining = await _repo.FindAllActiveByDeviceAsync("Device-Multi");
|
||||
|
||||
Assert.That(remaining, Is.Empty);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -175,19 +175,22 @@ public class PumpArchiveRepositoryTest
|
||||
private static readonly DateTime Now = DateTime.Now;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the <c>DeleteBeforeDate</c> repository method removes all records with a date earlier than the specified cutoff, retaining only records dated on or after that cutoff.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddDays(-1));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddDays(-1));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,11 @@ public class PumpStateRepositoryTest
|
||||
// ============================================================
|
||||
// INIT
|
||||
// ============================================================
|
||||
/// <summary>
|
||||
/// One-time setup that prepares the integration test environment for the PumpStateRepository by recreating the
|
||||
/// "pump_states" MongoDB collection, building the repository indexes, and seeding two initial pump states (one
|
||||
/// actively infusing for a known patient/device and one not infusing) to verify the baseline document count.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
@@ -43,26 +48,26 @@ public class PumpStateRepositoryTest
|
||||
|
||||
// Insertar estados iniciales
|
||||
var initialStates = new List<PumpState>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now,
|
||||
IsInfusing = true,
|
||||
Status = PumpEnum.Status.Infusing,
|
||||
PumpMode = PumpEnum.Mode.Infusing
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceB,
|
||||
LastUpdated = Now.AddSeconds(-10),
|
||||
IsInfusing = false,
|
||||
Status = PumpEnum.Status.NotInfusing
|
||||
}
|
||||
};
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceA,
|
||||
PatientId = PatientId,
|
||||
LastUpdated = Now,
|
||||
IsInfusing = true,
|
||||
Status = PumpEnum.Status.Infusing,
|
||||
PumpMode = PumpEnum.Mode.Infusing
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
DeviceId = DeviceB,
|
||||
LastUpdated = Now.AddSeconds(-10),
|
||||
IsInfusing = false,
|
||||
Status = PumpEnum.Status.NotInfusing
|
||||
}
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.GetCollection<PumpState>("pump_states")
|
||||
.InsertManyAsync(initialStates);
|
||||
@@ -74,6 +79,9 @@ public class PumpStateRepositoryTest
|
||||
// ============================================================
|
||||
// FIND BY DEVICE ID
|
||||
// ============================================================
|
||||
/// <summary>
|
||||
/// Verifies that FindByDeviceIdAsync retrieves the correct infusion state for a given device, returning a non-null result that matches the requested device identifier and reflects the expected infusion status.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByDeviceIdAsync_ReturnsCorrectState()
|
||||
{
|
||||
@@ -90,6 +98,9 @@ public class PumpStateRepositoryTest
|
||||
// ============================================================
|
||||
// UPSERT (INSERT + UPDATE)
|
||||
// ============================================================
|
||||
/// <summary>
|
||||
/// Verifies that <c>UpsertAsync</c> inserts a new <see cref="PumpState"/> record when no existing entry is found for the specified <c>DeviceId</c>, and that the persisted state retains the provided property values.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpsertAsync_InsertsNewWhenNotExists()
|
||||
{
|
||||
@@ -108,6 +119,11 @@ public class PumpStateRepositoryTest
|
||||
Assert.That(found!.IsInfusing, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>UpsertAsync</c> correctly updates an existing pump state in the repository, ensuring
|
||||
/// the updated <see cref="PumpState"/> is persisted and retrievable with the modified <c>IsInfusing</c>,
|
||||
/// <c>Status</c>, and <c>LastUpdated</c> values.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpsertAsync_UpdatesExistingState()
|
||||
{
|
||||
@@ -130,7 +146,7 @@ public class PumpStateRepositoryTest
|
||||
Assert.That(found!.IsInfusing, Is.False);
|
||||
Assert.That(found.Status, Is.EqualTo(PumpEnum.Status.NotInfusing));
|
||||
Assert.That(
|
||||
found.LastUpdated,
|
||||
found.LastUpdated,
|
||||
Is.EqualTo(updated.LastUpdated).Within(TimeSpan.FromMilliseconds(1))
|
||||
);
|
||||
}
|
||||
@@ -139,6 +155,9 @@ public class PumpStateRepositoryTest
|
||||
// ============================================================
|
||||
// GET ALL
|
||||
// ============================================================
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetAllAsync</c> returns a non-null collection of pump states containing at least two entries, including those associated with the seeded devices A and B.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAllAsync_ReturnsAllStates()
|
||||
{
|
||||
@@ -161,6 +180,9 @@ public class PumpStateRepositoryTest
|
||||
// ============================================================
|
||||
// UNIQUE INDEX: UPSERT OVERWRITES (NO DUPLICADOS)
|
||||
// ============================================================
|
||||
/// <summary>
|
||||
/// Verifies that UpsertAsync updates an existing entity instead of inserting a duplicate, ensuring the total record count remains unchanged when upserting a <see cref="PumpState"/> for an already-known device identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpsertAsync_DoesNotCreateDuplicates()
|
||||
{
|
||||
|
||||
@@ -12,35 +12,38 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class RecordingAlertArchiveRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time test setup that prepares the archive collection for recording-alert integration tests by clearing it, creating a fresh instance of <see cref="RecordingAlertArchiveRepository"/>, and seeding it with two patient recording alerts (one matching the current patient with the current timestamp and one for a different patient dated ten days earlier), verifying that both records are persisted.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var recordingAlert1 = new PatientRecordingAlert
|
||||
public async Task Init()
|
||||
{
|
||||
PatientId = PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var recordingAlert2 = new PatientRecordingAlert
|
||||
{
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-10)
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_recordingalerts");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_recordingalerts");
|
||||
|
||||
_repository = new RecordingAlertArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert1);
|
||||
await _repository.InsertOneAsync(recordingAlert2);
|
||||
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(2));
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var recordingAlert1 = new PatientRecordingAlert
|
||||
{
|
||||
PatientId = PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var recordingAlert2 = new PatientRecordingAlert
|
||||
{
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-10)
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_recordingalerts");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_recordingalerts");
|
||||
|
||||
_repository = new RecordingAlertArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert1);
|
||||
await _repository.InsertOneAsync(recordingAlert2);
|
||||
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
private RecordingAlertArchiveRepository _repository;
|
||||
|
||||
@@ -55,19 +58,23 @@ public class RecordingAlertArchiveRepositoryTest
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>DeleteBeforeDate</c> operation removes all documents dated before the specified cutoff date, leaving only documents on or after that date.
|
||||
/// Expects more than one document in the collection initially and exactly one remaining after deletion.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddDays(-1));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddDays(-1));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -12,35 +12,39 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class RecordingAlertRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time test setup that initializes the recording alert repository with two sample patient recording alerts
|
||||
/// and ensures the underlying collection contains exactly two documents for integration test scenarios.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var recordingAlert1 = new PatientRecordingAlert
|
||||
public async Task Init()
|
||||
{
|
||||
PatientId = PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var recordingAlert2 = new PatientRecordingAlert
|
||||
{
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-10)
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_recordingalerts");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_recordingalerts");
|
||||
|
||||
_repository = new RecordingAlertRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert1);
|
||||
await _repository.InsertOneAsync(recordingAlert2);
|
||||
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(2));
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var recordingAlert1 = new PatientRecordingAlert
|
||||
{
|
||||
PatientId = PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var recordingAlert2 = new PatientRecordingAlert
|
||||
{
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-10)
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_recordingalerts");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_recordingalerts");
|
||||
|
||||
_repository = new RecordingAlertRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert1);
|
||||
await _repository.InsertOneAsync(recordingAlert2);
|
||||
|
||||
Assert.That(await _repository.Collection.CountDocumentsAsync(_ => true), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
private RecordingAlertRepository _repository;
|
||||
|
||||
@@ -55,227 +59,251 @@ public class RecordingAlertRepositoryTest
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's DeleteAsync method successfully removes a PatientRecordingAlert document, confirming the record exists prior to deletion and is no longer retrievable afterwards.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteAsync()
|
||||
{
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
public async Task DeleteAsync()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.Id == recordingAlert.Id);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.DeleteAsync(recordingAlert.Id);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.Id == recordingAlert.Id);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.Id == recordingAlert.Id);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.DeleteAsync(recordingAlert.Id);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.Id == recordingAlert.Id);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the <c>DeleteOlderDaysAsync</c> repository method removes patient recording alerts that exceed the specified age threshold and match the given recording name, while preserving alerts within the threshold.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteOlderDaysAsync()
|
||||
{
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
public async Task DeleteOlderDaysAsync()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now,
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5),
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(2));
|
||||
|
||||
await _repository.DeleteOlderDaysAsync("recordingName1", 2);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
|
||||
await _repository.Collection.DeleteManyAsync(d => d.PatientId == recordingAlert.PatientId);
|
||||
|
||||
var resultClear = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultClear.ToList(), Has.Count.EqualTo(0));
|
||||
}
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now,
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5),
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(2));
|
||||
|
||||
await _repository.DeleteOlderDaysAsync("recordingName1", 2);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
|
||||
await _repository.Collection.DeleteManyAsync(d => d.PatientId == recordingAlert.PatientId);
|
||||
|
||||
var resultClear = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultClear.ToList(), Has.Count.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>DeleteOlderNumberAsync</c> removes older records with the specified name, keeping only the most recent ones according to the provided count.
|
||||
/// Inserts two <see cref="PatientRecordingAlert"/> entries sharing the same name but different timestamps, asserts both exist, performs the deletion, and confirms that only one record remains.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteOlderNumberAsync()
|
||||
{
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
public async Task DeleteOlderNumberAsync()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now,
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5),
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.Name == "recordingName1");
|
||||
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(2));
|
||||
|
||||
await _repository.DeleteOlderNumberAsync("recordingName1", 1);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.Name == "recordingName1");
|
||||
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now,
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5),
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.Name == "recordingName1");
|
||||
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(2));
|
||||
|
||||
await _repository.DeleteOlderNumberAsync("recordingName1", 1);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.Name == "recordingName1");
|
||||
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>DeleteByPatientId</c> removes a patient's recording alert from the repository, ensuring the alert cannot be retrieved after deletion.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteByPatientId()
|
||||
{
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
public async Task DeleteByPatientId()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5)
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.DeleteByPatientId(recordingAlert.PatientId);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5)
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.DeleteByPatientId(recordingAlert.PatientId);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns a non-null result when searching for records by patient identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientIdAsync()
|
||||
{
|
||||
var result = await _repository.FindByPatientIdAsync(PatientId);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
}
|
||||
public async Task FindByPatientIdAsync()
|
||||
{
|
||||
var result = await _repository.FindByPatientIdAsync(PatientId);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindLastObservations</c> returns only the most recent recording alert
|
||||
/// for a given patient and recording name, filtering out older entries based on the
|
||||
/// specified count limit, and that the returned observation matches the expected time.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindLastObservations()
|
||||
{
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
public async Task FindLastObservations()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now,
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5),
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(2));
|
||||
|
||||
var resultFind = await _repository.FindLastObservations(recordingAlert.PatientId, "recordingName1", 1);
|
||||
|
||||
Assert.That(resultFind, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(resultFind.ToList(), Has.Count.EqualTo(1));
|
||||
Assert.That(resultFind.FirstOrDefault()?.Time.Day, Is.EqualTo(Now.Day));
|
||||
Assert.That(resultFind.FirstOrDefault()?.Time.Month, Is.EqualTo(Now.Month));
|
||||
Assert.That(resultFind.FirstOrDefault()?.Time.Year, Is.EqualTo(Now.Year));
|
||||
};
|
||||
await _repository.DeleteByPatientId(recordingAlert.PatientId);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now,
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
var recordingAlertOld = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = recordingAlert.PatientId,
|
||||
IsRecording = true,
|
||||
Time = Now.AddDays(-5),
|
||||
Name = "recordingName1"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
await _repository.InsertOneAsync(recordingAlertOld);
|
||||
|
||||
var result = await _repository.Collection.FindAsync(_ => true);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(2));
|
||||
|
||||
var resultFind = await _repository.FindLastObservations(recordingAlert.PatientId, "recordingName1", 1);
|
||||
|
||||
Assert.That(resultFind, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(resultFind.ToList(), Has.Count.EqualTo(1));
|
||||
Assert.That(resultFind.FirstOrDefault()?.Time.Day, Is.EqualTo(Now.Day));
|
||||
Assert.That(resultFind.FirstOrDefault()?.Time.Month, Is.EqualTo(Now.Month));
|
||||
Assert.That(resultFind.FirstOrDefault()?.Time.Year, Is.EqualTo(Now.Year));
|
||||
};
|
||||
await _repository.DeleteByPatientId(recordingAlert.PatientId);
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the repository's ability to update the <c>patientid</c> ObjectId field across records, verifying that after the update the original patient identifier no longer returns any alerts while the new patient identifier does, and that deletion by patient ID subsequently removes the record.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateManyObjectId()
|
||||
{
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
public async Task UpdateManyObjectId()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var newPatientId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
|
||||
var result = await _repository.FindByPatientIdAsync(recordingAlert.PatientId);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.UpdateManyObjectId("patientid", newPatientId, recordingAlert.PatientId);
|
||||
|
||||
var resultOldId = await _repository.FindByPatientIdAsync(recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultOldId.FirstOrDefault(), Is.Null);
|
||||
|
||||
var resultNewId = await _repository.FindByPatientIdAsync(newPatientId);
|
||||
|
||||
Assert.That(resultNewId.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.DeleteByPatientId(newPatientId);
|
||||
|
||||
var resultDelete = await _repository.FindByPatientIdAsync(newPatientId);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
var recordingAlert = new PatientRecordingAlert
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
IsRecording = true,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var newPatientId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.InsertOneAsync(recordingAlert);
|
||||
|
||||
var result = await _repository.FindByPatientIdAsync(recordingAlert.PatientId);
|
||||
|
||||
Assert.That(result.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.UpdateManyObjectId("patientid", newPatientId, recordingAlert.PatientId);
|
||||
|
||||
var resultOldId = await _repository.FindByPatientIdAsync(recordingAlert.PatientId);
|
||||
|
||||
Assert.That(resultOldId.FirstOrDefault(), Is.Null);
|
||||
|
||||
var resultNewId = await _repository.FindByPatientIdAsync(newPatientId);
|
||||
|
||||
Assert.That(resultNewId.FirstOrDefault(), Is.Not.Null);
|
||||
|
||||
await _repository.DeleteByPatientId(newPatientId);
|
||||
|
||||
var resultDelete = await _repository.FindByPatientIdAsync(newPatientId);
|
||||
|
||||
Assert.That(resultDelete.FirstOrDefault(), Is.Null);
|
||||
}
|
||||
}
|
||||
@@ -11,24 +11,27 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class ServiceConfigRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time initialization for integration tests by creating a <see cref="ServiceConfig"/> entry in the test database and preparing the repository used by the test fixture.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var serviceConfig = new ServiceConfig
|
||||
public async Task Init()
|
||||
{
|
||||
Id = _id,
|
||||
StrId = Id.ToString()
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("service_config");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("service_config");
|
||||
|
||||
_repository = new ServiceConfigRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(serviceConfig);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var serviceConfig = new ServiceConfig
|
||||
{
|
||||
Id = _id,
|
||||
StrId = Id.ToString()
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("service_config");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("service_config");
|
||||
|
||||
_repository = new ServiceConfigRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(serviceConfig);
|
||||
}
|
||||
|
||||
private ServiceConfigRepository _repository;
|
||||
|
||||
@@ -43,21 +46,29 @@ public class ServiceConfigRepositoryTest
|
||||
private static readonly ObjectId Id = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="_repository"/>.FindById returns a non-null entity when queried by its string identifier,
|
||||
/// and that the returned entity's <c>StrId</c> matches the supplied id.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Find_string()
|
||||
{
|
||||
var result = await _repository.FindById(Id.ToString());
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.StrId, Is.EqualTo(Id.ToString()));
|
||||
}
|
||||
public async Task FindById_Find_string()
|
||||
{
|
||||
var result = await _repository.FindById(Id.ToString());
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.StrId, Is.EqualTo(Id.ToString()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindById method successfully retrieves an object by its identifier,
|
||||
/// returning a non-null result whose Id matches the requested identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_Find_ObjectId()
|
||||
{
|
||||
var result = await _repository.FindById(_id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.Id, Is.EqualTo(_id));
|
||||
}
|
||||
public async Task FindById_Find_ObjectId()
|
||||
{
|
||||
var result = await _repository.FindById(_id);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result!.Id, Is.EqualTo(_id));
|
||||
}
|
||||
}
|
||||
@@ -13,47 +13,50 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class TreatmentArchiveRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time setup method that prepares the integration test environment for the treatment archive repository by creating and inserting two sample patient treatments (one new and one discontinued) into a freshly created archive collection.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var treatment1 = new PatientTreatment
|
||||
public async Task Init()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
OrderControl = OrderControlType.Nw,
|
||||
PlacerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
FillerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
OrderStatus = "A",
|
||||
OrderTime = DateTime.Now,
|
||||
Notes = [],
|
||||
Routes = []
|
||||
};
|
||||
|
||||
var treatment2 = new PatientTreatment
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
OrderControl = OrderControlType.Dc,
|
||||
PlacerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
FillerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
OrderStatus = "A",
|
||||
OrderTime = DateTime.Now.AddDays(-5),
|
||||
Notes = [],
|
||||
Routes = []
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_treatments");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_treatments");
|
||||
|
||||
_repository = new TreatmentArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(treatment1);
|
||||
await _repository.InsertOneAsync(treatment2);
|
||||
|
||||
Assert.That(_repository.Collection.FindAsync(_ => true).Result.ToList(), Has.Count.EqualTo(2));
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var treatment1 = new PatientTreatment
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
OrderControl = OrderControlType.Nw,
|
||||
PlacerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
FillerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
OrderStatus = "A",
|
||||
OrderTime = DateTime.Now,
|
||||
Notes = [],
|
||||
Routes = []
|
||||
};
|
||||
|
||||
var treatment2 = new PatientTreatment
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = PatientId,
|
||||
OrderControl = OrderControlType.Dc,
|
||||
PlacerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
FillerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
||||
OrderStatus = "A",
|
||||
OrderTime = DateTime.Now.AddDays(-5),
|
||||
Notes = [],
|
||||
Routes = []
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("archive_patients_treatments");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_treatments");
|
||||
|
||||
_repository = new TreatmentArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(treatment1);
|
||||
await _repository.InsertOneAsync(treatment2);
|
||||
|
||||
Assert.That(_repository.Collection.FindAsync(_ => true).Result.ToList(), Has.Count.EqualTo(2));
|
||||
}
|
||||
|
||||
private TreatmentArchiveRepository _repository;
|
||||
|
||||
@@ -68,28 +71,35 @@ public class TreatmentArchiveRepositoryTest
|
||||
private static readonly ObjectId PatientId = ObjectId.GenerateNewId();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests the <see cref="DeleteBeforeDate"/> repository method to ensure it correctly removes records older than the specified cutoff date,
|
||||
/// leaving only the most recent record. Verifies that when multiple patient records exist, deletion by date retains exactly one record.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddHours(-2));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
public async Task DeleteBeforeDate()
|
||||
{
|
||||
var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(1));
|
||||
|
||||
await _repository.DeleteBeforeDate(Now.AddHours(-2));
|
||||
|
||||
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
||||
|
||||
Assert.That(resultDelete, Is.Not.Null);
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository successfully retrieves a non-empty collection of records associated with the specified patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindAllFromPatient()
|
||||
{
|
||||
var result = await _repository.FindAllFromPatient(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(0));
|
||||
}
|
||||
public async Task FindAllFromPatient()
|
||||
{
|
||||
var result = await _repository.FindAllFromPatient(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Has.Count.GreaterThan(0));
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class TreatmentRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time test setup that resets the treatments collection, instantiates the repository, and seeds two patient treatments (one with OrderControlType.Nw and one with OrderControlType.Dc) to verify insert behavior.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
@@ -45,7 +48,7 @@ public class TreatmentRepositoryTest
|
||||
RequestedGiveCodesStatus =
|
||||
[
|
||||
new CodeStatus
|
||||
{ Code = new Code { CodingSystem = "CS", Identifier = "I", Text = "T" }, Status = "status" }
|
||||
{ Code = new Code { CodingSystem = "CS", Identifier = "I", Text = "T" }, Status = "status" }
|
||||
]
|
||||
};
|
||||
|
||||
@@ -75,6 +78,9 @@ public class TreatmentRepositoryTest
|
||||
private PatientTreatment _treatment2 = null!;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that GetByPatientId returns an empty result collection rather than null when no patient treatments are found for the supplied patient identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByPatientId_Not_Find_Return_Null()
|
||||
{
|
||||
@@ -85,6 +91,10 @@ public class TreatmentRepositoryTest
|
||||
Assert.That(patientTreatments.ToList(), Is.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the repository's <c>GetByPatientId</c> method returns the expected patient treatment records
|
||||
/// for the given patient, verifying that the result is not null and contains the expected number of entries.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByPatientId_Find_Return_Null()
|
||||
{
|
||||
@@ -95,6 +105,10 @@ public class TreatmentRepositoryTest
|
||||
Assert.That(patientTreatments.ToList(), Has.Count.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DeleteAsync"/> successfully removes a persisted patient treatment from the repository.
|
||||
/// The test inserts a treatment, confirms it exists, deletes it by id, and asserts it is no longer retrievable.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteAsync()
|
||||
{
|
||||
@@ -126,6 +140,9 @@ public class TreatmentRepositoryTest
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>FindByPatientIdAsync</c> returns a non-null list containing the expected number of treatments for the specified patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientIdAsync_Find_Return_List_Traetments()
|
||||
{
|
||||
@@ -135,6 +152,9 @@ public class TreatmentRepositoryTest
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DeleteByPatientId"/> removes the patient treatment associated with the given patient identifier, ensuring no records remain for that patient after deletion.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task DeleteByPatientId()
|
||||
{
|
||||
@@ -166,6 +186,9 @@ public class TreatmentRepositoryTest
|
||||
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that _repository.FindBolusTreatments returns a non-null collection containing exactly one bolus treatment for the specified patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindBolusTreatments_Find_Return_Treatment()
|
||||
{
|
||||
@@ -175,6 +198,9 @@ public class TreatmentRepositoryTest
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that FindByPatientIdAsync returns a non-null list containing the expected number of treatments for the specified patient.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByPatientId_Find_Return_List_Traetments()
|
||||
{
|
||||
|
||||
@@ -12,36 +12,39 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class UnitRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time setup method that prepares the integration test environment by configuring API settings, creating a fresh "units" collection in the database, and seeding it with two sample <see cref="Unit"/> records via the <see cref="UnitRepository"/>.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
// Set up your test environment, including database connection
|
||||
|
||||
// Mocking ApiSettings
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
// Creating sample unit data
|
||||
var unit1 = new Unit
|
||||
public async Task Init()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "unit1"
|
||||
// Add other properties as needed
|
||||
};
|
||||
|
||||
var unit2 = new Unit
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "unit2"
|
||||
// Add other properties as needed
|
||||
};
|
||||
|
||||
// Insert sample data into the database
|
||||
await IntegrationDb.Database.DropCollectionAsync("units");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("units");
|
||||
_repository = new UnitRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
await _repository.InsertOneUnit(unit1);
|
||||
await _repository.InsertOneUnit(unit2);
|
||||
}
|
||||
// Set up your test environment, including database connection
|
||||
|
||||
// Mocking ApiSettings
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
// Creating sample unit data
|
||||
var unit1 = new Unit
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "unit1"
|
||||
// Add other properties as needed
|
||||
};
|
||||
|
||||
var unit2 = new Unit
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "unit2"
|
||||
// Add other properties as needed
|
||||
};
|
||||
|
||||
// Insert sample data into the database
|
||||
await IntegrationDb.Database.DropCollectionAsync("units");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("units");
|
||||
_repository = new UnitRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
await _repository.InsertOneUnit(unit1);
|
||||
await _repository.InsertOneUnit(unit2);
|
||||
}
|
||||
|
||||
private UnitRepository _repository;
|
||||
|
||||
@@ -52,37 +55,40 @@ public class UnitRepositoryTest
|
||||
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that inserting a valid <see cref="Unit"/> into the repository returns the unit and that the inserted unit can be successfully retrieved by its identifier, with key properties preserved.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOneUnit_ValidUnit_ReturnsUnit()
|
||||
{
|
||||
// Arrange
|
||||
var unit = new Unit
|
||||
public async Task InsertOneUnit_ValidUnit_ReturnsUnit()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Title = "Test Unit",
|
||||
Name = "Test Unit",
|
||||
LastUpdate = DateTime.UtcNow,
|
||||
PointOfCareIds = [ObjectId.GenerateNewId()],
|
||||
Status = StatusEnum.Type.Ok,
|
||||
Configuration = new UnitConfiguration
|
||||
// Arrange
|
||||
var unit = new Unit
|
||||
{
|
||||
AutoAdt = true,
|
||||
},
|
||||
AltableOptionListId = ObjectId.GenerateNewId(),
|
||||
AllergyListId = ObjectId.GenerateNewId()
|
||||
};
|
||||
|
||||
// Act
|
||||
var insertResult = await _repository.InsertOneUnit(unit);
|
||||
var findResult = await _repository.FindById(unit.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(insertResult, Is.Not.Null);
|
||||
Assert.That(findResult, Is.Not.Null);
|
||||
Assert.That(findResult?.Id, Is.EqualTo(unit.Id));
|
||||
Assert.That(findResult?.Title, Is.EqualTo(unit.Title));
|
||||
Assert.That(findResult?.Name, Is.EqualTo(unit.Name));
|
||||
}
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Title = "Test Unit",
|
||||
Name = "Test Unit",
|
||||
LastUpdate = DateTime.UtcNow,
|
||||
PointOfCareIds = [ObjectId.GenerateNewId()],
|
||||
Status = StatusEnum.Type.Ok,
|
||||
Configuration = new UnitConfiguration
|
||||
{
|
||||
AutoAdt = true,
|
||||
},
|
||||
AltableOptionListId = ObjectId.GenerateNewId(),
|
||||
AllergyListId = ObjectId.GenerateNewId()
|
||||
};
|
||||
|
||||
// Act
|
||||
var insertResult = await _repository.InsertOneUnit(unit);
|
||||
var findResult = await _repository.FindById(unit.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(insertResult, Is.Not.Null);
|
||||
Assert.That(findResult, Is.Not.Null);
|
||||
Assert.That(findResult?.Id, Is.EqualTo(unit.Id));
|
||||
Assert.That(findResult?.Title, Is.EqualTo(unit.Title));
|
||||
Assert.That(findResult?.Name, Is.EqualTo(unit.Name));
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task FindByLocation_ValidLocation_ReturnsUnit()
|
||||
@@ -116,40 +122,46 @@ public class UnitRepositoryTest
|
||||
// Assert.That(result?.Id, Is.EqualTo(unit.Id));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that FindById retrieves the matching <see cref="Unit"/> from the repository when a valid identifier is provided.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_ValidId_ReturnsUnit()
|
||||
{
|
||||
// Arrange
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
var unit = new Unit
|
||||
public async Task FindById_ValidId_ReturnsUnit()
|
||||
{
|
||||
Id = unitId,
|
||||
Title = "Test Unit",
|
||||
Name = "Test Unit"
|
||||
};
|
||||
|
||||
await _repository.InsertOneUnit(unit);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(unitId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(unitId));
|
||||
}
|
||||
// Arrange
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
var unit = new Unit
|
||||
{
|
||||
Id = unitId,
|
||||
Title = "Test Unit",
|
||||
Name = "Test Unit"
|
||||
};
|
||||
|
||||
await _repository.InsertOneUnit(unit);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(unitId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(unitId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that FindById returns <c>null</c> when queried with an ID that does not exist in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindById_InvalidId_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var invalidId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(invalidId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindById_InvalidId_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var invalidId = ObjectId.GenerateNewId();
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindById(invalidId);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task FindByMasterListId_ValidId_ReturnsMatchingUnits()
|
||||
@@ -191,40 +203,47 @@ public class UnitRepositoryTest
|
||||
// // Add more assertions as needed
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>FindByName</c> method returns the matching unit when called with a valid unit name.
|
||||
/// The test inserts a unit, retrieves it by name, and asserts that the returned entity is not null and has the expected name.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByName_ValidName_ReturnsUnit()
|
||||
{
|
||||
// Arrange
|
||||
var unitName = "TestUnit";
|
||||
var unit = new Unit
|
||||
public async Task FindByName_ValidName_ReturnsUnit()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Title = "Test Unit",
|
||||
Name = unitName
|
||||
};
|
||||
|
||||
await _repository.InsertOneUnit(unit);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByName(unitName);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo(unitName));
|
||||
}
|
||||
// Arrange
|
||||
var unitName = "TestUnit";
|
||||
var unit = new Unit
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Title = "Test Unit",
|
||||
Name = unitName
|
||||
};
|
||||
|
||||
await _repository.InsertOneUnit(unit);
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByName(unitName);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Name, Is.EqualTo(unitName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's FindByName method returns null when invoked with a name that does not match any existing entity.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task FindByName_InvalidName_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var invalidName = "NonExistentUnitName";
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByName(invalidName);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
public async Task FindByName_InvalidName_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var invalidName = "NonExistentUnitName";
|
||||
|
||||
// Act
|
||||
var result = await _repository.FindByName(invalidName);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
// [Test]
|
||||
// public async Task FindByPointOfCare_ValidPointOfCare_ReturnsUnit()
|
||||
@@ -323,55 +342,62 @@ public class UnitRepositoryTest
|
||||
// Assert.That(result, Is.Empty);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetAll</c> returns a non-null collection containing the units that have been inserted into the repository.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the <c>units</c> collection used to seed the repository is <c>null</c>.</exception>
|
||||
[Test]
|
||||
public async Task GetAll_ReturnsAllUnits()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
var units = new List<Unit>();
|
||||
if (units == null) throw new ArgumentNullException(nameof(units));
|
||||
for (var i = 0; i < 5; i++)
|
||||
public async Task GetAll_ReturnsAllUnits()
|
||||
{
|
||||
var unit = new Unit
|
||||
// Arrange
|
||||
|
||||
var units = new List<Unit>();
|
||||
if (units == null) throw new ArgumentNullException(nameof(units));
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
Id = ObjectId.GenerateNewId()
|
||||
};
|
||||
units.Add(unit);
|
||||
await _repository.InsertOneUnit(unit);
|
||||
var unit = new Unit
|
||||
{
|
||||
Id = ObjectId.GenerateNewId()
|
||||
};
|
||||
units.Add(unit);
|
||||
await _repository.InsertOneUnit(unit);
|
||||
}
|
||||
|
||||
// Act
|
||||
var result = await _repository.GetAll();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.Not.EqualTo(0));
|
||||
}
|
||||
|
||||
// Act
|
||||
var result = await _repository.GetAll();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Has.Count.Not.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that UpdateUnit correctly updates an existing unit in the repository and returns the updated entity with the new title and the original identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateUnit_ValidUnit_ReturnsUpdatedUnit()
|
||||
{
|
||||
// Arrange
|
||||
var originalUnit = new Unit
|
||||
public async Task UpdateUnit_ValidUnit_ReturnsUpdatedUnit()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Title = "Original Title"
|
||||
};
|
||||
|
||||
var updatedUnit = new Unit
|
||||
{
|
||||
Id = originalUnit.Id,
|
||||
Title = "Updated Title"
|
||||
};
|
||||
|
||||
await _repository.InsertOneUnit(originalUnit);
|
||||
|
||||
// Act
|
||||
var result = await _repository.UpdateUnit(updatedUnit);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(originalUnit.Id));
|
||||
Assert.That(result?.Title, Is.EqualTo(updatedUnit.Title));
|
||||
}
|
||||
// Arrange
|
||||
var originalUnit = new Unit
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Title = "Original Title"
|
||||
};
|
||||
|
||||
var updatedUnit = new Unit
|
||||
{
|
||||
Id = originalUnit.Id,
|
||||
Title = "Updated Title"
|
||||
};
|
||||
|
||||
await _repository.InsertOneUnit(originalUnit);
|
||||
|
||||
// Act
|
||||
var result = await _repository.UpdateUnit(updatedUnit);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result?.Id, Is.EqualTo(originalUnit.Id));
|
||||
Assert.That(result?.Title, Is.EqualTo(updatedUnit.Title));
|
||||
}
|
||||
}
|
||||
@@ -11,35 +11,38 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class UserRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// One-time integration test setup that prepares a clean "users" collection in the test database and seeds it with two predefined users, ensuring a deterministic state for downstream test cases.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var user1 = new User
|
||||
public async Task Init()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UserName = "username1",
|
||||
Password = "password1"
|
||||
//Rol = "rol1"
|
||||
};
|
||||
|
||||
var user2 = new User
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UserName = "username2",
|
||||
Password = "password2"
|
||||
//Rol = "rol2"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("users");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("users");
|
||||
|
||||
_repository = new UserRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(user1);
|
||||
await _repository.InsertOneAsync(user2);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var user1 = new User
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UserName = "username1",
|
||||
Password = "password1"
|
||||
//Rol = "rol1"
|
||||
};
|
||||
|
||||
var user2 = new User
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UserName = "username2",
|
||||
Password = "password2"
|
||||
//Rol = "rol2"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("users");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("users");
|
||||
|
||||
_repository = new UserRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(user1);
|
||||
await _repository.InsertOneAsync(user2);
|
||||
}
|
||||
|
||||
private UserRepository _repository = null!;
|
||||
|
||||
@@ -51,17 +54,20 @@ public class UserRepositoryTest
|
||||
private IOptions<ApiSettings> _optionsApiSettings = null!;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the <see cref="_repository"/>'s <c>GetUser</c> method asynchronously returns a non-null user with the expected username and password credentials.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetUser()
|
||||
{
|
||||
var result = await _repository.GetUser("username1", "password1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
public async Task GetUser()
|
||||
{
|
||||
Assert.That(result!.UserName, Is.EqualTo("username1"));
|
||||
Assert.That(result.Password, Is.EqualTo("password1"));
|
||||
//Assert.That(result.Rol, Is.EqualTo("rol1"));
|
||||
};
|
||||
}
|
||||
var result = await _repository.GetUser("username1", "password1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result!.UserName, Is.EqualTo("username1"));
|
||||
Assert.That(result.Password, Is.EqualTo("password1"));
|
||||
//Assert.That(result.Rol, Is.EqualTo("rol1"));
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user