Documentation modifications

This commit is contained in:
julian
2026-06-27 15:23:26 -07:00
parent a633fe6c06
commit a19fb90902
218 changed files with 2882 additions and 0 deletions
@@ -8,6 +8,13 @@ using MongoDB.Driver;
namespace adas_core.Test.Repositories;
/// <summary>
/// Integration test fixture for the <see cref="PumpObservationRepository"/>.
/// </summary>
/// <remarks>
/// Marked with the <c>Integration</c> category, so these tests target interactions with external dependencies rather than isolated unit logic.
/// </remarks>
/// <!-- aidoc:v1 sig=c9f19af -->
[TestFixture]
[Category("Integration")]
public class PumpObservationRepositoryTest
@@ -21,6 +28,13 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// INIT SETUP DE LA COLECCIÓN CON DATOS DE PRUEBA
// -------------------------------------------------------------------
/// <summary>
/// One-time setup that prepares the integration test environment for the <see cref="PumpObservationRepository"/> by clearing the
/// <c>pump_observations</c> collection, recreating it, building the indexes, and seeding it with three sample <see cref="PumpObservation"/>
/// records belonging to <see cref="BasePatientObservation.PatientId"/>. The setup then asserts that exactly three documents were
/// inserted into the collection.
/// </summary>
/// <!-- aidoc:v1 sig=81c0015 body=162df76 -->
[OneTimeSetUp]
public async Task Init()
{
@@ -79,6 +93,10 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// FIND LAST OBSERVATIONS (LÍMITE = 2)
// -------------------------------------------------------------------
/// <summary>
/// Verifies that the repository returns exactly two observations for the specified patient and "PumpX", and that the returned list is ordered with the first observation's time greater than or equal to the second observation's time.
/// </summary>
/// <!-- aidoc:v1 sig=3214dea body=70daa63 -->
[Test]
public async Task FindLastObservations_ReturnsTwo()
{
@@ -92,6 +110,10 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// INSERT
// -------------------------------------------------------------------
/// <summary>
/// Verifies that <see cref="IRepository{PumpObservation}.InsertAsync"/> persists a new <see cref="PumpObservation"/> so that a subsequent lookup by <see cref="BasePatientObservation.Id"/> returns the stored entity.
/// </summary>
/// <!-- aidoc:v1 sig=2215003 body=9eae88d -->
[Test]
public async Task InsertAsync_Works()
{
@@ -109,6 +131,10 @@ public class PumpObservationRepositoryTest
Assert.That(found.FirstOrDefault(), Is.Not.Null);
}
/// <summary>
/// Verifies that the repository successfully inserts a batch of <see cref="PumpObservation"/> documents and that all items can be retrieved by their identifiers from the underlying collection.
/// </summary>
/// <!-- aidoc:v1 sig=5a5d3db body=8d0d26b -->
[Test]
public async Task InsertManyAsync_Works()
{
@@ -127,6 +153,10 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// FIND METHODS
// -------------------------------------------------------------------
/// <summary>
/// Verifies that the FindByDeviceIdAsync repository method returns a non-empty collection of pump observations for the specified device, ordered by time in descending order with the most recent observation first.
/// </summary>
/// <!-- aidoc:v1 sig=01527dc body=3a6c4b2 -->
[Test]
public async Task FindByDeviceIdAsync_ReturnsOrdered()
{
@@ -140,6 +170,10 @@ public class PumpObservationRepositoryTest
}
}
/// <summary>
/// Verifies that the repository's <c>FindByPatientAsync</c> call returns a non-empty collection of observations for the configured <c>PatientId</c>, ordered by time in descending order so that the most recent observation appears first.
/// </summary>
/// <!-- aidoc:v1 sig=1926bb1 body=010dd96 -->
[Test]
public async Task FindByPatientAsync_ReturnsOrdered()
{
@@ -153,6 +187,10 @@ public class PumpObservationRepositoryTest
}
}
/// <summary>
/// Verifies that <see cref="Repository.FindLastByDeviceIdAsync"/> returns a non-null observation whose <see cref="BasePatientObservation.DeviceId"/> matches the device identifier passed in.
/// </summary>
/// <!-- aidoc:v1 sig=eeea0f1 body=d0bcd5d -->
[Test]
public async Task FindLastByDeviceIdAsync_Works()
{
@@ -162,6 +200,10 @@ public class PumpObservationRepositoryTest
Assert.That(obs.DeviceId, Is.EqualTo("Device-A"));
}
/// <summary>
/// Verifies that the repository lookup by patient identifier returns a non-empty collection of results.
/// </summary>
/// <!-- aidoc:v1 sig=363130a body=c6821a0 -->
[Test]
public async Task FindByPatientId_Works()
{
@@ -173,6 +215,10 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// AGGREGATED LAST OBSERVATIONS
// -------------------------------------------------------------------
/// <summary>
/// Verifies that the aggregated last observations retrieved for the test <c>PatientId</c> are distinct by name, ensuring the resulting collection is non-empty and contains at most two entries.
/// </summary>
/// <!-- aidoc:v1 sig=878cf7b body=9a03f04 -->
[Test]
public async Task AggregatedPatientLastObservations_DistinctByName()
{
@@ -188,6 +234,10 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// DELETE METHODS
// -------------------------------------------------------------------
/// <summary>
/// Verifies that <see cref="PumpObservation"/> records associated with a given patient can be removed via <c>DeleteByPatientId</c>, ensuring no matching observations remain in the repository after deletion.
/// </summary>
/// <!-- aidoc:v1 sig=d53a759 body=16f0ddb -->
[Test]
public async Task DeleteByPatientId_Works()
{
@@ -207,6 +257,10 @@ public class PumpObservationRepositoryTest
Assert.That(list.Any(), Is.False);
}
/// <summary>
/// Tests that <c>DeleteOlderThanDaysAsync</c> successfully deletes pump observations older than the given number of days, asserting that the returned count is at least one when matching data exists.
/// </summary>
/// <!-- aidoc:v1 sig=eedf26a body=5bdb401 -->
[Test]
public async Task DeleteOlderThanDaysAsync_Works()
{
@@ -225,6 +279,11 @@ public class PumpObservationRepositoryTest
Assert.That(deleted, Is.GreaterThanOrEqualTo(1));
}
/// <summary>
/// Verifies that the older-observation pruning operation retains only the requested number of newest <see cref="PumpObservation"/> entries for the given name and returns the count of deleted items.
/// Inserts five timed observations and asserts that exactly three older entries are removed when two are kept.
/// </summary>
/// <!-- aidoc:v1 sig=d7625b7 body=dc1036f -->
[Test]
public async Task DeleteOlderNumberAsync_Works()
{
@@ -246,6 +305,10 @@ public class PumpObservationRepositoryTest
Assert.That(deleted, Is.EqualTo(3));
}
/// <summary>
/// Verifies that <see cref="_repo.DeleteKeepLastNAsync"/> correctly deletes the older records while preserving the most recent <paramref name="n"/> entries, returning the expected count of deleted items.
/// </summary>
/// <!-- aidoc:v1 sig=6f857ff body=814bec4 -->
[Test]
public async Task DeleteKeepLastNAsync_Works()
{
@@ -267,6 +330,10 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// UPDATE METHOD
// -------------------------------------------------------------------
/// <summary>
/// Verifies that <see cref="Repository{BasePatientObservation}.UpdateManyObjectIdByFieldAsync"/> correctly updates the <see cref="BasePatientObservation.PatientId"/> field of all matching records, replacing the old <see cref="MongoDB.Bson.ObjectId"/> value with a new one, and reports the number of documents modified.
/// </summary>
/// <!-- aidoc:v1 sig=e139730 body=639f796 -->
[Test]
public async Task UpdateManyObjectIdByFieldAsync_Works()
{
@@ -292,6 +359,12 @@ public class PumpObservationRepositoryTest
// -------------------------------------------------------------------
// AGGREGATION: LAST OBSERVATION TIME PER PATIENT
// -------------------------------------------------------------------
/// <summary>
/// Verifies that the repository returns a non-null dictionary containing the last patient observation
/// time for the specified patient, and that the recorded timestamp is not in the future relative to
/// <see cref="DateTime.UtcNow"/>.
/// </summary>
/// <!-- aidoc:v1 sig=1accf32 body=8a4a652 -->
[Test]
public async Task FindAllLastPatientObservationTimeAsync_Works()
{
@@ -305,6 +378,10 @@ public class PumpObservationRepositoryTest
}
}
/// <summary>
/// Verifies that looking up records by device ID with a date range entirely outside the stored data window returns an empty collection.
/// </summary>
/// <!-- aidoc:v1 sig=c885ffe body=2c99833 -->
[Test]
public async Task FindByDeviceIdAsync_EmptyWhenOutOfDateRange()
{
@@ -316,6 +393,10 @@ public class PumpObservationRepositoryTest
Assert.That(result, Is.Empty);
}
/// <summary>
/// Verifies that the repository's FindByPatientAsync method respects the <c>limit</c> parameter when retrieving records for a patient, asserting that the returned collection contains exactly one item when the limit is set to one.
/// </summary>
/// <!-- aidoc:v1 sig=4955050 body=a2ef54e -->
[Test]
public async Task FindByPatientAsync_RespectsLimit()
{
@@ -324,6 +405,10 @@ public class PumpObservationRepositoryTest
Assert.That(list, Has.Count.EqualTo(1));
}
/// <summary>
/// Verifies that FindLastByDeviceIdAsync returns null when no observation exists for the supplied device identifier.
/// </summary>
/// <!-- aidoc:v1 sig=275de54 body=b35493b -->
[Test]
public async Task FindLastByDeviceIdAsync_ReturnsNullWhenNotExists()
{
@@ -332,6 +417,10 @@ public class PumpObservationRepositoryTest
Assert.That(obs, Is.Null);
}
/// <summary>
/// Verifies that InsertManyAsync completes without throwing when invoked with an empty collection of <see cref="PumpObservation"/>.
/// </summary>
/// <!-- aidoc:v1 sig=a2eefa5 body=d0db476 -->
[Test]
public async Task InsertManyAsync_IgnoresEmptyList()
{
@@ -343,6 +432,10 @@ public class PumpObservationRepositoryTest
}
/// <summary>
/// Verifies that <c>DeleteOlderNumberAsync</c> leaves the stored data unchanged and returns zero when the total number of <see cref="PumpObservation"/> entries for the given device name is below the specified <c>maxCount</c> threshold.
/// </summary>
/// <!-- aidoc:v1 sig=934d0ad body=3bd6af8 -->
[Test]
public async Task DeleteOlderNumberAsync_DoesNothingWhenCountBelowLimit()
{
@@ -363,6 +456,10 @@ public class PumpObservationRepositoryTest
Assert.That(deleted, Is.Zero);
}
/// <summary>
/// Verifies that the repository cleanup operation preserves recent observations by inserting a <see cref="PumpObservation"/> whose timestamp is one minute in the past and asserting that the deletion count returned by <c>DeleteOlderThanDaysAsync</c> is zero.
/// </summary>
/// <!-- aidoc:v1 sig=1c414ad body=819234d -->
[Test]
public async Task DeleteOlderThanDaysAsync_DoesNotDeleteRecentObservations()
{
@@ -382,6 +479,10 @@ public class PumpObservationRepositoryTest
Assert.That(deleted, Is.Zero);
}
/// <summary>
/// Verifies that <see cref="AggregatedPatientLastObservations"/> deduplicates <see cref="PumpObservation"/> entries that share the same <see cref="PumpObservation.Code"/> and <see cref="PumpObservation.Name"/> for a given patient, returning only a single entry per code/name combination.
/// </summary>
/// <!-- aidoc:v1 sig=646e129 body=eebdec4 -->
[Test]
public async Task AggregatedPatientLastObservations_RemovesDuplicatesByCodeAndName()
{