using e_suite.API.Common.exceptions; using e_suite.API.Common.models; using e_suite.Database.Audit; using e_suite.Database.Core.Models; using eSuite.Core.Miscellaneous; using Microsoft.AspNetCore.Mvc; using Moq; using NUnit.Framework; namespace eSuite.API.UnitTests.Controllers.OrganisationControllerUnitTests; [TestFixture] public class EditOrganisationUnitTests : OrganisationControllerTestBase { [SetUp] public override async Task Setup() { await base.Setup(); } [Test] public void ShouldReturnNotFound() { //Arrange var exceptionText = "Organisation with this id does not exist."; var organisation = new EditOrganisation { GeneralIdRef = new GeneralIdRef { Guid = new Guid("c0504bf6-b8b9-4a64-89ef-06b04e9e8d12") }, Name = "Sun-Strategy", Address = "Bristol, UK", Status = OrganisationStatus.Active }; _organisationManagerMock.Setup(x => x.EditOrganisation(It.IsAny(), organisation, true, It.IsAny())).Throws(new NotFoundException(exceptionText)); Assert.ThrowsAsync(async () => { //Act var actualResult = await _organisationController.EditOrganisation(organisation); }); } [Test] public async Task ShouldReturnOk() { //Arrange var organisation = new EditOrganisation { GeneralIdRef = new GeneralIdRef { Guid = new Guid("2777ed7e-294f-4b54-9e06-ebdb3facebe1") }, Name = "Sun-Strategy", Address = "Bristol, UK", Status = OrganisationStatus.Active }; //Act var actualResult = await _organisationController.EditOrganisation(organisation); //Assert _organisationManagerMock.Verify(x => x.EditOrganisation(It.IsAny(), organisation, true, It.IsAny()), Times.Once()); Assert.That(actualResult.GetType(), Is.EqualTo(typeof(OkResult))); var objectResult = actualResult as OkResult; Assert.That(objectResult?.StatusCode, Is.EqualTo(200)); } }