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(), It.IsAny())).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(), It.IsAny())).ThrowsAsync(new NotFoundException(exceptionText)); //Assert Assert.ThrowsAsync(async () => { //Act var actualResult = await _organisationController.GetOrganisation(organisationGeneralIdRef); }); } }