Backend/e-suite.Modules.SiteManager/e-suite.Modules.SiteManager.UnitTests/GetSiteUnitTests.cs
2026-01-20 21:50:10 +00:00

81 lines
2.5 KiB
C#

using e_suite.API.Common.exceptions;
using e_suite.Database.Core.Models;
using e_suite.Database.Core.Tables.Printer;
using e_suite.Modules.SiteManager.UnitTests.Helpers;
using eSuite.Core.Miscellaneous;
using NUnit.Framework;
namespace e_suite.Modules.SiteManager.UnitTests;
[TestFixture]
public class GetSiteUnitTests : SiteManagerTestBase
{
[SetUp]
public override async Task Setup()
{
await base.Setup();
}
[Test]
public void GetSite_SiteNotFound_ThrowsException()
{
//Arrange
var generalIdRef = new GeneralIdRef
{
Guid = new Guid("9bd47040-8124-47fb-aac8-e3e02c02a1a5")
};
//Assert
var actualResult = Assert.ThrowsAsync<NotFoundException>(async () =>
{
//Act
var actualResult = await SiteManager.GetSite(generalIdRef, CancellationToken.None);
});
Assert.That(actualResult!.Message, Is.EqualTo("Site not found"));
}
[Test]
public async Task GetSite_SiteExists_ReturnsSite()
{
//Arrange
var organisation = new Organisation
{
Guid = new Guid("80db1d8b-5bdd-45e3-b6b8-86d99aa3fc74"),
Id = 2356,
Name = "Test organisation LLC",
Status = OrganisationStatus.Pending
};
var site = new Site
{
Guid = new Guid("949c4b6e-16cb-44c9-8441-1465977f2ce3"),
Id = 21351,
Name = "Testing site",
Organisation = organisation,
OrganisationId = organisation.Id,
Status = OrganisationStatus.Active
};
SiteManagerRepository.Sites.Add(site);
var generalIdRef = new GeneralIdRef
{
Guid = site.Guid
};
//Act
var actualResult = await SiteManager.GetSite(generalIdRef, CancellationToken.None);
//Assert
Assert.Multiple(() =>
{
Assert.That(actualResult, Is.Not.Null);
Assert.That(actualResult.Guid, Is.EqualTo(site.Guid));
Assert.That(actualResult.Id, Is.EqualTo(site.Id));
Assert.That(actualResult.Address, Is.EqualTo(site.Address));
Assert.That(actualResult.Name, Is.EqualTo(site.Name));
Assert.That(actualResult.Status, Is.EqualTo(site.Status));
Assert.That(actualResult.OrganisationId.Guid, Is.EqualTo(organisation.Guid));
Assert.That(actualResult.OrganisationId.Id, Is.EqualTo(organisation.Id));
});
}
}