public void AddBooking_ValidatesRequest() { //arrange //arrange var clinic = _fixture.Create <Clinic>(); var doctor = _fixture.Create <Doctor>(); var patient = _fixture.Create <Patient>(); patient.Clinic = clinic; _context.Clinic.Add(clinic); _context.Patient.Add(patient); _context.Doctor.Add(doctor); _context.SaveChanges(); var request = _fixture.Create <AddBookingRequest>(); request.DoctorId = doctor.Id; request.PatientId = patient.Id; //act _bookingService.AddBooking(request); //assert _validator.Verify(x => x.ValidateRequest(request), Times.Once); }
public void AddBooking_ValidatesRequest() { //arrange var request = _fixture.Create <AddBookingRequest>(); //act _bookingService.AddBooking(request); //assert _addBookingRequestValidation.Verify(x => x.ValidateRequest(request), Times.Once); }
public async Task ShouldReturnBookingsByRenter() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var bookingService = new BookingService(dbContext); var car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 10 }; for (int i = 0; i < 5; i++) { var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = car, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; await bookingService.AddBooking(booking); } for (int i = 0; i < 5; i++) { var booking = new Booking { GuestUserId = "YYYYYY", GuestName = "YYYYYY", Car = car, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; await bookingService.AddBooking(booking); } var pendingBookings = await bookingService.GetPendingBookings(); Assert.Equal(10, pendingBookings.Count); var bookingsByRenter = await bookingService.GetBookings("XXXXXX"); Assert.Equal(5, bookingsByRenter.Count); Assert.Equal("XXXXXX", bookingsByRenter[3].GuestUserId); }
public void AddBooking_ValidatesRequest() { //arrange var request = _fixture.Create <AddBookingRequest>(); //act _bookingService.AddBooking(request); //assert using (new AssertionScope()) { _addBookingValidator.Verify(x => x.ValidateRequest(request), Times.Once); } }
public async Task ShouldNotAllowBookingIfCarIsNotAvailable() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var carService = new CarService(dbContext); var bookingService = new BookingService(dbContext); var car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 1 }; var carResult = await carService.AddCarDetail("tester", car); car = await carService.GetCar(carResult.Id.Value); var booking1 = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = car, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; await bookingService.AddBooking(booking1); var booking2 = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = car, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking2); Assert.False(result.Success); Assert.NotNull(result.ValidationErrors); Assert.Equal("All available units are rented out.", result.ValidationErrors["Car"]); }
public IActionResult Booking(Booking createdBooking, DateTime date, DateTime time) { createdBooking.Time = date + time.TimeOfDay; BookingStatus status; var goat = "goat"; if (DateTime.Now > createdBooking.Time) { status = BookingStatus.InPast; } else if (holidayService.IsConflict(createdBooking)) { status = BookingStatus.OnHoliday; } else { status = bookingService.AddBooking(createdBooking); } if (status == BookingStatus.BookingMade) { return(View("Confirmation", createdBooking)); } ModelState.AddModelError(string.Empty, BookingErrorMessageLookup[status]); return(View(createdBooking)); }
public async Task ShouldAddBookingUnderNormalCircumstances() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); Assert.True(result.Success); Assert.Equal(1, result.Id); Assert.Empty(result.ValidationErrors); }
/// <summary> /// Eventhandler for button "Make booking for selected car". /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnChooseCar_Click(object sender, EventArgs e) { try { int bookingId = bookingServiceClient.AddBooking(CreateBooking()); Booking b = bookingServiceClient.GetBooking(bookingId); lstBoxConfirmation.Items.Add(new ListItem($"{b.CustomerToBook.FirstName}, {b.CustomerToBook.LastName}, " + $"{b.CarToBook.Brand}, {b.CarToBook.Model}, {b.StartDate}, {b.EndDate}")); txtCustomerID.Text = String.Empty; txtEmail.Text = String.Empty; txtFirstName.Text = String.Empty; txtLastName.Text = String.Empty; txtPhone.Text = String.Empty; } catch (FaultException ex) { lblErrorNocarChosen.Text = ex.Message; } catch (TimeoutException ex) { lblErrorNocarChosen.Text = ex.Message; } catch (EndpointNotFoundException) { Response.Write("<script>alert('Endpoint not found, please check connection.');</script>"); } }
public BookingResource AddBooking(BookingDTO dto) { Booking toAdd = new Booking().CopyPropertiesFrom(dto); Booking dbBooking = service.AddBooking(toAdd); BookingResource b = new BookingResource().CopyPropertiesFrom(dbBooking); b.PersonResource = GetPersonResFromBooking(dbBooking); return(b); }
private void saveButton_Click(object sender, RoutedEventArgs e) { int tableCount = tableNoTextBox.Text.Split(',').Length; Booking b = new Booking(Convert.ToDateTime(bookingDate.Text), startTimeTextBox.Text, endingTimeTextBox.Text, tableNoTextBox.Text, tableCount, customerNameTextBox.Text, phoneTextBox.Text, addressTextBox.Text, Convert.ToDouble(advanceTextBox.Text)); BookingService bs = new BookingService(); bs.AddBooking(b); MessageBox.Show("Successfull Booking"); this.Close(); }
public ActionResult PhotoGrapherBooking(PhotoGrapherBooking book) { bk.AddBooking(book); TempData["msg"] = "<script>alert('PhotoGrapher Booking Successfully ,FeedBack Soon');</script>"; //Current Url Redirect return(Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri)); }
public void AddBooking(int roomId, int guestId, string fromDateStr, string toDateStr, bool expected) { var booking = new Booking { RoomId = roomId, GuestId = guestId, FromDate = DateTime.Parse(fromDateStr), ToDate = DateTime.Parse(toDateStr) }; var res = _service.AddBooking(booking).GetAwaiter().GetResult(); Utilities.PrintOut(res); Assert.That(res?.RoomId == roomId, Is.EqualTo(expected)); // False When Add Again res = _service.AddBooking(booking).GetAwaiter().GetResult(); Assert.That(res, Is.Null); }
public void AddBooking_ValidatesRequest() { //arrange var existingPatient = _fixture .Build <Patient>() .With(x => x.ClinicId, 1) .Create(); _context.Patient.Add(existingPatient); _context.SaveChanges(); var request = _fixture.Create <NewBookingRequest>(); request.PatientId = existingPatient.Id; //act _bookingService.AddBooking(request); //assert _validator.Verify(x => x.ValidateRequest(request), Times.Once); }
public async Task ShouldConfirmBookingIfPayedInFull() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); Assert.True(result.Success); Assert.Equal(1, result.Id); Assert.Empty(result.ValidationErrors); booking = await bookingService.GetBooking(result.Id.Value); Assert.False(string.IsNullOrEmpty(booking.ReferenceNumber)); booking.AddPayment(100); booking.AddPayment(200); result = await bookingService.UpdateBooking("tester", booking); Assert.True(result.Success); Assert.Empty(result.ValidationErrors); booking = await bookingService.GetBooking(booking.ReferenceNumber); Assert.Equal(BookingStatus.Confirmed, booking.Status); }
public async Task ShouldNotBeAllowedToUpdateConfirmedBooking() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); Assert.True(result.Success); Assert.Equal(1, result.Id); Assert.Empty(result.ValidationErrors); booking.Id = result.Id.Value; booking.AddPayment(300); result = await bookingService.UpdateBooking("tester", booking); Assert.True(result.Success); Assert.Empty(result.ValidationErrors); booking.StartDateUtc = DateTime.UtcNow.AddDays(1); result = await bookingService.UpdateBooking("tester", booking); Assert.False(result.Success); Assert.NotEmpty(result.ValidationErrors); Assert.Equal("Updating of confirmed or cancelled booking is not allowed", result.ValidationErrors["Booking"]); }
public ActionResult Create(BookingViewModel model) { try { bool result = _bookingService.AddBooking(model); if (result) { return(RedirectToAction(nameof(Index))); } throw new Exception(); } catch { ModelState.AddModelError(string.Empty, "Ooops! Something went wrong!"); return(View()); } }
public void AddBookingTest() { var bookingdata = GenerateTestBookingData().AsQueryable(); var mockSet = GetMockset(bookingdata); var contextOptions = new DbContextOptions <BookingContext>(); var mockContext = new Mock <BookingContext>(contextOptions); mockContext.Setup(c => c.Bookings).Returns(mockSet.Object); var service = new BookingService(mockContext.Object); var custId = new List <int>(); foreach (var book in bookingdata) { if (!custId.Contains(book.Customer.CustomerId)) { custId.Add(book.Customer.CustomerId); } } var id = custId[new Random().Next(custId.Count)]; var cust = new Customer() { CustomerId = 3, CustomerEmail = "*****@*****.**", CustomerName = "TestAdd", CustomerPhone = "04" }; var addbooking = new BookingModel() { BookingId = 4, Customer = cust, TimeOfVisit = DateTime.Now.AddHours(1), EndTime = DateTime.Now.AddHours(2) }; service.AddBooking(addbooking); mockSet.Verify(m => m.Add(It.IsAny <BookingModel>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); var res = service.GetAllBookings(); // Assert.Equal(res, addbooking); }
public async Task ShouldReturnPayments() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var paymentService = new StripePaymentService(dbContext); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); booking.Id = result.Id.Value; booking.AddPayment(100); booking.AddPayment(200); await bookingService.UpdateBooking("tester", booking); var payments = await paymentService.GetPayments(); Assert.NotEmpty(payments); Assert.Equal(2, payments.Count); }
private void btnMakeBooking_Click(object sender, EventArgs e) { try { int bookingId = bookingServiceClient.AddBooking(CreateBooking()); Booking b = bookingServiceClient.GetBooking(bookingId); lstBookingConfirmation.Items.Add(new ListBoxItemObject($"{b.CustomerToBook.FirstName}, {b.CustomerToBook.LastName}, " + $"{b.CarToBook.Brand}, {b.CarToBook.Model}, {b.StartDate}, {b.EndDate}")); } catch (FaultException ex) { MessageBox.Show(ex.Message); } catch (TimeoutException ex) { MessageBox.Show(ex.Message); } catch (EndpointNotFoundException) { MessageBox.Show("Endpoint not found, please check connection."); } }
public ActionResult Add(int courtId, int length, int hour, string name, string notes) { _service.AddBooking(courtId, hour, length, name, notes); return(RedirectToAction("index", "home")); }
public async Task <IActionResult> PostBooking(Models.Bookings.Booking booking) { await _service.AddBooking(booking); return(CreatedAtAction("GetBooking", new { id = booking.Id }, booking)); }