private async Task SaveAppointment() { if (IsValid()) { if (Appointment.AppointmentId == Guid.Empty) { CreateAppointmentRequest toCreate = new CreateAppointmentRequest() { Details = Title, SelectedDoctor = (int)Appointment.DoctorId, PatientId = Patient.PatientId, ClientId = Patient.ClientId, ScheduleId = ScheduleId, RoomId = Appointment.RoomId, AppointmentTypeId = Appointment.AppointmentTypeId, DateOfAppointment = Appointment.Start.DateTime, }; await AppointmentService.CreateAsync(toCreate); } else { var toUpdate = UpdateAppointmentRequest.FromDto(Appointment); await AppointmentService.EditAsync(toUpdate); } await OnAppointmentChanged.InvokeAsync(Appointment.Title); } }
public async Task TestCreateAsyncModelPatientNull() { // Arrange var service = new AppointmentService(null, null, null, null); // Act async Task TestAction() => await service.CreateAsync(new AppointmentDTO { Patient = null }); // Assert var ex = await Assert.ThrowsAsync <ArgumentNullException>(TestAction); Assert.Equal("Patient", ex.ParamName); }
public async Task <IActionResult> Create([FromBody] AppointmentRequest request) { try { await appointmentService.CreateAsync(request); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task TestCreateAsync() { // Arrange var consultant = new Consultant { Id = 1 }; var week = new Week { Id = 1 }; var day = new Day { Id = 1 }; var timeSlot = new TimeSlot { Id = 1 }; var dto = new AppointmentDTO { ConsultantId = consultant.Id, TimeSlotId = 1, Date = DateTime.Today, Patient = new PatientDTO() }; var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(x => x.ConsultantRepository.GetByIdAsync(It.IsAny <int>(), It.IsAny <bool>())) .ReturnsAsync(consultant); mockUnitOfWork .Setup(x => x.WeekRepository.GetByIdAsync(It.IsAny <int>(), It.IsAny <bool>())) .ReturnsAsync(week); mockUnitOfWork .Setup(x => x.DayRepository.GetByConditionAsync(It.IsAny <Expression <Func <Day, bool> > >(), It.IsAny <bool>())) .ReturnsAsync(new List <Day> { day }); mockUnitOfWork .Setup(x => x.TimeSlotRepository.GetByIdAsync(It.IsAny <int>(), It.IsAny <bool>())) .ReturnsAsync(timeSlot); mockUnitOfWork .Setup(x => x.AppointmentRepository.Add(It.IsAny <Appointment>())) .Verifiable(); mockUnitOfWork .Setup(x => x.CommitAsync()) .Verifiable(); var mockPublisher = new Mock <IAppointmentPublisher>(); mockPublisher .Setup(x => x.PushMessageToQueue(It.IsAny <AppointmentMessage>())) .Verifiable(); var service = new AppointmentService(mockUnitOfWork.Object, _mapper, mockPublisher.Object, _mockLogger.Object); // Act var result = await service.CreateAsync(dto); // Assert Assert.NotNull(result); Assert.IsAssignableFrom <AppointmentDTO>(result); mockPublisher .Verify(x => x.PushMessageToQueue(It.IsAny <AppointmentMessage>()), Times.Once()); mockUnitOfWork .Verify(x => x.AppointmentRepository.Add(It.IsAny <Appointment>()), Times.Once); mockUnitOfWork .Verify(x => x.CommitAsync(), Times.Once); }
public async Task <IActionResult> Create(CreateAppointmentDto createAppointmentDto) { var appointment = await _appointmentService.CreateAsync(createAppointmentDto); return(CreatedAtAction(nameof(GetById), new { id = appointment.Id }, appointment)); }