# Class PumpStateRepositoryTest

Namespace
  adas_core.Test.Repositories

Assembly
  adas-core.Test.dll

    [TestFixture]
    [Category("Integration")]
    public class PumpStateRepositoryTest

Inheritance
  object
  PumpStateRepositoryTest

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Methods

### FindByDeviceIdAsync_ReturnsCorrectState()

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.

    [Test]
    public Task FindByDeviceIdAsync_ReturnsCorrectState()

#### Returns

Task

### GetAllAsync_ReturnsAllStates()

Verifies that `GetAllAsync` returns a non-null collection of pump states containing at least two entries, including those associated with the seeded devices A and B.

    [Test]
    public Task GetAllAsync_ReturnsAllStates()

#### Returns

Task

### Init()

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.

    [OneTimeSetUp]
    public Task Init()

#### Returns

Task

### UpsertAsync_DoesNotCreateDuplicates()

Verifies that UpsertAsync updates an existing entity instead of inserting a duplicate, ensuring the total record count remains unchanged when upserting a PumpState for an already-known device identifier.

    [Test]
    public Task UpsertAsync_DoesNotCreateDuplicates()

#### Returns

Task

### UpsertAsync_InsertsNewWhenNotExists()

Verifies that `UpsertAsync` inserts a new PumpState record when no existing entry is found for the specified `DeviceId`, and that the persisted state retains the provided property values.

    [Test]
    public Task UpsertAsync_InsertsNewWhenNotExists()

#### Returns

Task

### UpsertAsync_UpdatesExistingState()

Verifies that `UpsertAsync` correctly updates an existing pump state in the repository, ensuring the updated PumpState is persisted and retrievable with the modified `IsInfusing`, `Status`, and `LastUpdated` values.

    [Test]
    public Task UpsertAsync_UpdatesExistingState()

#### Returns

Task