Exemple #1
0
        public IHttpActionResult GetBooking(int bookingid)
        {
            //check the validity of the input
            if (ModelState.IsValid)
            {
                try
                {
                    Booking booking = bs.GetBookingById(bookingid);
                    if (booking == null)
                    {
                        return(NotFound());
                    }
                    return(Ok(booking));
                }
                catch (BookingsException)
                {
                    throw;
                }
            }

            else
            {
                //throw user defined exception object
                throw new BookingsException("The entered details are not valid");
            }
        }
        public void GetBookingById_ThrowsEntityNotFound_WhenBookingDoesNotExist()
        {
            var nonExistingId  = Guid.NewGuid();
            var bookingService = new BookingsService(bookingRepoMock.Object);

            Assert.ThrowsException <EntityNotFoundException>(() =>
            {
                bookingService.GetBookingById(nonExistingId.ToString());
            });
        }
        public void GetBookingById_ThrowsException_WhenBookingIdHasInvalidValue()
        {
            var bookingService = new BookingsService(bookingRepoMock.Object);

            var badId = "asdjlkasdklas sakld askld";

            Assert.ThrowsException <Exception>(() =>
            {
                bookingService.GetBookingById(badId);
            });
        }
        public void GetBookingById_Returns_BookingWhenExists()
        {
            Exception throwException = null;
            var       bookingService = new BookingsService(bookingRepoMock.Object);
            Booking   booking        = null;

            try
            {
                booking = bookingService.GetBookingById(existingBookingId.ToString());
            }
            catch (Exception e)
            {
                throwException = e;
            }

            Assert.IsNull(throwException, $"Exception was thrown");
            Assert.IsNotNull(booking);
        }