Table of Contents

Class CacheKeyClassifierTest

Namespace
adas_core.Test.Utilities
Assembly
adas-core.Test.dll
[TestFixture]
public class CacheKeyClassifierTest
Inheritance
CacheKeyClassifierTest
Inherited Members
Extension Methods

Methods

ByPatient_DeleteByPatternAsync_OnlyRemovesMatchingPatientKeys()

Verifies that DeleteByPatternAsync removes only cache entries whose keys match the patient-specific pattern built via CacheKeyPatterns.ByPatient, leaving entries belonging to other patients and unrelated entity types intact, and reports the count of deleted keys.

[Test]
public Task ByPatient_DeleteByPatternAsync_OnlyRemovesMatchingPatientKeys()

Returns

Task

ByPatient_ReturnsPatternContainingPrefixAndPatientId()

Verifies that ByPatient(string, string) generates a cache key pattern that embeds both the supplied prefix and patient identifier, producing the expected format of {prefix}::{patientId}.

[Test]
public void ByPatient_ReturnsPatternContainingPrefixAndPatientId()

Classify_ReturnsAppointments_ForKeyInMixedCase()

Verifies that Classify(string) correctly returns the Appointments entity type when the supplied cache key contains a mixture of uppercase and lowercase characters, confirming that key classification is case-insensitive.

[Test]
public void Classify_ReturnsAppointments_ForKeyInMixedCase()

Classify_ReturnsAppointments_ForKeyStartingWithAppointmentsPatient()

Verifies that Classify(string) returns Appointments when the cache key starts with the "appointments:patient:" prefix.

[Test]
public void Classify_ReturnsAppointments_ForKeyStartingWithAppointmentsPatient()

Classify_ReturnsAppointments_ForKeyStartingWithAppointmentsPoc()

Verifies that Classify(string) returns Appointments when the provided cache key begins with the "appointments:PoC:" segment.

[Test]
public void Classify_ReturnsAppointments_ForKeyStartingWithAppointmentsPoc()

Classify_ReturnsConfigObservations_ForKeyStartingWithConfigObservations()

Verifies that Classify(string) returns ConfigObservations when the supplied cache key starts with the configObservations: prefix.

[Test]
public void Classify_ReturnsConfigObservations_ForKeyStartingWithConfigObservations()

Classify_ReturnsDisplays_ForKeyStartingWithConfigDisplaysBase()

Verifies that Classify(string) correctly returns Displays for a cache key matching the "configDisplays:display:<id>:base" pattern.

[Test]
public void Classify_ReturnsDisplays_ForKeyStartingWithConfigDisplaysBase()

Classify_ReturnsDisplays_ForKeyStartingWithConfigDisplaysConfig()

Verifies that Classify(string) returns Displays when the supplied cache key begins with the configDisplays: prefix.

[Test]
public void Classify_ReturnsDisplays_ForKeyStartingWithConfigDisplaysConfig()

Classify_ReturnsGroupedObservations_ForKeyStartingWithGroupedObs()

Verifies that Classify(string) returns GroupedObservations for cache keys that begin with the "groupedObs:" prefix, such as those following the "groupedObs:HR:patient:{id}" pattern.

[Test]
public void Classify_ReturnsGroupedObservations_ForKeyStartingWithGroupedObs()

Classify_ReturnsPatients_ForKeyInUpperCase()

Verifies that Classify(string) returns Patients when the cache key is provided in upper case.

[Test]
public void Classify_ReturnsPatients_ForKeyInUpperCase()

Classify_ReturnsPatients_ForKeyStartingWithPatients()

Verifies that Classify(string) returns Patients when the cache key starts with the "patients" prefix.

[Test]
public void Classify_ReturnsPatients_ForKeyStartingWithPatients()

Classify_ReturnsPatients_ForKeyStartingWithPatientsXYZ()

Verifies that Classify(string) returns Patients when the cache key starts with the "patients:xyz:" prefix.

[Test]
public void Classify_ReturnsPatients_ForKeyStartingWithPatientsXYZ()

