Exemple #1
0
        public async Task Given_Prescription_To_Update_returns_200()
        {
            var entity = new UpdatePrescriptionDto
            {
                ConsultationId = _constulatations[0].Id,
                Description    = "DEDEDE"
            };
            var result = await FakeController.Put(_fakeEntities[0].Id, entity);

            var objectResult = (OkObjectResult)result;

            Assert.NotNull(_fakeEntities[0].UpdatedAt);
            Assert.Equal(200, objectResult.StatusCode);
        }
Exemple #2
0
        public async Task <IActionResult> Put(int id, [FromBody] UpdatePrescriptionDto updatePrescriptionDto)
        {
            var prescription = await _prescriptionRepository.Get(id);

            if (prescription == null)
            {
                return(NotFound());
            }

            if (updatePrescriptionDto.ConsultationId != null)
            {
                var consultation = await _consultationRepository.Get(updatePrescriptionDto.ConsultationId.Value);

                if (consultation == null)
                {
                    return(BadRequest("Consult bestaat niet."));
                }
            }

            if (updatePrescriptionDto.PatientId != null)
            {
                var patient = await _patientRepository.Get(updatePrescriptionDto.PatientId.Value);

                if (patient == null)
                {
                    return(BadRequest("Patiënt bestaat niet."));
                }
            }

            var userId      = User.Claims.First(u => u.Type == ClaimTypes.Sid).Value;
            var currentUser = await _identityRepository.GetUserById(userId);

            _mapper.Map(updatePrescriptionDto, prescription);

            prescription.Id = id;

            var updatedPrescription = await _prescriptionRepository.Update(prescription, currentUser);

            var updatedPrescriptionDto = _mapper.Map <Prescription, UpdatedPrescriptionDto>(updatedPrescription);

            return(Ok(updatedPrescriptionDto));
        }
Exemple #3
0
        public async Task Update_prescriptions_And_test_If_User_Changed()
        {
            var environmentVariable = Environment.GetEnvironmentVariable("prescriptions");
            var jObject             = JObject.Parse(environmentVariable);
            var dto = jObject.ToObject <Prescription>();

            var update = new UpdatePrescriptionDto
            {
                Description    = "commentscomments",
                PatientId      = dto.Patient.Id,
                ConsultationId = dto.Consultation.Id,
                EndDate        = DateTime.Now,
                StartDate      = DateTime.Now
            };

            var serialize = JsonConvert.SerializeObject(update);
            var content   = new StringContent(serialize, Encoding.UTF8, "application/json");

            var defaultPage = await _client.PutAsync("/api/prescriptions/" + dto.Id, content);

            var readAsStringAsync = defaultPage.Content.ReadAsStringAsync();
            var json = readAsStringAsync.Result;
            var u    = JObject.Parse(json);
            var user = u.ToObject <Prescription>();


            var defaultPager = await _client.GetAsync("/api/prescriptions/" + dto.Id);

            var asStringAsync = defaultPager.Content.ReadAsStringAsync();
            var result        = asStringAsync.Result;
            var parsedJObject = JObject.Parse(result);
            var userDto       = parsedJObject.ToObject <Prescription>();

            Assert.Equal(HttpStatusCode.OK, defaultPager.StatusCode);
            Assert.NotNull(environmentVariable);
            Assert.IsType <Prescription>(userDto);
            Assert.Equal(update.Description, userDto.Description);
            Assert.Equal(HttpStatusCode.OK, defaultPage.StatusCode);
            Assert.NotNull(user);
        }