rama creada apartir de master en j
This commit is contained in:
@@ -35,6 +35,10 @@ public class DisplayServiceTest
|
||||
|
||||
private DisplayService _displayService = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes mocked dependencies and configuration required to construct a <see cref="DisplayService"/> instance for unit tests.
|
||||
/// Sets up the HTTP context with a test user claim, creates default cache settings, and wires all collaborators (repositories, services, logger, permissions) into the service under test.
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
@@ -56,7 +60,7 @@ public class DisplayServiceTest
|
||||
_httpContextAccessorMock.Setup(a => a.HttpContext).Returns(new DefaultHttpContext { User = claims });
|
||||
|
||||
var cacheSettings = Options.Create(new CacheSettings());
|
||||
|
||||
|
||||
_displayService = new DisplayService(
|
||||
_mockDisplayRepository.Object,
|
||||
_mockPointOfCareService.Object,
|
||||
@@ -73,12 +77,15 @@ public class DisplayServiceTest
|
||||
_mockCacheService.Object,
|
||||
cacheSettings
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// InsertOne
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DisplayService.InsertOne"/> inserts a display by resolving the default configuration for its type and persisting it through the repository's insert method.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InsertOne_ShouldInsertDisplay()
|
||||
{
|
||||
@@ -104,6 +111,9 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetById
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that the <see cref="DisplayService"/> returns the expected <see cref="Display"/> instance when a matching id is provided through the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetById_ShouldReturnDisplay()
|
||||
{
|
||||
@@ -120,6 +130,9 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetAllByUser - userName null
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that _displayService.GetAllByUser returns an empty collection when the user name is null.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetAllByUser_ShouldReturnEmpty_WhenUserNameNull()
|
||||
{
|
||||
@@ -130,7 +143,7 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetAllByUser - Admin case
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task GetAllByUser_ShouldReturnDisplays_WhenAdmin()
|
||||
{
|
||||
@@ -144,7 +157,7 @@ public class DisplayServiceTest
|
||||
{
|
||||
Id = adminId,
|
||||
UserName = userName,
|
||||
Authorization =
|
||||
Authorization =
|
||||
[
|
||||
new Authorization { UnitId = unitId.ToString(), Rol = nameof(PermissionEnum.RolesType.AuthAdmin) }
|
||||
]
|
||||
@@ -182,13 +195,13 @@ public class DisplayServiceTest
|
||||
_mockPermissionService
|
||||
.Setup(p => p.GetPermissionsForUnit(unitId.ToString(), user))
|
||||
.ReturnsAsync(new DisplayPermissionTypes(
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true,true,true,true,true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
new UserActions(true, true, true, true, true),
|
||||
true
|
||||
));
|
||||
|
||||
@@ -207,6 +220,11 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetByType
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that retrieving display configurations by type returns the associated displays
|
||||
/// from the display repository, ensuring the service correctly resolves configurations and
|
||||
/// their linked displays for the given display type.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByType_ShouldReturnDisplays()
|
||||
{
|
||||
@@ -226,6 +244,10 @@ public class DisplayServiceTest
|
||||
That(result[0], Is.EqualTo(display));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DisplayService.GetByType"/> returns an empty collection when no display configurations are found for the specified display type.
|
||||
/// </summary>
|
||||
/// <returns>A task that completes when the assertion confirming the empty result has been executed.</returns>
|
||||
[Test]
|
||||
public async Task GetByType_ShouldReturnEmpty_WhenNoConfigsFound()
|
||||
{
|
||||
@@ -240,6 +262,11 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetByPointOfCare
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Tests that GetByPointOfCare returns the displays associated with the specified point of care.
|
||||
/// </summary>
|
||||
/// <param name="poc">The point of care used to look up associated displays.</param>
|
||||
/// <returns>A task representing the asynchronous test execution.</returns>
|
||||
[Test]
|
||||
public async Task GetByPointOfCare_ShouldReturnDisplays()
|
||||
{
|
||||
@@ -257,11 +284,15 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetByConfigId
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DisplayService.GetByConfigId"/> returns the displays associated with the specified configuration ID retrieved from the repository.
|
||||
/// </summary>
|
||||
/// <returns>A task that completes when the assertion confirms the returned collection contains the expected number of displays.</returns>
|
||||
[Test]
|
||||
public async Task GetByConfigId_ShouldReturnDisplays()
|
||||
{
|
||||
var cfgId = ObjectId.GenerateNewId();
|
||||
var d = new Display { Id = ObjectId.GenerateNewId(), DisplayConfigId = cfgId, Name = "display1"};
|
||||
var d = new Display { Id = ObjectId.GenerateNewId(), DisplayConfigId = cfgId, Name = "display1" };
|
||||
|
||||
_mockDisplayRepository.Setup(r => r.GetByConfigId(cfgId))
|
||||
.ReturnsAsync([d]);
|
||||
@@ -274,6 +305,9 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetByName
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that the <see cref="DisplayService.GetByName"/> method throws a <see cref="NotFoundException"/> when no display matching the specified name is found in the repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetByName_ShouldThrow_WhenNotFound()
|
||||
{
|
||||
@@ -287,6 +321,9 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetInfo
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetInfo</c> returns a <see cref="Display"/> with its associated <c>PointOfCare</c> entries populated when invoked with the "with POC" flag enabled and a valid display identifier.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetInfo_ShouldReturnDisplayWithPoc()
|
||||
{
|
||||
@@ -309,7 +346,7 @@ public class DisplayServiceTest
|
||||
It.IsAny<TimeSpan?>(),
|
||||
It.IsAny<CancellationToken>()))
|
||||
.Returns((string _, Func<Task<Display?>> factory, TimeSpan? _, CancellationToken _) => factory());
|
||||
|
||||
|
||||
_mockDisplayRepository.Setup(r => r.GetById(id)).ReturnsAsync(display);
|
||||
_mockDisplayConfigService.Setup(s => s.GetById(cfgId))
|
||||
.ReturnsAsync(new DisplayConfig { Id = cfgId });
|
||||
@@ -328,11 +365,14 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// GetByUnitId
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="IDisplayService.GetByUnitId"/> returns the displays associated with the specified unit identifier when the repository contains matching records.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetByUnitId_ShouldReturnDisplays()
|
||||
{
|
||||
var id = ObjectId.GenerateNewId();
|
||||
var d = new Display { Id = ObjectId.GenerateNewId(), UnitId = id , Name = "display1"};
|
||||
var d = new Display { Id = ObjectId.GenerateNewId(), UnitId = id, Name = "display1" };
|
||||
|
||||
_mockDisplayRepository.Setup(r => r.GetByUnitId(id))
|
||||
.ReturnsAsync([d]);
|
||||
@@ -345,6 +385,10 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// UpdatePointOfCareList
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that UpdatePointOfCareList throws a <see cref="NotFoundException"/> when the display with the specified identifier does not exist.
|
||||
/// </summary>
|
||||
/// <exception cref="NotFoundException">Thrown when no display is found for the given id.</exception>
|
||||
[Test]
|
||||
public void UpdatePointOfCareList_ShouldThrow_WhenDisplayNotFound()
|
||||
{
|
||||
@@ -360,6 +404,11 @@ public class DisplayServiceTest
|
||||
// -----------------------------------------------------------
|
||||
// UpdateConfigPreset
|
||||
// -----------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="DisplayService.UpdateConfigPreset"/> throws a <see cref="NotFoundException"/> when the repository update operation returns a null result, indicating the display or configuration preset could not be found.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the display whose configuration preset is being updated.</param>
|
||||
/// <param name="cfgId">The unique identifier of the configuration preset to associate with the display.</param>
|
||||
[Test]
|
||||
public void UpdateConfigPreset_ShouldThrow_WhenUpdateFails()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user