Classify_ReturnsPumpObservations_ForKeyStartingWithPumpObs()

Verifies that Classify(string) returns PumpObservations when the provided cache key starts with the "pumpObs" prefix.

[Test]
public void Classify_ReturnsPumpObservations_ForKeyStartingWithPumpObs()

Classify_ReturnsUnknown_ForUnrecognizedPrefixDiagnostics()

Verifies that the cache key classifier returns Unknown when a key has a prefix that is not recognized.

[Test]
public void Classify_ReturnsUnknown_ForUnrecognizedPrefixDiagnostics()

Classify_ReturnsUnknown_ForUnrecognizedPrefixRandom()

Verifies that Classify(string) returns Unknown when the supplied cache key uses an unrecognized prefix.

[Test]
public void Classify_ReturnsUnknown_ForUnrecognizedPrefixRandom()

ConfigObservationsAllKeyWithTtl_GeneratesCorrectFormat()

Verifies that ConfigObservationsAllKeyWithTtl(CacheSettings?) generates the cache key "configObservations:all" consistently regardless of the supplied CacheSettings, including when TTL configuration and enabled state differ from defaults.

[Test]
public void ConfigObservationsAllKeyWithTtl_GeneratesCorrectFormat()

DisplayBaseKeyWithTtl_GeneratesCorrectFormat()

Verifies that DisplayBaseKeyWithTtl(CacheSettings?, ObjectId) generates the expected base display cache key using the "configDisplays:display:{displayId}:base" format and returns the TTL value configured in the in-memory cache settings.

[Test]
public void DisplayBaseKeyWithTtl_GeneratesCorrectFormat()

DisplayWithConfigKeyWithTtl_GeneratesCorrectFormat()

Verifies that DisplayWithConfigKeyWithTtl(CacheSettings?, ObjectId) produces a cache key in the expected "configDisplays:display:{displayId}:config" format and that it differs from the base display key generated by DisplayBaseKeyWithTtl(CacheSettings?, ObjectId).

[Test]
public void DisplayWithConfigKeyWithTtl_GeneratesCorrectFormat()

ForEntity_ReturnsCorrectPatternForEachEntityType(EntityType, string)

Verifies that ForEntity(EntityType) returns the correct cache key pattern for each supported CacheEnum.EntityType, mapping known entity types to their specific namespace patterns (e.g., patients:, displays:, pumpObs:, appointments:, groupedObs:, configObservation:) and falling back to a wildcard pattern (*) for Unknown.

[TestCase(CacheEnum.EntityType.Patients, "patients:*")]
[TestCase(CacheEnum.EntityType.Displays, "displays:*")]
[TestCase(CacheEnum.EntityType.PumpObservations, "pumpObs:*")]
[TestCase(CacheEnum.EntityType.Appointments, "appointments:*")]
[TestCase(CacheEnum.EntityType.GroupedObservations, "groupedObs:*")]
[TestCase(CacheEnum.EntityType.ConfigObservations, "configObservation:*")]
[TestCase(CacheEnum.EntityType.Unknown, "*")]
public void ForEntity_ReturnsCorrectPatternForEachEntityType(CacheEnum.EntityType entity, string expectedPattern)

Parameters

entity CacheEnum.EntityType

The entity type under test for which a cache key pattern is requested.

expectedPattern string

The cache key pattern that ForEntity(EntityType) is expected to return for the given entity type.

LatestObservationsKeyWithTtl_ExcludesEmptyFields()

Verifies that the cache key generated by LatestObservationsKeyWithTtl(CacheSettings?, ObjectId, IEnumerable<string>, int?) excludes empty strings and null entries from the provided observation types, producing a clean delimiter-separated key for the remaining valid values.

[Test]
public void LatestObservationsKeyWithTtl_ExcludesEmptyFields()

LatestObservationsKeyWithTtl_SortsFieldNamesAlphabetically()

Verifies that LatestObservationsKeyWithTtl(CacheSettings?, ObjectId, IEnumerable<string>, int?) generates a deterministic cache key by sorting the supplied field names alphabetically, regardless of their input order.

