60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using e_suite.API.Common.models;
|
|
using e_suite.Utilities.Pagination;
|
|
using eSuite.Core.Miscellaneous;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace eSuite.API.UnitTests.Controllers.RoleControllerUnitTests;
|
|
|
|
[TestFixture]
|
|
public class GetRolesUnitTests : RoleControllerTestBase
|
|
{
|
|
[SetUp]
|
|
public override async Task Setup()
|
|
{
|
|
await base.Setup();
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetRoles_WhenCalled_ReturnsPagedData()
|
|
{
|
|
//Arrange
|
|
var domains = new List<ReadRole>
|
|
{
|
|
new()
|
|
{
|
|
Guid = new Guid("16241e96-9062-4221-b073-a48330b2cc9b"),
|
|
Id = 999,
|
|
Name = "Some Role"
|
|
}
|
|
};
|
|
|
|
var paginatedData = new PaginatedData<ReadRole>
|
|
{
|
|
Count = domains.Count,
|
|
Data = domains,
|
|
Page = 1,
|
|
PageSize = 10
|
|
};
|
|
|
|
var cancellationToken = CancellationToken.None;
|
|
|
|
var paging = new Paging();
|
|
|
|
var generalIdRef = new GeneralIdRef();
|
|
|
|
_roleManagerMock.Setup(x => x.GetRoles(paging, generalIdRef, cancellationToken)).ReturnsAsync(paginatedData);
|
|
|
|
//Act
|
|
var actualResult = await _roleController.GetRoles(paging, generalIdRef, cancellationToken);
|
|
|
|
//Assert
|
|
Assert.That(actualResult.GetType(), Is.EqualTo(typeof(OkObjectResult)));
|
|
var objectResult = actualResult as OkObjectResult;
|
|
|
|
Assert.That(objectResult?.StatusCode, Is.EqualTo(200));
|
|
Assert.That(objectResult?.Value, Is.Not.Null);
|
|
Assert.That(objectResult!.Value!.GetType, Is.EqualTo(typeof(PaginatedData<ReadRole>)));
|
|
}
|
|
} |