rama creada apartir de master en j
This commit is contained in:
@@ -12,31 +12,34 @@ namespace adas_core.Test.Repositories;
|
||||
[Category("Integration")]
|
||||
public class MedicineRepositoryTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs one-time initialization for integration tests by seeding the medicines collection with a test record and verifying it can be retrieved by code or note.
|
||||
/// </summary>
|
||||
[OneTimeSetUp]
|
||||
public async Task Init()
|
||||
{
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
_testMedicine = new Medicine
|
||||
public async Task Init()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("medicines");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("medicines");
|
||||
|
||||
_repository = new MedicineRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(_testMedicine);
|
||||
|
||||
var result = _repository.GetMedicineByCodeOrNote(["12345"]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
_testMedicine = new Medicine
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
await IntegrationDb.Database.DropCollectionAsync("medicines");
|
||||
await IntegrationDb.Database.CreateCollectionAsync("medicines");
|
||||
|
||||
_repository = new MedicineRepository(_optionsApiSettings, IntegrationDb.Database);
|
||||
|
||||
await _repository.InsertOneAsync(_testMedicine);
|
||||
|
||||
var result = _repository.GetMedicineByCodeOrNote(["12345"]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
private MedicineRepository _repository = null!;
|
||||
|
||||
@@ -49,14 +52,17 @@ public class MedicineRepositoryTest
|
||||
|
||||
private IOptions<ApiSettings> _optionsApiSettings = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <c>GetMedicineByCodeOrNote</c> returns a non-null, empty list when invoked with an array containing an empty string.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task Get_Medicines_Of_Treatments_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.GetMedicineByCodeOrNote([""]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
public async Task Get_Medicines_Of_Treatments_Return_Empty_List()
|
||||
{
|
||||
var result = await _repository.GetMedicineByCodeOrNote([""]);
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Medicines_Of_Treatments_By_Code_When_Have_Code_And_Notes_Return_Paracetamol()
|
||||
@@ -83,50 +89,63 @@ public class MedicineRepositoryTest
|
||||
Assert.That(result, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the repository returns a non-null medicine when a valid medicine code is found.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetMedicine_Find_Code_Return_Medicine()
|
||||
{
|
||||
var result = await _repository.GetMedicine("12345");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMedicine_Not_Find_Code_Return_Empty()
|
||||
{
|
||||
var result = await _repository.GetMedicine("123456");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMedicine_Find_Note_Return_Medicine()
|
||||
{
|
||||
var result = await _repository.GetMedicine("note1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateMedicine_Return_Medicine()
|
||||
{
|
||||
var updateMedicine = new Medicine
|
||||
public async Task GetMedicine_Find_Code_Return_Medicine()
|
||||
{
|
||||
Id = _testMedicine.Id,
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1", "note2", "note3"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
var result = await _repository.UpdateMedicine(updateMedicine);
|
||||
var resultUpdate = await _repository.GetMedicineById(_testMedicine.Id);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
|
||||
var result = await _repository.GetMedicine("12345");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate?.Notes != null && resultUpdate.Notes.Contains("note3"), Is.True);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository's <c>GetMedicine</c> method returns <c>null</c> when the provided medicine code does not match any existing record.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetMedicine_Not_Find_Code_Return_Empty()
|
||||
{
|
||||
var result = await _repository.GetMedicine("123456");
|
||||
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the repository returns a non-null medicine when a medicine is found
|
||||
/// by the supplied note identifier ("note1"), confirming successful lookup by note.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task GetMedicine_Find_Note_Return_Medicine()
|
||||
{
|
||||
var result = await _repository.GetMedicine("note1");
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that UpdateMedicine returns the updated medicine and that the changes are persisted and retrievable via GetMedicineById, including the updated notes collection.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task UpdateMedicine_Return_Medicine()
|
||||
{
|
||||
var updateMedicine = new Medicine
|
||||
{
|
||||
Id = _testMedicine.Id,
|
||||
Codes = ["12345"],
|
||||
Notes = ["note1", "note2", "note3"],
|
||||
Name = "test",
|
||||
Group = [MedicineEnum.Group.Metabolic.ToString()]
|
||||
};
|
||||
|
||||
var result = await _repository.UpdateMedicine(updateMedicine);
|
||||
var resultUpdate = await _repository.GetMedicineById(_testMedicine.Id);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(resultUpdate, Is.Not.Null);
|
||||
Assert.That(resultUpdate?.Notes != null && resultUpdate.Notes.Contains("note3"), Is.True);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user