95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
using adas_core.Domain.Enums;
|
|
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 TreatmentArchiveRepositoryTest
|
|
{
|
|
[OneTimeSetUp]
|
|
public async Task Init()
|
|
{
|
|
_optionsApiSettings = Options.Create(_apiSettings);
|
|
|
|
var treatment1 = new PatientTreatment
|
|
{
|
|
Id = ObjectId.GenerateNewId(),
|
|
PatientId = PatientId,
|
|
OrderControl = OrderControlType.Nw,
|
|
PlacerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
|
FillerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
|
OrderStatus = "A",
|
|
OrderTime = DateTime.Now,
|
|
Notes = [],
|
|
Routes = []
|
|
};
|
|
|
|
var treatment2 = new PatientTreatment
|
|
{
|
|
Id = ObjectId.GenerateNewId(),
|
|
PatientId = PatientId,
|
|
OrderControl = OrderControlType.Dc,
|
|
PlacerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
|
FillerOrder = new Entity { EntityIdentifier = "3690", NamespaceId = "CareVue" },
|
|
OrderStatus = "A",
|
|
OrderTime = DateTime.Now.AddDays(-5),
|
|
Notes = [],
|
|
Routes = []
|
|
};
|
|
|
|
await IntegrationDb.Database.DropCollectionAsync("archive_patients_treatments");
|
|
await IntegrationDb.Database.CreateCollectionAsync("archive_patients_treatments");
|
|
|
|
_repository = new TreatmentArchiveRepository(_optionsApiSettings, IntegrationDb.Database);
|
|
|
|
await _repository.InsertOneAsync(treatment1);
|
|
await _repository.InsertOneAsync(treatment2);
|
|
|
|
Assert.That(_repository.Collection.FindAsync(_ => true).Result.ToList(), Has.Count.EqualTo(2));
|
|
}
|
|
|
|
private TreatmentArchiveRepository _repository;
|
|
|
|
private readonly ApiSettings _apiSettings = new()
|
|
{
|
|
ArchivePatientsTreatments = "archive_patients_treatments"
|
|
};
|
|
|
|
private IOptions<ApiSettings> _optionsApiSettings;
|
|
|
|
private static readonly DateTime Now = DateTime.Now;
|
|
private static readonly ObjectId PatientId = 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.AddHours(-2));
|
|
|
|
var resultDelete = await _repository.Collection.FindAsync(p => p.PatientId == PatientId);
|
|
|
|
Assert.That(resultDelete, Is.Not.Null);
|
|
Assert.That(resultDelete.ToList(), Has.Count.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindAllFromPatient()
|
|
{
|
|
var result = await _repository.FindAllFromPatient(PatientId);
|
|
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result.ToList(), Has.Count.GreaterThan(0));
|
|
}
|
|
} |