rama creada apartir de master en j
This commit is contained in:
@@ -17,51 +17,54 @@ namespace adas_core.Test.Services;
|
||||
[TestFixture]
|
||||
public class DiagnosisServiceTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the mocked dependencies (patient, diagnosis, unit, audit, subscribers and calculated observations services along with their repositories) and constructs the <see cref="DiagnosisService"/> instance under test.
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_patientServiceMock = new Mock<IPatientService>();
|
||||
_patientServiceLazy = new Lazy<IPatientService>(() => _patientServiceMock.Object);
|
||||
|
||||
//var sectionServiceMock = new Mock<ISectionService>();
|
||||
//sectionServiceLazy = new Lazy<ISectionService>(() => sectionServiceMock.Object);
|
||||
|
||||
_diagnosisRepositoryMock = new Mock<IDiagnosisRepository>();
|
||||
_diagnosisArchiveRepositoryMock = new Mock<IDiagnosisArchiveRepository>();
|
||||
_clientMessageServiceMock = new Mock<IClientMessageService>();
|
||||
_subscribersServiceMock = new Mock<ISubscribersService>();
|
||||
_unitServiceMock = new Mock<IUnitService>();
|
||||
_httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
_auditService = new Mock<ILocalAuditService>();
|
||||
_calculatedObservationsServiceMock = new Mock<ICalculatedObservationsService>();
|
||||
_calculatedObservationsServiceLazy =
|
||||
new Lazy<ICalculatedObservationsService>(() => _calculatedObservationsServiceMock.Object);
|
||||
_calculatedObservationsServiceMock.Setup(x => x.Map(It.IsAny<PatientDiagnosis>()))
|
||||
.ReturnsAsync((PatientDiagnosis? value) => value);
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
_logger = new Mock<ILogger<DiagnosisService>>();
|
||||
_diagnosisService = new DiagnosisService(
|
||||
_patientServiceLazy,
|
||||
//sectionServiceLazy,
|
||||
_optionsApiSettings,
|
||||
_diagnosisRepositoryMock.Object,
|
||||
_diagnosisArchiveRepositoryMock.Object,
|
||||
_logger.Object,
|
||||
_clientMessageServiceMock.Object,
|
||||
_subscribersServiceMock.Object,
|
||||
_calculatedObservationsServiceLazy,
|
||||
_httpContextAccessor.Object,
|
||||
_auditService.Object,
|
||||
_unitServiceMock.Object
|
||||
);
|
||||
|
||||
|
||||
// Create a mock of the singleton class subscribers
|
||||
var mockSingleton = new Mock<ICalculatedObservationsService>();
|
||||
|
||||
// Set up the mock object to return a specific value when a method is called
|
||||
mockSingleton.Setup(x => x.Map(It.IsAny<PatientDiagnosis>())).ReturnsAsync((PatientDiagnosis? value) => value);
|
||||
}
|
||||
public void Setup()
|
||||
{
|
||||
_patientServiceMock = new Mock<IPatientService>();
|
||||
_patientServiceLazy = new Lazy<IPatientService>(() => _patientServiceMock.Object);
|
||||
|
||||
//var sectionServiceMock = new Mock<ISectionService>();
|
||||
//sectionServiceLazy = new Lazy<ISectionService>(() => sectionServiceMock.Object);
|
||||
|
||||
_diagnosisRepositoryMock = new Mock<IDiagnosisRepository>();
|
||||
_diagnosisArchiveRepositoryMock = new Mock<IDiagnosisArchiveRepository>();
|
||||
_clientMessageServiceMock = new Mock<IClientMessageService>();
|
||||
_subscribersServiceMock = new Mock<ISubscribersService>();
|
||||
_unitServiceMock = new Mock<IUnitService>();
|
||||
_httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
_auditService = new Mock<ILocalAuditService>();
|
||||
_calculatedObservationsServiceMock = new Mock<ICalculatedObservationsService>();
|
||||
_calculatedObservationsServiceLazy =
|
||||
new Lazy<ICalculatedObservationsService>(() => _calculatedObservationsServiceMock.Object);
|
||||
_calculatedObservationsServiceMock.Setup(x => x.Map(It.IsAny<PatientDiagnosis>()))
|
||||
.ReturnsAsync((PatientDiagnosis? value) => value);
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
_logger = new Mock<ILogger<DiagnosisService>>();
|
||||
_diagnosisService = new DiagnosisService(
|
||||
_patientServiceLazy,
|
||||
//sectionServiceLazy,
|
||||
_optionsApiSettings,
|
||||
_diagnosisRepositoryMock.Object,
|
||||
_diagnosisArchiveRepositoryMock.Object,
|
||||
_logger.Object,
|
||||
_clientMessageServiceMock.Object,
|
||||
_subscribersServiceMock.Object,
|
||||
_calculatedObservationsServiceLazy,
|
||||
_httpContextAccessor.Object,
|
||||
_auditService.Object,
|
||||
_unitServiceMock.Object
|
||||
);
|
||||
|
||||
|
||||
// Create a mock of the singleton class subscribers
|
||||
var mockSingleton = new Mock<ICalculatedObservationsService>();
|
||||
|
||||
// Set up the mock object to return a specific value when a method is called
|
||||
mockSingleton.Setup(x => x.Map(It.IsAny<PatientDiagnosis>())).ReturnsAsync((PatientDiagnosis? value) => value);
|
||||
}
|
||||
|
||||
private DiagnosisService _diagnosisService;
|
||||
|
||||
@@ -137,69 +140,78 @@ public class DiagnosisServiceTest
|
||||
// }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>SaveRequest</c> does not insert a diagnosis when the patient referenced by the <see cref="ApiRequest"/> cannot be found.
|
||||
/// </summary>
|
||||
/// <returns>A task representing the asynchronous test execution.</returns>
|
||||
[Test]
|
||||
public async Task SaveRequest_Not_FindPatient_Return_not_insert()
|
||||
{
|
||||
var apiRequest = new ApiRequest
|
||||
public async Task SaveRequest_Not_FindPatient_Return_not_insert()
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync((Patient?)null);
|
||||
|
||||
await _diagnosisService.SaveRequest(apiRequest, null);
|
||||
|
||||
_diagnosisRepositoryMock.Verify(d => d.InsertOneAsync(It.IsAny<PatientDiagnosis>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveRequest_Not_Observations_Return_not_insert()
|
||||
{
|
||||
var patientObs = new Person
|
||||
{
|
||||
FirstName = "Miguel",
|
||||
LastName = "Villanueva",
|
||||
Ids = new Dictionary<string, string> { { "MR", "437537" } }
|
||||
};
|
||||
|
||||
var patient = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitString = "UCI5C",
|
||||
Bed = "Box4",
|
||||
PatientNumber = "437537",
|
||||
Person = patientObs
|
||||
};
|
||||
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
ObservationData = new ObservationData
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Code = "302147001",
|
||||
CodingSystem = "SNM",
|
||||
Value = "Aire; Contacto; Preventivo",
|
||||
Text = "Aislamiento",
|
||||
Time = Now
|
||||
},
|
||||
Patient = patientObs,
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync((Patient?)null);
|
||||
|
||||
await _diagnosisService.SaveRequest(apiRequest, null);
|
||||
|
||||
_diagnosisRepositoryMock.Verify(d => d.InsertOneAsync(It.IsAny<PatientDiagnosis>()), Times.Never);
|
||||
}
|
||||
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
|
||||
await _diagnosisService.SaveRequest(apiRequest, null);
|
||||
|
||||
_diagnosisRepositoryMock.Verify(d => d.InsertOneAsync(It.IsAny<PatientDiagnosis>()), Times.Never);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that <c>SaveRequest</c> does not insert a <see cref="PatientDiagnosis"/> when the provided <see cref="ApiRequest"/> is not considered an observation request, ensuring observations must be present to trigger a database insertion.
|
||||
/// </summary>
|
||||
/// <param name="apiRequest">The API request containing the patient and observation data being evaluated.</param>
|
||||
/// <param name="null">Reserved parameter passed to <c>SaveRequest</c> as a null value.</param>
|
||||
[Test]
|
||||
public async Task SaveRequest_Not_Observations_Return_not_insert()
|
||||
{
|
||||
var patientObs = new Person
|
||||
{
|
||||
FirstName = "Miguel",
|
||||
LastName = "Villanueva",
|
||||
Ids = new Dictionary<string, string> { { "MR", "437537" } }
|
||||
};
|
||||
|
||||
var patient = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitString = "UCI5C",
|
||||
Bed = "Box4",
|
||||
PatientNumber = "437537",
|
||||
Person = patientObs
|
||||
};
|
||||
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
ObservationData = new ObservationData
|
||||
{
|
||||
Code = "302147001",
|
||||
CodingSystem = "SNM",
|
||||
Value = "Aire; Contacto; Preventivo",
|
||||
Text = "Aislamiento",
|
||||
Time = Now
|
||||
},
|
||||
Patient = patientObs,
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
|
||||
await _diagnosisService.SaveRequest(apiRequest, null);
|
||||
|
||||
_diagnosisRepositoryMock.Verify(d => d.InsertOneAsync(It.IsAny<PatientDiagnosis>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveRequest_Not_DiagnosisCodeSettings_Return_not_insert()
|
||||
|
||||
Reference in New Issue
Block a user