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

66 lines
2.1 KiB
C#

using e_suite.API.Common.models;
using e_suite.Database.Audit;
using e_suite.Database.Core.Models;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
namespace eSuite.API.UnitTests.Controllers.OrganisationControllerUnitTests;
[TestFixture]
public class CreateOrganisationUnitTests : OrganisationControllerTestBase
{
[SetUp]
public override async Task Setup()
{
await base.Setup();
}
[Test]
public void ShouldReturnBadRequest()
{
//Arrange
const string execptionText = "Guid is already used.";
var organisation = new CreateOrganisation
{
Guid = new Guid("f14056df-94d3-42cc-9a03-5da516477d63"),
Name = "Sun-Strategy",
Address = "Bristol, UK",
Status = OrganisationStatus.Active
};
_organisationManagerMock.Setup(x => x.AddOrganisation(It.IsAny<AuditUserDetails>(), organisation, true, It.IsAny<CancellationToken>())).Throws(new ArgumentException(execptionText));
//Assert
Assert.ThrowsAsync<ArgumentException>(async () =>
{
//Act
var actualResult = await _organisationController.CreateOrganisation(organisation);
});
}
[Test]
public async Task CreateOrganisation_EverythingCorrect_CreatesOrganisation()
{
//Arrange
var organisation = new CreateOrganisation
{
Guid = new Guid("34f241fa-5289-4fc5-a5e9-065d594238c2"),
Name = "Sun-Strategy",
Address = "Bristol, UK",
Status = OrganisationStatus.Active
};
//Act
var actualResult = await _organisationController.CreateOrganisation(organisation);
//Assert
_organisationManagerMock.Verify(x => x.AddOrganisation(It.IsAny<AuditUserDetails>(), organisation, true,It.IsAny<CancellationToken>()), Times.Once());
Assert.That(actualResult.GetType(), Is.EqualTo(typeof(OkResult)));
var objectResult = actualResult as OkResult;
Assert.That(objectResult?.StatusCode, Is.EqualTo(200));
}
}