Backend/e-suite.API/eSuite.API.UnitTests/Controllers/OrganisationControllerUnitTests/GetOrganisationUnitTests.cs
2026-01-20 21:50:10 +00:00

75 lines
2.4 KiB
C#

using e_suite.API.Common.exceptions;
using e_suite.Database.Core.Models;
using e_suite.Database.Core.Tables.Printer;
using eSuite.Core.Miscellaneous;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
namespace eSuite.API.UnitTests.Controllers.OrganisationControllerUnitTests;
[TestFixture]
public class GetOrganisationUnitTests : OrganisationControllerTestBase
{
[SetUp]
public override async Task Setup()
{
await base.Setup();
}
[Test]
public async Task ShouldReturnOk()
{
//Arrange
var organisationGeneralIdRef = new GeneralIdRef
{
Guid = new Guid("22676f28-b9dd-4961-b499-e35de117617c"),
Id = 999,
};
var organisation = new Organisation
{
Id = (long)organisationGeneralIdRef.Id,
Guid = (Guid)organisationGeneralIdRef.Guid,
Name = "Sun-Strategy",
Address = "Bristol, UK",
Status = OrganisationStatus.Active,
Deleted = false,
};
_organisationManagerMock.Setup(x => x.GetOrganisation(It.IsAny<GeneralIdRef>(), It.IsAny<CancellationToken>())).ReturnsAsync(organisation);
//Act
var actualResult = await _organisationController.GetOrganisation(organisationGeneralIdRef);
//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(Organisation)));
}
[Test]
public void ShouldReturnNotFound()
{
//Arrange
var exceptionText = "Organisation with this id does not exist.";
var organisationGeneralIdRef = new GeneralIdRef
{
Guid = new Guid("1d0dcee0-469c-4deb-9a68-f6ff0c9b79a6"),
Id = 999,
};
_organisationManagerMock.Setup(x => x.GetOrganisation(It.IsAny<GeneralIdRef>(), It.IsAny<CancellationToken>())).ThrowsAsync(new NotFoundException(exceptionText));
//Assert
Assert.ThrowsAsync<NotFoundException>(async () =>
{
//Act
var actualResult = await _organisationController.GetOrganisation(organisationGeneralIdRef);
});
}
}