public void Post_Method_Adds_A_New_Lab_Result() { var labResultCount = 20; var patients = CreateTestPatients(20); var labResults = CreateTestLabResults(labResultCount); var repo = new InMemoryLabResultRepository(labResults); var patientRepo = new InMemoryPatientRepository(patients); var cache = new MemoryCache(new MemoryCacheOptions()); var controller = new LabResultController(repo, patientRepo, cache); var newLabResult = new LabResult() { TestType = "TestType", Result = "Result", Patient = CreateTestPatient(999), PatientId = 999, TimeOfTest = DateTime.Now.AddDays(-2), LabName = "LabName", OrderedByProvider = "OrderedByProvider", Measurement = 1, MeasurementUnit = "Unit" }; // Make sure patient can be found for verification patients.Add(newLabResult.Patient); controller.Post(newLabResult); Assert.Equal(labResultCount + 1, repo.InternalData.Count); }
private LabResultController CreateController(List <LabResult> labResults, List <Patient> patients) { var repo = new InMemoryLabResultRepository(labResults); var patientRepo = new InMemoryPatientRepository(patients); var cache = new MemoryCache(new MemoryCacheOptions()); var controller = new LabResultController(repo, patientRepo, cache); return(controller); }
public void Put_Method_Updates_A_LabResult() { var labResultId = 99; var patients = CreateTestPatients(5); var labResults = CreateTestLabResults(5); labResults[0].Id = labResultId; var repo = new InMemoryLabResultRepository(labResults); var patientRepo = new InMemoryPatientRepository(patients); var cache = new MemoryCache(new MemoryCacheOptions()); var controller = new LabResultController(repo, patientRepo, cache); var labResultToUpdate = new LabResult() { Id = labResultId, TestType = "TestType", Result = "Result", Patient = CreateTestPatient(999), PatientId = 999, TimeOfTest = DateTime.Now.AddDays(-2), LabName = "LabName", OrderedByProvider = "OrderedByProvider", Measurement = 1, MeasurementUnit = "Unit" }; // Make sure patient can be found for verification patients.Add(labResultToUpdate.Patient); controller.Put(labResultId, labResultToUpdate); var labResultFromDb = repo.InternalData.FirstOrDefault(lr => lr.Id == labResultId); Assert.NotNull(labResultFromDb); Assert.Equal(labResultToUpdate.TestType, labResultFromDb.TestType); Assert.Equal(labResultToUpdate.Result, labResultFromDb.Result); Assert.Equal(labResultToUpdate.PatientId, labResultFromDb.PatientId); Assert.Equal(labResultToUpdate.TimeOfTest, labResultFromDb.TimeOfTest); Assert.Equal(labResultToUpdate.EnteredTime, labResultFromDb.EnteredTime); Assert.Equal(labResultToUpdate.LabName, labResultFromDb.LabName); Assert.Equal(labResultToUpdate.OrderedByProvider, labResultFromDb.OrderedByProvider); Assert.Equal(labResultToUpdate.Measurement, labResultFromDb.Measurement); Assert.Equal(labResultToUpdate.MeasurementUnit, labResultFromDb.MeasurementUnit); }
public void Delete_Method_Removes_A_LabResult() { var labResultId = 99; var labResults = CreateTestLabResults(5); var patients = CreateTestPatients(5); labResults[0].Id = labResultId; var repo = new InMemoryLabResultRepository(labResults); var patientRepo = new InMemoryPatientRepository(patients); var cache = new MemoryCache(new MemoryCacheOptions()); var controller = new LabResultController(repo, patientRepo, cache); controller.Delete(labResultId); var labResultFromDb = repo.InternalData.FirstOrDefault(p => p.Id == labResultId); Assert.Null(labResultFromDb); }
public void Get_By_Patient_Id_Returns_Matching_LabResults() { var patientId = 99; var labResultCount = 20; var patients = CreateTestPatients(20); patients[0].Id = patientId; var labResults = CreateTestLabResults(labResultCount); labResults[0].PatientId = patientId; var repo = new InMemoryLabResultRepository(labResults); var patientRepo = new InMemoryPatientRepository(patients); var cache = new MemoryCache(new MemoryCacheOptions()); var controller = new LabResultController(repo, patientRepo, cache); var result = controller.GetByPatient(patientId); var okResult = Assert.IsType <OkObjectResult>(result); var actualLabResult = Assert.IsType <List <LabResult> >(okResult.Value); Assert.All(actualLabResult, labResult => Assert.Equal(labResult.PatientId, patientId)); }