using adas_core.Domain.Models.AppSettings; using adas_core.Domain.Models.MongoModels; using adas_core.Infrastructure.Repositories; using Microsoft.Extensions.Options; using Options = Microsoft.Extensions.Options.Options; namespace adas_core.Test.Repositories; [TestFixture] [Category("Integration")] public class PoCMappingRepositoryTest { /// /// Performs one-time setup for integration tests by seeding the "mappings" collection with a sample document, where a single point of care is mapped from an original value to a new one across eleven bed entries, and initializing the against the integration database. /// [OneTimeSetUp] public async Task Init() { _optionsApiSettings = Options.Create(_apiSettings); var mappingItem1 = new PoCMappingItem { OriginalPoC = "original1", NewPoC = "new1", Beds = [ new List { "bed1", "bed 1" }, new List { "bed2", "bed 2" }, new List { "bed3", "bed 3" }, new List { "bed4", "bed 4" }, new List { "bed5", "bed 5" }, new List { "bed6", "bed 6" }, new List { "bed7", "bed 7" }, new List { "bed8", "bed 8" }, new List { "bed9", "bed 9" }, new List { "bed10", "bed 10" }, new List { "bed11", "bed 11" } ] }; var pointOfCares = new List { mappingItem1 }; var mapping = new PoCMapping { Id = "PV1", PointOfCares = pointOfCares }; await IntegrationDb.Database.DropCollectionAsync("mappings"); await IntegrationDb.Database.CreateCollectionAsync("mappings"); _repository = new PoCMappingRepository(_optionsApiSettings, IntegrationDb.Database); await _repository.InsertOneAsync(mapping); } private PoCMappingRepository _repository; private readonly ApiSettings _apiSettings = new(); private IOptions _optionsApiSettings; /// /// Verifies that finding a mapping by the key "PV1" returns a non-null result containing point of care entries with at least one associated bed. /// [Test] public async Task FindByKey_Find_Return_Mapping() { var result = await _repository.FindByKey("PV1"); Assert.That(result, Is.Not.Null); Assert.That(result!.PointOfCares, Has.Count.GreaterThan(0)); Assert.That(result.PointOfCares[0].Beds, Has.Count.GreaterThan(0)); } /// /// Verifies that the repository's FindByKey method returns null when the provided key does not correspond to an existing entity, confirming the not-found behavior. /// [Test] public async Task FindByKey_Not_Find_Return_Mapping() { var result = await _repository.FindByKey("PV2"); Assert.That(result, Is.Null); } }