private void LoadTestData() { var dep = DependencyService.Get <Common.ServiceContracts.IAppointment>(); Appointment model = new Appointment { Summary = "Summary test", Location = "Nottingham", StartDate = new DateTime(2019, 7, 29, 10, 15, 0), EndDate = new DateTime(2019, 7, 29, 12, 0, 0) }; using (AppointmentService service = new AppointmentService(dep)) { int i = service.CreateAppointment(model); model = new Appointment { Summary = "Summary test 2", Location = "Derby", StartDate = new DateTime(2019, 7, 29, 1, 0, 0), EndDate = new DateTime(2019, 7, 29, 2, 0, 0) }; i = service.CreateAppointment(model); model = new Appointment { Summary = "Summary test 3", Location = "Derby", StartDate = new DateTime(2019, 7, 16, 1, 0, 0), EndDate = new DateTime(2019, 7, 16, 2, 0, 0) }; i = service.CreateAppointment(model); } }
public void UpdateAppointmentLocationTest_Fail(string update, Appointment res) { Appointment model = new Appointment { Summary = "Test appointment 2", Location = "Nottingham", StartDate = new DateTime(2019, 08, 2, 14, 45, 0), EndDate = new DateTime(2019, 08, 2, 17, 0, 0) }; Appointment val = null; int i = 0; using (AppointmentService service = new AppointmentService(repos)) { i = service.CreateAppointment(model); if (i > 0) { val = service.GetAppointment(i); } if (val != null && val.AppointmentId == i) { val.Location = update; val = service.UpdateAppointment(model); } } Assert.IsTrue(val == res, val != res ? "Appointment updated" : "Update failed: " + i.ToString()); }
public void UpdateAppointmentTest_StartDate_Greater_Than_EndDate() { Appointment model = new Appointment { Summary = "Test appointment 2", Location = "Nottingham", StartDate = new DateTime(2019, 08, 2, 14, 45, 0), EndDate = new DateTime(2019, 08, 2, 17, 0, 0) }; var date = model.StartDate.AddHours(5); Appointment val = null; int i = 0; using (AppointmentService service = new AppointmentService(repos)) { i = service.CreateAppointment(model); if (i > 0) { val = service.GetAppointment(i); } if (val != null && val.AppointmentId == i) { val.StartDate = date; val = service.UpdateAppointment(model); } } Assert.IsTrue((val == null), (val == null) ? "Appointment updated" : "Update failed: " + date.ToString()); }
public void UpdateAppointmentTest_Summary() { Appointment model = new Appointment { Summary = "Test appointment 2", Location = "Nottingham", StartDate = new DateTime(2019, 08, 2, 14, 45, 0), EndDate = new DateTime(2019, 08, 2, 17, 0, 0) }; Appointment val = null; string update = model.Summary; int i = 0; using (AppointmentService service = new AppointmentService(repos)) { i = service.CreateAppointment(model); if (i > 0) { val = service.GetAppointment(i); } if (val != null && val.AppointmentId == i) { val.Summary = "There needs to be some changes around here!"; val = service.UpdateAppointment(model); } } Assert.IsTrue((val != null && val.Summary != update), (val != null && val.Summary != update) ? "Appointment updated" : "Update failed: " + i.ToString()); }
public void LoadAppointmentsByMonthTest() { Appointment model = new Appointment { Summary = "Sept appointment 1", Location = "Nottingham", StartDate = new DateTime(2019, 09, 29, 10, 15, 0), EndDate = new DateTime(2019, 09, 29, 12, 0, 0) }; int i = 0; using (AppointmentService service = new AppointmentService(repos)) { i = service.CreateAppointment(model); } DateTime m = model.StartDate; string name = new DateTimeFormatInfo().GetMonthName(m.Month); int val = 1; List <Appointment> res; using (AppointmentService service = new AppointmentService(repos)) { res = service.GetAppointmentsByMonth(m.Month); } Assert.IsTrue(res.Count == val, "Failed to load Appointments for " + name); }
public ActionResult MakeBooking(Appointment appt, bool acceptsTerms) { if (!acceptsTerms) { ModelState.AddModelError("acceptsTerms", "You must accept the terms"); } try { if (ModelState.IsValid) // Not worth trying if we already know it's bad { AppointmentService.CreateAppointment(appt); } } catch (RulesException ex) { ex.CopyTo(ModelState); // To be implemented in a moment } if (ModelState.IsValid) { return(View("Completed", appt)); } else { return(View()); // Re-renders the same view so the user can fix the errors } }
public async Task CreateAppointment_WithParameters_ShouldCreateAppointment() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var repository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var service = new AppointmentService(repository, ratingRepository); var user = new DentHubUser() { Id = "1", ClinicId = 1, FirstName = "Test", LastName = "Dentist", }; var timeStart = new DateTime(2019, 05, 05, 10, 0, 0); var timeEnd = new DateTime(2019, 05, 05, 10, 30, 0); Assert.NotNull(service.CreateAppointment(user, timeStart, timeEnd)); var result = await dbContext.Appointments.CountAsync(); Assert.Equal(1, result); }
private void CreateNewAppointment(AppointmentService service, Appointment model) { if (service.CreateAppointment(model) < 1) { Message = "Error recording new Appointment"; } }
public void CreateValidAppointment() { var appointments = new List <Appointment>(); appointments.Add(new Appointment() { Id = 1, Date = new DateTime(2018, 3, 1, 8, 20, 0), Doctor = new Doctor() { Id = 1 }, State = new State() { Id = (int)StateEnum.Assigned } }); appointments.Add(new Appointment() { Id = 2, Date = new DateTime(2018, 3, 2, 8, 20, 0), Doctor = new Doctor() { Id = 1 }, State = new State() { Id = (int)StateEnum.Assigned } }); appointments.Add(new Appointment() { Id = 3, Date = new DateTime(2018, 3, 2, 10, 20, 0), Doctor = new Doctor() { Id = 1 }, State = new State() { Id = (int)StateEnum.Assigned } }); mockRepository.Setup(x => x.GetDoctorAppointments(1)).Returns(appointments); mockDoctorService.Setup(x => x.GetDoctor(1)).Returns(new Doctor() { Id = 1 }); mockPatientService.Setup(x => x.GetPatient(1)).Returns(new Patient() { Id = 1 }); var service = new AppointmentService(mockRepository.Object, mockPatientService.Object, mockDoctorService.Object); service.CreateAppointment(new Appointment() { Id = 3, Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 10, 20, 0), Doctor = new Doctor() { Id = 1 }, Patient = new Patient() { Id = 1 } }); }
static void Main(string[] args) { string appointmentResult = AppointmentService.CreateAppointment("Steven Jhonson", "986782342", "5555-555-555", DateTime.Now, "Wall Street", "Armand"); Console.WriteLine(appointmentResult); string appointmentResult2 = AppointmentService.CreateAppointment("Ralf Manson", "", "5555-555-555", DateTime.Now, "Queen Street", ""); Console.WriteLine(appointmentResult2); }
public async void CreateAppointmentForUnexistingUserAndDoctorShouldThrowExeption() { var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); var appointmentService = new AppointmentService(dbContext); await Assert.ThrowsAsync <ArgumentException> (async() => await appointmentService.CreateAppointment(null, "*****@*****.**", new DateTime(2019, 08, 03, 09, 00, 00))); }
public ActionResult CreateAppointments(List <Appointment> appointments) { var appointmentIds = new List <Guid>(); foreach (var appointment in appointments) { var appointmentId = AppointmentService.CreateAppointment(GetHttpClient(), GetService(), appointment); appointmentIds.Add(appointmentId); } return(Json(appointmentIds, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage PostAppointment([FromBody] Appointment appointment) { if (appointment != null) { //var oAppointment = JsonConvert.DeserializeObject<Appointment>(appointment.ToString()); bool status = appointmentService.CreateAppointment(appointment); if (status) { return(Request.CreateResponse(System.Net.HttpStatusCode.Created, appointment)); } return(Request.CreateResponse(System.Net.HttpStatusCode.BadRequest)); } return(Request.CreateResponse(System.Net.HttpStatusCode.Ambiguous)); }
public void CreateAppointmentWithAInvalidHour() { var appointments = new List <Appointment>(); appointments.Add(new Appointment() { Id = 1, Date = new DateTime(2018, 3, 1, 8, 20, 0), Doctor = new Doctor() { Id = 1 }, State = new State() { Id = (int)StateEnum.Assigned } }); appointments.Add(new Appointment() { Id = 2, Date = new DateTime(2018, 3, 2, 8, 20, 0), Doctor = new Doctor() { Id = 1 }, State = new State() { Id = (int)StateEnum.Assigned } }); appointments.Add(new Appointment() { Id = 3, Date = new DateTime(2018, 3, 2, 10, 20, 0), Doctor = new Doctor() { Id = 1 }, State = new State() { Id = (int)StateEnum.Assigned } }); mockRepository.Setup(x => x.GetDoctorAppointments(1)).Returns(appointments); var service = new AppointmentService(mockRepository.Object, mockPatientService.Object, mockDoctorService.Object); service.CreateAppointment(new Appointment() { Id = 3, Date = new DateTime(2017, 3, 2, 3, 20, 0), Doctor = new Doctor() { Id = 1 } }); }
public void CreateAppointmentTest() { Appointment model = new Appointment { Summary = "Test appointment 1", Location = "Nottingham", StartDate = new System.DateTime(2019, 07, 29, 10, 15, 0), EndDate = new System.DateTime(2019, 07, 29, 12, 0, 0) }; int i = 0; using (AppointmentService service = new AppointmentService(repos)) { i = service.CreateAppointment(model); } Assert.IsTrue(i > 0, i == 0 ? "Failed to create new Appointment" : "Appointment created ID: " + i.ToString()); }
public async Task <ActionResult <AppointmentDto> > Post(AppointmentDto model) { try { if (ModelState.IsValid) { //var existing = await _appointmentService.GetAppointmentByIdAsync(model.AppointmentId); //if (existing != null) //{ // return BadRequest("The appointment is already exists!"); //} //var location = _linkGenerator.GetPathByAction(HttpContext, // "Get", "Appointments", // new { name = model.AppointmentId }); //if (string.IsNullOrWhiteSpace(location)) //{ // return BadRequest("Could not use current id"); //} var appointment = _mapper.Map <Appointment>(model); if (await _appointmentService.CreateAppointment(appointment)) { return(StatusCode(StatusCodes.Status201Created, appointment)); } return(BadRequest("Something bad happened!")); } else { return(BadRequest(ModelState)); } } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e}")); } }
public void GetAppointmentByIdTest() { Appointment model = new Appointment { Summary = "Test appointment 2", Location = "Nottingham", StartDate = new DateTime(2019, 08, 2, 14, 45, 0), EndDate = new DateTime(2019, 08, 2, 17, 0, 0) }; Appointment val = null; int i = 0; using (AppointmentService service = new AppointmentService(repos)) { i = service.CreateAppointment(model); if (i > 0) { val = service.GetAppointment(i); } } Assert.IsTrue((val != null && val.AppointmentId == i), (val != null && val.AppointmentId == i) ? "Retrieve Appointment" : "Failed to get Appointment: " + i.ToString()); }
public ActionResult ProceedWithCheckout2(List <CombinedPropertyObject> combinedPropertyObjects, List <InspectionPortalQA> questions) { var httpClient = GetHttpClient(); var service = GetService(); var orderId = Guid.Empty; Order newlyCreatedOrder = null; var existingOrder = OrderService.QueryOrderByOpportunity(httpClient, combinedPropertyObjects[0].OpportunityId); if (existingOrder == null) { orderId = OpportunityService.ConvertOpportunityToSalesOrder(GetService(), combinedPropertyObjects[0].OpportunityId); } else { orderId = existingOrder.Id; } newlyCreatedOrder = OrderService.QueryOrder(httpClient, orderId); if (newlyCreatedOrder == null) { return(Json("Error occured while retrieveing order with id: " + orderId, JsonRequestBehavior.AllowGet)); } var opportunity = OpportunityService.QueryOpportunity(GetHttpClient(), combinedPropertyObjects[0].OpportunityId); if (opportunity.StateCode == 0) { OpportunityService.SetOpportunityState(GetService(), combinedPropertyObjects[0].OpportunityId); } var newPropertyId = Guid.Empty; var newInspectionDetailId = Guid.Empty; foreach (var cpo in combinedPropertyObjects) { if (cpo.Apppointment != null) { var newAppointmentId = AppointmentService.CreateAppointment(httpClient, service, cpo.Apppointment); cpo.Inspection.AppointmentId = newAppointmentId; cpo.Inspection.OrderId = orderId; if (cpo.DoCreateAnInspection) { if (newPropertyId == Guid.Empty) { newPropertyId = InspectionService.CreateProperty(httpClient, cpo.Property); cpo.Inspection.PropertyId = newPropertyId; } else { cpo.Inspection.PropertyId = newPropertyId; } } else { cpo.Inspection.PropertyId = cpo.Property.Id; } newInspectionDetailId = InspectionService.CreateInspection(httpClient, cpo.Inspection); } if (questions == null || questions.Count == 0) { continue; } var questionCount = 0; foreach (var question in questions) { if (question == null) { continue; } question.InspectionId = newInspectionDetailId; question.OrderId = orderId; question.PropertyId = newPropertyId == Guid.Empty ? cpo.Property.Id : newPropertyId; question.OpportunityId = opportunity.Id; QuestionSetupService.CreateInspectionPortalQA(httpClient, question); questionCount++; if (question.AdditionalProductId != Guid.Empty && (question.AnswerDataTypeText == "Boolean (Yes/No)" || question.AnswerDataTypeText == "Boolean (True/False)")) { if (question.Answer != "Yes") { continue; } var product = ProductService.QueryProduct(httpClient, question.AdditionalProductId); if (product == null) { continue; } var orderProduct = new OrderProduct() { OrderId = orderId, Amount = product.BuyerPays, ProductId = product.Id, UomId = product.UomId }; OrderService.CreateOrderProduct(httpClient, orderProduct); } } } return(Json(newlyCreatedOrder, JsonRequestBehavior.AllowGet)); }
public ActionResult CreateAppointment(Appointment appointment) { var appointmentId = AppointmentService.CreateAppointment(GetService(), appointment); return(Json(appointmentId, JsonRequestBehavior.AllowGet)); }
public ActionResult ProceedWithCheckout(List <CombinedPropertyObject> combinedPropertyObjects, List <InspectionPortalQA> questions) { var httpClient = GetHttpClient(); var service = GetService(); var orderId = Guid.Empty; var propertyId = Guid.Empty; var inspectionDetailId = Guid.Empty; #region Create Property var firstItem = combinedPropertyObjects[0]; if (firstItem.DoCreateAnInspection) { if (propertyId == Guid.Empty) { propertyId = InspectionService.CreateProperty(httpClient, firstItem.Property); firstItem.Inspection.PropertyId = propertyId; } else { firstItem.Inspection.PropertyId = propertyId; } } else { propertyId = firstItem.Property.Id; //firstItem.Inspection.PropertyId = propertyId; } #endregion /*Query order. If order does not exist, then conver opportunity to order*/ var existingOrder = OrderService.QueryOrderByOpportunity(httpClient, combinedPropertyObjects[0].OpportunityId); if (existingOrder == null) { orderId = OpportunityService.ConvertOpportunityToSalesOrder(service, combinedPropertyObjects[0].OpportunityId); } else { orderId = existingOrder.Id; } #region Opportunity Update var opportunity = OpportunityService.QueryOpportunity(httpClient, firstItem.OpportunityId); if (opportunity != null) { opportunity.PropertyId = propertyId; OpportunityService.UpdateOpportunity(httpClient, opportunity); if (opportunity.StateCode == 0) { OpportunityService.SetOpportunityState(service, firstItem.OpportunityId); } } #endregion #region Appointments, Inspection foreach (var cpo in combinedPropertyObjects) { if (cpo.Apppointment == null) { continue; } var newAppointmentId = AppointmentService.CreateAppointment(httpClient, service, cpo.Apppointment); cpo.Inspection.AppointmentId = newAppointmentId; cpo.Inspection.OrderId = orderId; cpo.Inspection.PropertyId = propertyId; inspectionDetailId = InspectionService.CreateInspection(httpClient, cpo.Inspection); } #endregion #region Order var newlyCreatedOrder = OrderService.QueryOrder(httpClient, orderId); if (newlyCreatedOrder == null) { return(Json("Error occured while retrieveing order with id: " + orderId, JsonRequestBehavior.AllowGet)); } newlyCreatedOrder.PropertyId = propertyId; OrderService.UpdateOrder(httpClient, newlyCreatedOrder); #endregion #region Questions if (questions != null) { foreach (var question in questions) { if (question == null) { continue; } question.InspectionId = inspectionDetailId; question.OrderId = orderId; question.PropertyId = propertyId; question.OpportunityId = opportunity.Id; QuestionSetupService.CreateInspectionPortalQA(httpClient, question); if (question.AdditionalProductId != Guid.Empty && (question.AnswerDataTypeText == "Boolean (Yes/No)" || question.AnswerDataTypeText == "Boolean (True/False)")) { if (question.Answer != "Yes") { continue; } var product = ProductService.QueryProduct(httpClient, question.AdditionalProductId); if (product == null) { continue; } var orderProduct = new OrderProduct() { OrderId = orderId, Amount = product.BuyerPays, ProductId = product.Id, UomId = product.UomId }; OrderService.CreateOrderProduct(httpClient, orderProduct); } } } #endregion return(Json(newlyCreatedOrder, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> PostAppointment(long idHospital) { return(Ok(await _appointmentService.CreateAppointment(idHospital).ConfigureAwait(false))); }
public async void CreateAppointmentForUnexistingUserAndDoctorShouldReturnTrue() { //Arrange var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); var appointmentService = new AppointmentService(dbContext); //var usrManager = MockHelpers.MockUserManager<EClinicUser>(); var mockUserStore = new Mock <IUserStore <EClinicUser> >(); var userManager = new UserManager <EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); //userManager.UserValidators.Add(new UserValidator<EClinicUser>()); //userManager.PasswordValidators.Add(new PasswordValidator<EClinicUser>()); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; //await userManager.CreateAsync(AdminUserToAdd); //await userManager.CreateAsync(userToAdd); dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); int count = dbContext.Users.Count(); var result = await appointmentService.CreateAppointment("*****@*****.**", "*****@*****.**", new DateTime(2019, 08, 03, 09, 00, 00)); Assert.True(result); }
public void CreateAppointment_NullRequest_Test() { Assert.ThrowsAsync <ArgumentNullException>(() => _underTest.CreateAppointment(null)); }