[Test]
public void LatestObservationsKeyWithTtl_SortsFieldNamesAlphabetically()

PatientAppointmentsTodayKeyWithTtl_GeneratesCorrectFormat()

Verifies that CacheKeys.PatientAppointmentsTodayKeyWithTtl generates a cache key in the format "appointments:patient:{patientId}:{yyyyMMdd}" and returns a TTL of 120 seconds when caching is enabled and the Appointments mode is set to Cache.

[Test]
public void PatientAppointmentsTodayKeyWithTtl_GeneratesCorrectFormat()

PocAppointmentsTodayKeyWithTtl_GeneratesCorrectFormat()

Verifies that PocAppointmentsTodayKeyWithTtl(CacheSettings?, ObjectId) generates the expected cache key format ("appointments:PoC:{pocId}:{yyyyMMdd}") and returns the TTL value configured for point of care entries.

[Test]
public void PocAppointmentsTodayKeyWithTtl_GeneratesCorrectFormat()

PointOfCareBaseKeyWithTtl_GeneratesCorrectFormat()

Verifies that PointOfCareBaseKeyWithTtl(CacheSettings?, ObjectId) generates a cache key with the expected "pointOfCare:{pocId}:base" format and applies the configured point-of-care TTL in seconds from the in-memory settings.

[Test]
public void PointOfCareBaseKeyWithTtl_GeneratesCorrectFormat()

ResolveForEntity_ReturnsNull_WhenEntityModeIsNone()

Verifies that ResolveForEntity(CacheSettings?, EntityType) returns null when the entity mode is set to None, regardless of the in-memory TTL configuration.

[Test]
public void ResolveForEntity_ReturnsNull_WhenEntityModeIsNone()

ResolveForEntity_ReturnsNull_WhenGlobalCacheDisabled()

Verifies that ResolveForEntity(CacheSettings?, EntityType) returns null when the global cache is disabled, regardless of the configured entity-specific cache mode and Redis TTL settings.

[Test]
public void ResolveForEntity_ReturnsNull_WhenGlobalCacheDisabled()

ResolveForEntity_ReturnsNull_WhenGlobalDisabled_ForAllEntities()

Verifies that ResolveForEntity(CacheSettings?, EntityType) returns null for every supported entity type when caching is globally disabled via IsEnabled set to false.

[Test]
public void ResolveForEntity_ReturnsNull_WhenGlobalDisabled_ForAllEntities()

ResolveForEntity_ReturnsNull_WhenNoTtlConfigured()

Verifies that CacheKeyTtl.ResolveForEntity returns null when the provided CacheSettings enable caching for the entity but no TTL values are configured (neither GlobalSeconds nor the entity-specific seconds).

[Test]
public void ResolveForEntity_ReturnsNull_WhenNoTtlConfigured()

ResolveForEntity_UsesEntitySpecificTtl_WhenModeIsCache()

Verifies that ResolveForEntity(CacheSettings?, EntityType) returns the entity-specific TTL (configured via PatientsSeconds) when the cache mode for the entity is set to Cache, instead of falling back to the global TTL.

[Test]
public void ResolveForEntity_UsesEntitySpecificTtl_WhenModeIsCache()

ResolveForEntity_UsesGlobalSeconds_WhenNoEntitySpecificTtl()

Verifies that ResolveForEntity(CacheSettings?, EntityType) falls back to the globally configured TTL (in seconds) when no entity-specific TTL is defined for the requested entity type.

[Test]
public void ResolveForEntity_UsesGlobalSeconds_WhenNoEntitySpecificTtl()

ResolveForEntity_UsesRedisTtl_WhenModeIsRedis()

Verifies that ResolveForEntity(CacheSettings?, EntityType) returns the entity-specific Redis TTL (AppointmentsSeconds) when the cache mode for the entity is set to Redis.

[Test]
public void ResolveForEntity_UsesRedisTtl_WhenModeIsRedis()