rama creada apartir de master en j

This commit is contained in:
jrojas
2026-06-26 10:29:23 +02:00
parent 319fd3dfb0
commit c1517fda87
2810 changed files with 1927392 additions and 25392 deletions
@@ -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()
{