public async Task <ActionResult> CreatePatientHistory([FromBody] PatientHistoryModel patientHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var instance = PatientHistory.Create(patientHistory.PatientId); try { var newPatientHistory = await _repository.AddAsync(instance); if (newPatientHistory == null) { return(BadRequest(new ApiResponse { Status = false })); } return(CreatedAtRoute("GetPatientHistoryRoute", new { id = newPatientHistory.HistoryId }, new ApiResponse { Status = true, PatientHistory = newPatientHistory })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }
public void Given_PatientHistoryRepository_When_AddAsyncingAPatientHistory_Then_ThePatientHistoryShouldBeProperlySaved() { var doctor = Doctor.Create("Daniel", "Oana", "*****@*****.**", "parola", "0746524459", "ads", "Cardiologie", "Sf. Spiridon", "Iasi", "Str. Vasile Lupu"); var patient = Patient.Create("Roland", "Iordache", "*****@*****.**", "asfdsdssd", "Iasi", new DateTime(1996, 02, 10), "0746524459", null); RunOnDatabase(async ctx => { //Arrange var repository = new PatientHistoryRepository(ctx); var patientHistory = PatientHistory.Create(patient, doctor, "Paracetamol", "Febra", "Odihna", new DateTime(1996, 02, 10)); //Act await repository.AddAsync(patientHistory); //Assert Assert.AreEqual(repository.GetAllAsync().Result.Count, 1); }); }
public void Given_PatientHistoryRepository_When_AddAsyncingAPatientHistory_Then_ThePatientHistoryShouldBeProperlySaved() { var patient = Patient.Create("1234", "Roland", "Iordache", "*****@*****.**", "asfdsdssd", "Iasi", "Romania", new DateTime(1996, 02, 10), "0746524459", null); var doctor = Doctor.Create("1234", "Mircea", "Cartarescu", "*****@*****.**", "parola", "0746524459", "blasdadsadsada", "Cardiologie", "Sf. Spiridon", "Iasi", "Romania", "Str. Vasile Lupu", true); RunOnDatabase(async ctx => { //Arrange var repository = new PatientHistoryRepository(ctx); var patientHistory = PatientHistory.Create(patient.PatientId); //Act await repository.AddAsync(patientHistory); //Assert string[] includes = { " " }; Assert.AreEqual(repository.GetAllAsync(includes).Result.Count, 1); }); }
public void Given_PatientHistoryRepository_When_ReturningAPatientHistory_Then_ThePatientHistoryShouldBeProperlyReturned() { var patient = Patient.Create("1234", "Roland", "Iordache", "*****@*****.**", "asfdsdssd", "Iasi", "Romania", new DateTime(1996, 02, 10), "0746524459", null); var doctor = Doctor.Create("1234", "Mircea", "Cartarescu", "*****@*****.**", "parola", "0746524459", "blasdadsadsada", "Cardiologie", "Sf. Spiridon", "Iasi", "Romania", "Str. Vasile Lupu", true); RunOnDatabase(async ctx => { //Arrange var repository = new PatientHistoryRepository(ctx); var patientHistory = PatientHistory.Create(patient.PatientId); await repository.AddAsync(patientHistory); //Act var extractedPatientHistory = await repository.GetByIdAsync(patientHistory.HistoryId); //Assert Assert.AreEqual(patientHistory, extractedPatientHistory); }); }