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
+70 -14
View File
@@ -12,6 +12,12 @@ using Moq;
namespace adas_core.Test.Services;
/// <summary>
/// Provides a unit test class for testing the functionality of the UnitService.
/// </summary>
/// <remarks>
/// This class is intended to contain test methods that validate the behavior and correctness of the UnitService.
/// </remarks>
public class UnitServiceTest
{
private readonly Mock<ILocalAuditService> _auditServiceMock = new();
@@ -25,6 +31,10 @@ public class UnitServiceTest
private Mock<IUnitRepository> _unitRepositoryMock = null!;
private UnitService _unitService = null!;
/// <summary>
/// Initializes mocked dependencies and a configured <see cref="UnitService"/> instance for each test,
/// including a mock <see cref="HttpContext"/> with a test user claim.
/// </summary>
[SetUp]
public void SetUp()
{
@@ -59,6 +69,9 @@ public class UnitServiceTest
);
}
/// <summary>
/// Verifies that the unit service returns all units retrieved from the repository, including the correct count and content.
/// </summary>
[Test]
public async Task GetAll_ShouldReturnAllUnits()
{
@@ -75,6 +88,9 @@ public class UnitServiceTest
Assert.That(result, Is.EqualTo(units));
}
/// <summary>
/// Verifies that the Get method on the unit service returns the expected unit when a valid identifier is provided.
/// </summary>
[Test]
public async Task Get_ShouldReturnUnitById()
{
@@ -91,16 +107,19 @@ public class UnitServiceTest
Assert.That(result, Is.EqualTo(unit));
}
/// <summary>
/// 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.
/// </summary>
[Test]
public async Task Get_ShouldReturnUnitByName_WhenIdIsNotObjectId()
{
// Arrange
var unitName = "TestUnit";
var units = new List<Unit>
{
new() { Title = unitName },
new() { Name = unitName }
};
{
new() { Title = unitName },
new() { Name = unitName }
};
_unitRepositoryMock.Setup(repo => repo.GetAll()).ReturnsAsync(units);
// Act
@@ -111,16 +130,20 @@ public class UnitServiceTest
Assert.That(result?.Title ?? result?.Name, Is.EqualTo(unitName));
}
/// <summary>
/// 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.
/// </summary>
[Test]
public async Task GetAllUnits_ShouldReturnAllUnits()
{
// Arrange
var units = new List<Unit>
{
new() { Id = ObjectId.GenerateNewId(), Name = "Unit1" },
new() { Id = ObjectId.GenerateNewId(), Name = "Unit2" }
};
{
new() { Id = ObjectId.GenerateNewId(), Name = "Unit1" },
new() { Id = ObjectId.GenerateNewId(), Name = "Unit2" }
};
_unitRepositoryMock.Setup(repo => repo.GetAll()).ReturnsAsync(units);
@@ -133,6 +156,9 @@ public class UnitServiceTest
Assert.That(result, Is.EquivalentTo(units));
}
/// <summary>
/// Verifies that _unitService.FindById" returns the matching <see cref="Unit"/> when the repository locates it by id.
/// </summary>
[Test]
public async Task GetUnitById_ShouldReturnUnit_WhenFound()
{
@@ -150,6 +176,9 @@ public class UnitServiceTest
Assert.That(result, Is.EqualTo(unit));
}
/// <summary>
/// Verifies that <c>GetByName</c> returns the matching unit when a unit with the specified name exists in the repository.
/// </summary>
[Test]
public async Task GetUnitByName_ShouldReturnUnit_WhenFound()
{
@@ -167,6 +196,9 @@ public class UnitServiceTest
Assert.That(result, Is.EqualTo(expectedUnit));
}
/// <summary>
/// Verifies that <c>FindByPatientId</c> returns the associated unit when the patient is found in an active (in-use) point of care.
/// </summary>
[Test]
public async Task FindUnitByPatientId_ShouldReturnUnit_WhenPatientFoundInActivePoC()
{
@@ -194,6 +226,9 @@ public class UnitServiceTest
}
/// <summary>
/// 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.
/// </summary>
[Test]
public async Task FindUnitsByMasterListId_ShouldReturnUnits_WhenUnitsFound()
{
@@ -216,18 +251,22 @@ public class UnitServiceTest
}
}
/// <summary>
/// Verifies that the unit service returns the matching units when the repository contains units
/// whose point of care matches the specified patient location.
/// </summary>
[Test]
public async Task FindByLocation_ShouldReturnUnits_WhenUnitsFound()
{
// Arrange
var location = new PatientLocation("TestUnit", "TestBed", "TestRoom");
var units = new List<Unit>
{
new()
{
PointOfCares = [new PointOfCare { UnitName = "TestUnit", Bed = "TestBed" }]
}
};
new()
{
PointOfCares = [new PointOfCare { UnitName = "TestUnit", Bed = "TestBed" }]
}
};
_unitRepositoryMock.Setup(repo => repo.GetAll()).ReturnsAsync(units);
// Act
@@ -240,6 +279,9 @@ public class UnitServiceTest
Assert.That(result?.First().PointOfCares?.First().Bed, Is.EqualTo("TestBed"));
}
/// <summary>
/// Verifies that FindByLocation returns an empty list when no units match the specified patient location.
/// </summary>
[Test]
public async Task FindByLocation_ShouldReturnEmptyList_WhenNoUnitsFound()
{
@@ -255,6 +297,10 @@ public class UnitServiceTest
Assert.That(result?.Count, Is.EqualTo(0));
}
/// <summary>
/// Verifies that the unit service returns the expected unit when a valid unit identifier is provided.
/// </summary>
/// <returns>A task that represents the asynchronous test execution.</returns>
[Test]
public async Task FindById_ShouldReturnUnit_WhenValidIdProvided()
{
@@ -271,6 +317,10 @@ public class UnitServiceTest
Assert.That(result, Is.EqualTo(expectedUnit));
}
/// <summary>
/// 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.
/// </summary>
[Test]
public async Task FindById_ShouldReturnNull_WhenNullIdProvided()
{
@@ -283,6 +333,9 @@ public class UnitServiceTest
Assert.That(result, Is.Null);
}
/// <summary>
/// Verifies that FindByName retrieves and returns the expected <c>Unit</c> when a valid unit name is provided.
/// </summary>
[Test]
public async Task FindByName_ShouldReturnUnit_WhenValidNameProvided()
{
@@ -300,6 +353,9 @@ public class UnitServiceTest
}
/// <summary>
/// Verifies that the unit service correctly delegates the insert operation to the repository and returns the inserted unit entity unchanged.
/// </summary>
[Test]
public async Task InsertOne_ShouldReturnInsertedUnit()
{