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(), organisation, true, It.IsAny())).Throws(new ArgumentException(execptionText)); //Assert Assert.ThrowsAsync(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(), 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)); } }