Creado apartir del commit b888de6c92056de294456f581a56e25e734d4ab7 de develop
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
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 DiagnosisRepositoryTest
|
||||
{
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
var patientDiagnosis1 = new PatientDiagnosis
|
||||
{
|
||||
Id = Id,
|
||||
PatientId = PatientId,
|
||||
Time = Now,
|
||||
Code = "code1",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
var patientDiagnosis2 = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
Time = Now,
|
||||
Code = "code2",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
var patientDiagnosis3 = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
Time = Now,
|
||||
Code = "code3",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("patients_diagnosis");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("patients_diagnosis");
|
||||
|
||||
_repository = new DiagnosisRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(patientDiagnosis1);
|
||||
await _repository.InsertOneAsync(patientDiagnosis2);
|
||||
await _repository.InsertOneAsync(patientDiagnosis3);
|
||||
}
|
||||
|
||||
private DiagnosisRepository _repository;
|
||||
|
||||
private readonly ApiSettings _apiSettings = new()
|
||||
{
|
||||
PatientsDiagnosis = "patients_diagnosis"
|
||||
};
|
||||
|
||||
private IOptions<ApiSettings> _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 GetByPatient_Find_Patient_Return_List()
|
||||
{
|
||||
var result = await _repository.GetByPatient(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Not.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetByPatient_not_Find_Patient_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.GetByPatient(ObjectId.GenerateNewId());
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByPatientIdAndCode_Find_Patient_Return_Diagnois()
|
||||
{
|
||||
var result = await _repository.FindByPatientIdAndCode(PatientId, "code1", "diagnosisSystem");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByPatientIdAndCode_not_Find_Patient_Return_null()
|
||||
{
|
||||
var result = await _repository.FindByPatientIdAndCode(ObjectId.GenerateNewId(), "code4", "diagnosisSystem");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByPatientIdAsync_Find_Patient_Return_List()
|
||||
{
|
||||
var result = await _repository.FindByPatientIdAsync(PatientId);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Is.Not.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindByPatientIdAsync_not_Find_Patient_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.FindByPatientIdAsync(ObjectId.GenerateNewId());
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.ToList(), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteAsync_Find_id()
|
||||
{
|
||||
var patientDiagnosis = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
Time = Now,
|
||||
Code = "code1",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(patientDiagnosis);
|
||||
|
||||
var result = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(1));
|
||||
|
||||
await _repository.DeleteAsync(patientDiagnosis.Id);
|
||||
|
||||
var resultDelete = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
|
||||
Assert.That(resultDelete.ToList(), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteByPatientId_Find_patientId()
|
||||
{
|
||||
var patientDiagnosis = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
Time = Now,
|
||||
Code = "code1",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(patientDiagnosis);
|
||||
|
||||
var result = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
|
||||
Assert.That(result.ToList(), Has.Count.EqualTo(1));
|
||||
|
||||
await _repository.DeleteByPatientId(patientDiagnosis.PatientId);
|
||||
|
||||
var resultDelete = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
|
||||
Assert.That(resultDelete.ToList(), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateManyObjectId_With_base_UpdateManyObjectIdAsync()
|
||||
{
|
||||
var patientDiagnosis = new PatientDiagnosis
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
PatientId = ObjectId.GenerateNewId(),
|
||||
Time = Now,
|
||||
Code = "code1",
|
||||
DiagnosisSystem = "diagnosisSystem"
|
||||
};
|
||||
|
||||
await _repository.InsertOneAsync(patientDiagnosis);
|
||||
|
||||
var resultInsert = await _repository.FindByPatientIdAsync(patientDiagnosis.PatientId);
|
||||
|
||||
var resultList = resultInsert.ToList();
|
||||
|
||||
Assert.That(resultList, Has.Count.EqualTo(1));
|
||||
|
||||
var newPatientId = ObjectId.GenerateNewId();
|
||||
|
||||
await _repository.UpdateManyObjectId("patientId", newPatientId, patientDiagnosis.PatientId);
|
||||
|
||||
var resultUpdate = await _repository.FindByPatientIdAsync(newPatientId);
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate.ToList().Count(f => f.PatientId == newPatientId), Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user