using adas_core.Domain.Models; using adas_core.Domain.Models.AppSettings; using adas_core.Infrastructure.Repositories; using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Driver; using Options = Microsoft.Extensions.Options.Options; namespace adas_core.Test.Repositories; [TestFixture] [Category("Integration")] public class DiagnosisArchiveRepositoryTest { [OneTimeSetUp] public async Task Init() { _optionsApiSettings = Options.Create(_apiSettings); var patientDiagnosis1 = new PatientDiagnosis { Id = Id, PatientId = PatientId, Time = Now.AddDays(-1), Code = "code1", DiagnosisSystem = "diagnosisSystem" }; var patientDiagnosis2 = new PatientDiagnosis { Id = ObjectId.GenerateNewId(), PatientId = PatientId, Time = Now.AddDays(-2), Code = "code2", DiagnosisSystem = "diagnosisSystem" }; var patientDiagnosis3 = new PatientDiagnosis { Id = ObjectId.GenerateNewId(), PatientId = PatientId, Time = Now.AddDays(-3), Code = "code3", DiagnosisSystem = "diagnosisSystem" }; await IntegrationDb.Database.DropCollectionAsync("archive_patients_diagnosis"); await IntegrationDb.Database.CreateCollectionAsync("archive_patients_diagnosis"); _repository = new DiagnosisArchiveRepository(_optionsApiSettings, IntegrationDb.Database); await _repository.InsertOneAsync(patientDiagnosis1); await _repository.InsertOneAsync(patientDiagnosis2); await _repository.InsertOneAsync(patientDiagnosis3); } private DiagnosisArchiveRepository _repository; private readonly ApiSettings _apiSettings = new() { ArchivePatientsDiagnosis = "archive_patients_diagnosis" }; private IOptions _optionsApiSettings; private static readonly DateTime Now = DateTime.Now; private static readonly ObjectId PatientId = ObjectId.GenerateNewId(); private static readonly ObjectId Id = ObjectId.GenerateNewId(); [Test] public async Task DeleteBeforeDate() { var result = await _repository.Collection.FindAsync(p => p.PatientId == PatientId); Assert.That(result, Is.Not.Null); Assert.That(result.ToList(), Has.Count.GreaterThan(1)); await _repository.DeleteBeforeDate(Now.AddDays(-1)); var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId); Assert.That(resultDelete, Is.Not.Null); Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1)); } }