public async Task CreateAppointmentAsync_NotExistingEmployeeId_ShouldThrowFactroApiException() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var appointmentApi = this.fixture.GetService <IAppointmentApi>(); var employeeId = Guid.NewGuid().ToString(); var startDate = DateTime.Now; var endDate = startDate.AddHours(1); var subject = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject); var createAppointmentResponse = default(CreateAppointmentResponse); // Act Func <Task> act = async() => createAppointmentResponse = await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); using (new AssertionScope()) { var appointments = (await appointmentApi.GetAppointmentsAsync()) .Where(x => x.Subject.StartsWith(BaseTestFixture.TestPrefix)).ToList(); appointments.Should().NotContain(x => x.EmployeeId == employeeId && x.Subject == subject); createAppointmentResponse.Should().BeNull(); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task CreateAppointmentAsync_TwoIdenticalAppointments_ShouldStoreBothAppointments() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var appointmentApi = this.fixture.GetService <IAppointmentApi>(); const string employeeId = BaseTestFixture.ValidEmployeeId; var startDate = DateTime.Now; var endDate = startDate.AddHours(1); var subject = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject); await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Act Func <Task> act = async() => await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { var appointments = (await appointmentApi.GetAppointmentsAsync()) .Where(x => x.Subject.StartsWith(BaseTestFixture.TestPrefix)).ToList(); var matchingAppointments = appointments.Where(x => x.Subject == subject); matchingAppointments.Should().HaveCount(2); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task CreateAppointmentAsync_ValidAppointment_ShouldStoreAppointment() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var appointmentApi = this.fixture.GetService <IAppointmentApi>(); const string employeeId = BaseTestFixture.ValidEmployeeId; var startDate = DateTime.Now; var endDate = startDate.AddHours(1); var subject = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject); var createAppointmentResponse = default(CreateAppointmentResponse); // Act Func <Task> act = async() => createAppointmentResponse = await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { var appointments = (await appointmentApi.GetAppointmentsAsync()) .Where(x => x.Subject.StartsWith(BaseTestFixture.TestPrefix)).ToList(); appointments.Should().ContainEquivalentOf(createAppointmentResponse); } await this.fixture.ClearFactroInstanceAsync(); }
public IHttpActionResult Create(CreateAppointmentRequest request) { var service = ExchangeServer.Open(); var appointment = new Appointment(service); // Set the properties on the appointment object to create the appointment. appointment.Subject = request.Subject; appointment.Body = request.Body; appointment.Start = DateTime.Parse(request.Start); //appointment.StartTimeZone = TimeZoneInfo.Local; appointment.End = DateTime.Parse(request.End); //appointment.EndTimeZone = TimeZoneInfo.Local; appointment.Location = request.Location; //appointment.ReminderDueBy = DateTime.Now; foreach (var email in request.Recipients) { appointment.RequiredAttendees.Add(email); } // Save the appointment to your calendar. appointment.Save(SendInvitationsMode.SendOnlyToAll); // Verify that the appointment was created by using the appointment's item ID. Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject)); var response = new CreateAppointmentResponse { Message = "Appointment created: " + item.Subject, AppointId = appointment.Id.ToString() }; return(Ok(response)); }
public async Task <IActionResult> Post([FromBody] CreateAppointmentRequest request) { var appointmentCommand = mapper.Map <CreateAppointmentCommand>(request); appointmentCommand.CreatedBy = Guid.Parse(User.Claims.FirstOrDefault(x => x.Type == "id").Value); var getPatientTask = patientApi.GetPatient(request.PatientId); var getFromClinicTask = clinicApi.GetClinic(request.FromClinicId); var getToClinicTask = clinicApi.GetClinic(request.ToClinicId); await Task.WhenAll(getPatientTask, getFromClinicTask, getToClinicTask); var getPatientResultTask = getPatientTask.Result.Content.DeserializeStringContent <DTO.Patient.GetPatientResponse>(); var getFromClinicResultTask = getFromClinicTask.Result.Content.DeserializeStringContent <DTO.Clinic.GetClinicResponse>(); var getToClinicResultTask = getToClinicTask.Result.Content.DeserializeStringContent <DTO.Clinic.GetClinicResponse>(); await Task.WhenAll(getPatientResultTask, getFromClinicResultTask, getToClinicResultTask); appointmentCommand.FromClinicName = getFromClinicResultTask.Result.Name; appointmentCommand.ToClinicName = getToClinicResultTask.Result.Name; appointmentCommand.PatientName = getPatientResultTask.Result.FirstName + " " + getPatientResultTask.Result.LastName; var consultationCreateResponse = await appointmentApi.SaveAppointment(appointmentCommand); var consultationCreateContent = await consultationCreateResponse.Content.DeserializeStringContent <string>(); if (!consultationCreateResponse.IsSuccessStatusCode) { return(BadRequest(consultationCreateContent)); } return(CreatedAtAction(nameof(GetAppointmentById), new { id = consultationCreateContent }, consultationCreateContent)); }
public async Task <CreateAppointmentResponse> Create(CreateAppointmentRequest request) { try { var appointment = new Appointment(request.Name, request.StartDateTime, request.Length, request.Owner, request.Invitee); var overlaps = await _appointmentRepository.QueryOverlaps(appointment); if (overlaps.Count() > 0) { throw new AppoinmentOverlappedException($"{appointment.StartDateTime} and with {appointment.EndDateTime} is overlapped"); } var entity = await _appointmentRepository.Save(appointment); return(new CreateAppointmentResponse { Id = entity.Id, EndDateTime = entity.EndDateTime, Invitee = entity.Invitee, StartDateTime = entity.StartDateTime, Length = entity.Length, Name = entity.Name, Owner = entity.Owner }); } catch (Exception exception) { _logger.LogError(exception, $"{nameof(Create)} appoinment error occured", request); throw; } }
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 void ValidateCreateAppointmentRequest_NullRequest_Test() { CreateAppointmentRequest input = null; var validateMessage = _validateRequest.ValidateRequestData(input).ToList(); Assert.IsTrue(validateMessage.Find(x => x.Contains(ExceptionMessages.InvalidRequest)) != null); }
public async Task CreateAppointment_UnsuccessfulRequest_ShouldThrowAppointmentApiException() { // Arrange var employeeId = Guid.NewGuid().ToString(); var startDate = DateTime.UtcNow; var endDate = startDate.AddHours(1); var subject = Guid.NewGuid().ToString(); var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject); var expectedResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { RequestUri = new Uri("http://www.mock-web-address.com"), }, }; var appointmentApi = this.fixture.GetAppointmentApi(expectedResponse); // Act Func <Task> act = async() => await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public async Task <ActionResult> CreateEvent(CreateEventViewModel eventObject) { var model = eventObject; // Create EWS Appointment var request = new CreateAppointmentRequest { Body = "Created From Web App", End = DateTime.Parse(eventObject.Event.end).ToString(), Start = DateTime.Parse(eventObject.Event.start).ToString(), Location = "Web", Subject = eventObject.Event.title, Recipients = eventObject.Users }; var resp = await _client.CreateAppointment(request); // Send Emails var emailRequest = new SendEmailRequest { Recipients = eventObject.Users, Body = "Automated Email After Appointment Creation", FileAttachments = new List <string>(), Subject = "Automated Email After Appointment Creation" }; var sendEmailResponse = await _client.SendEmail(emailRequest); return(RedirectToAction("Index")); }
public async Task <JsonResult> Post([FromBody] CreateAppointmentRequest request) { var command = _mapper.Map <CreateAppointmentCommand>(request); var cmdResponse = await PublishCommand(command); var response = cmdResponse.AsApiResponse(201, 409); return(response); }
public async Task <IActionResult> Create(CreateAppointmentRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState.ValidationState)); } var response = await _appointmentService.Create(request); return(Ok(response)); }
public CreateAppointmentResponse Post(CreateAppointmentRequest request) { var appointment = this.appointmentsApplication.Create(Request.ToCaller(), request.StartUtc, request.EndUtc, request.DoctorId); Response.SetLocation(appointment); return(new CreateAppointmentResponse { Appointment = appointment }); }
public void Initialize() { this.identifierFactory = new Mock <IIdentifierFactory>(); this.identifierFactory.Setup(f => f.IsValid(It.IsAny <Identifier>())).Returns(true); this.validator = new CreateAppointmentRequestValidator(this.identifierFactory.Object); this.dto = new CreateAppointmentRequest { StartUtc = DateTime.UtcNow.AddSeconds(1), EndUtc = DateTime.UtcNow.AddSeconds(2), DoctorId = "adoctorid" }; }
public async Task <CreateAppointmentResponse> CreateTestAppointmentAsync(IAppointmentApi appointmentApi) { const string employeeId = ValidEmployeeId; var startDate = DateTime.Now; var endDate = startDate.AddHours(1); var subject = $"{TestPrefix}{Guid.NewGuid().ToString()}"; var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject); var createAppointmentResponse = await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); return(createAppointmentResponse); }
public async Task CreateAppointment(CreateAppointmentRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var appointment = MapAppointment(request); var appointmentJob = MapAppointmentJob(request); var appointmentId = await _appointmentDAL.SaveAppointment(appointment); appointmentJob.AppointmentId = appointmentId; await _appointmentDAL.SaveAppointmentJob(appointmentJob); }
private StringContent GetValidNewAppointmentJson(Guid scheduleId) { var request = new CreateAppointmentRequest() { AppointmentTypeId = _testAppointmentTypeId, ClientId = _testClientId, DateOfAppointment = new OfficeSettings().TestDate, Title = "new appointment title", PatientId = _testPatientId, RoomId = _testRoomId, ScheduleId = scheduleId, SelectedDoctor = _testDoctorId }; var jsonContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"); return(jsonContent); }
public async Task CreateAppointmentAsync_NullRequestModelSubject_ShouldThrowArgumentNullException() { // Arrange var employeeId = Guid.NewGuid().ToString(); var startDate = DateTime.UtcNow; var endDate = startDate.AddHours(1); var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, null); var appointmentApi = this.fixture.GetAppointmentApi(); // Act Func <Task> act = async() => await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
/// <inheritdoc/> /// <exception cref="ArgumentNullException"><paramref name="createAppointmentRequest"/> is null or EmployeeId or Subject is null, empty or whitespace</exception> public async Task <CreateAppointmentResponse> CreateAppointmentAsync(CreateAppointmentRequest createAppointmentRequest) { if (createAppointmentRequest == null) { throw new ArgumentNullException(nameof(createAppointmentRequest), $"{nameof(createAppointmentRequest)} can not be null."); } if (string.IsNullOrWhiteSpace(createAppointmentRequest.EmployeeId)) { throw new ArgumentNullException(nameof(createAppointmentRequest), $"{nameof(createAppointmentRequest.EmployeeId)} can not be null, empty or whitespace."); } if (createAppointmentRequest.Subject == null) { throw new ArgumentNullException(nameof(createAppointmentRequest), $"{nameof(createAppointmentRequest.Subject)} can not be null."); } var requestRoute = AppointmentApiEndpoints.Base.Create(); var requestString = JsonConvert.SerializeObject(createAppointmentRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PostAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( "Could not create appointment.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } var responseContentString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <CreateAppointmentResponse>( responseContentString, this.jsonSerializerSettings); return(result); }
public void CreateAppointment() { var rep = new EWSIntegrationClient(); var start = new DateTime(2016, 1, 13, 13, 0, 0); var end = start.AddHours(1); var request = new CreateAppointmentRequest { Body = "Test Appointment From MVC Unit Test", Location = "MVC Unit Test", Subject = "MVC Unit Test Appointment", Start = start.ToString(), End = end.ToString() }; var result = rep.CreateAppointment(request).Result; Assert.IsNotNull(result.AppointId); }
public async Task <CreateAppointmentResponse> CreateAppointment(CreateAppointmentRequest request) { var response = new CreateAppointmentResponse(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage resp = await client.PostAsJsonAsync("/api/appointments", request); if (resp.IsSuccessStatusCode) { response = await resp.Content.ReadAsAsync <CreateAppointmentResponse>(); return(response); } } return(response); }
public async Task CreateAppointment_ValidRequest_ShouldReturnCreatedAppointment() { // Arrange var employeeId = Guid.NewGuid().ToString(); var startDate = DateTime.UtcNow; var endDate = startDate.AddHours(1); var subject = Guid.NewGuid().ToString(); var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject); var expectedAppointment = new CreateAppointmentResponse { EmployeeId = createAppointmentRequest.EmployeeId, StartDate = createAppointmentRequest.StartDate, EndDate = createAppointmentRequest.EndDate, Subject = createAppointmentRequest.Subject, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedAppointment, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var appointmentApi = this.fixture.GetAppointmentApi(expectedResponse); var createAppointmentResponse = default(CreateAppointmentResponse); // Act Func <Task> act = async() => createAppointmentResponse = await appointmentApi.CreateAppointmentAsync(createAppointmentRequest); // Assert await act.Should().NotThrowAsync(); createAppointmentResponse.Should().BeEquivalentTo(expectedAppointment); }
public void CreateAppointment() { var controller = new AppointmentsController(); var start = new DateTime(2016, 1, 15, 13, 0, 0); var end = start.AddHours(2); var request = new CreateAppointmentRequest { Body = "Appointment Created from Unit Test", Location = "Cconference Room", Subject = "Appointment Unit Test", Start = start.ToString(), End = end.ToString(), Recipients = new List <string> { "*****@*****.**" } }; var result = controller.Create(request) as OkNegotiatedContentResult <CreateAppointmentResponse>; Assert.IsNotNull(result.Content.AppointId); Assert.IsNotNull(result.Content.Message); }
public async Task <AppointmentDto> CreateAsync(CreateAppointmentRequest appointment) { return((await _httpService.HttpPostAsync <CreateAppointmentResponse>("appointments", appointment)).Appointment); }
internal AppointmentJob MapAppointmentJob(CreateAppointmentRequest request) { return(_mapper.Map <CreateAppointmentRequest, AppointmentJob>(request)); }
public async Task <AppointmentDto> CreateAsync(CreateAppointmentRequest appointment) { _logger.LogInformation($"Creating new appointment for {appointment.Title}"); return((await _httpService.HttpPostAsync <CreateAppointmentResponse>(CreateAppointmentRequest.Route, appointment)).Appointment); }