# Class UnitServiceTest

Namespace
  adas_core.Test.Services

Assembly
  adas-core.Test.dll

Provides a unit test class for testing the functionality of the UnitService.

    public class UnitServiceTest

Inheritance
  object
  UnitServiceTest

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?)

## Remarks

This class is intended to contain test methods that validate the behavior and correctness of the UnitService.

## Methods

### FindById_ShouldReturnNull_WhenNullIdProvided()

Verifies that the unit service's FindById method returns null when invoked with a null identifier, ensuring graceful handling of null input without throwing or returning a default entity.

    [Test]
    public Task FindById_ShouldReturnNull_WhenNullIdProvided()

#### Returns

Task

### FindById_ShouldReturnUnit_WhenValidIdProvided()

Verifies that the unit service returns the expected unit when a valid unit identifier is provided.

    [Test]
    public Task FindById_ShouldReturnUnit_WhenValidIdProvided()

#### Returns

Task

  A task that represents the asynchronous test execution.

### FindByLocation_ShouldReturnEmptyList_WhenNoUnitsFound()

Verifies that FindByLocation returns an empty list when no units match the specified patient location.

    [Test]
    public Task FindByLocation_ShouldReturnEmptyList_WhenNoUnitsFound()

#### Returns

Task

### FindByLocation_ShouldReturnUnits_WhenUnitsFound()

Verifies that the unit service returns the matching units when the repository contains units whose point of care matches the specified patient location.

    [Test]
    public Task FindByLocation_ShouldReturnUnits_WhenUnitsFound()

#### Returns

Task

### FindByName_ShouldReturnUnit_WhenValidNameProvided()

Verifies that FindByName retrieves and returns the expected `Unit` when a valid unit name is provided.

    [Test]
    public Task FindByName_ShouldReturnUnit_WhenValidNameProvided()

#### Returns

Task

### FindUnitByPatientId_ShouldReturnUnit_WhenPatientFoundInActivePoC()

Verifies that `FindByPatientId` returns the associated unit when the patient is found in an active (in-use) point of care.

    [Test]
    public Task FindUnitByPatientId_ShouldReturnUnit_WhenPatientFoundInActivePoC()

#### Returns

Task

### FindUnitsByMasterListId_ShouldReturnUnits_WhenUnitsFound()

Verifies that the unit service returns the matching units retrieved from the repository when a call is made to find units by the specified master list identifier and type.

    [Test]
    public Task FindUnitsByMasterListId_ShouldReturnUnits_WhenUnitsFound()

#### Returns

Task

### GetAllUnits_ShouldReturnAllUnits()

Verifies that _unitService" returns all units retrieved from the repository, ensuring the result is not null, contains the expected number of units, and matches the source data.

    [Test]
    public Task GetAllUnits_ShouldReturnAllUnits()

#### Returns

Task

### GetAll_ShouldReturnAllUnits()

Verifies that the unit service returns all units retrieved from the repository, including the correct count and content.

    [Test]
    public Task GetAll_ShouldReturnAllUnits()

#### Returns

Task

### GetUnitById_ShouldReturnUnit_WhenFound()

Verifies that _unitService.FindById" returns the matching Unit when the repository locates it by id.

    [Test]
    public Task GetUnitById_ShouldReturnUnit_WhenFound()

#### Returns

Task

### GetUnitByName_ShouldReturnUnit_WhenFound()

Verifies that `GetByName` returns the matching unit when a unit with the specified name exists in the repository.

    [Test]
    public Task GetUnitByName_ShouldReturnUnit_WhenFound()

#### Returns

Task

### Get_ShouldReturnUnitById()

Verifies that the Get method on the unit service returns the expected unit when a valid identifier is provided.

    [Test]
    public Task Get_ShouldReturnUnitById()

#### Returns

Task

### Get_ShouldReturnUnitByName_WhenIdIsNotObjectId()

Verifies that the Get method retrieves a unit by name when the provided identifier is not a valid ObjectId, matching against either the unit's Title or Name.

    [Test]
    public Task Get_ShouldReturnUnitByName_WhenIdIsNotObjectId()

#### Returns

Task

### InsertOne_ShouldReturnInsertedUnit()

Verifies that the unit service correctly delegates the insert operation to the repository and returns the inserted unit entity unchanged.

    [Test]
    public Task InsertOne_ShouldReturnInsertedUnit()

#### Returns

Task

### SetUp()

Initializes mocked dependencies and a configured UnitService instance for each test, including a mock HttpContext with a test user claim.

    [SetUp]
    public void SetUp()