public void AddToBooking_Negative_RoomIdNotThere()
        {
            Book toBeBooked = new Book
            {
                RenterId = 2,
                RoomId   = 3,
                Status   = "alloted"
            };
            Acknowledgement <Book> bookAcknowledgement = new Acknowledgement <Book>();

            bookAcknowledgement.code    = 0;
            bookAcknowledgement.Set     = null;
            bookAcknowledgement.Message = "fail";
            //Arrange
            var _mockDataService = new Mock <BookingService>();

            _mockDataService.Setup(p => p.AddToBooking(toBeBooked)).Throws(new RoomIdNotThere());
            var _bookingManager = new BookingManager(_mockDataService.Object);

            try
            {
                var responseReturned = _bookingManager.AddToBooking(toBeBooked);
                Assert.IsTrue(false);
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }
        public void AddToBooking_Positive()
        {
            Book toBeBooked = new Book
            {
                RenterId = 2,
                RoomId   = 3,
                Status   = "alloted"
            };

            Book Booked = new Book
            {
                BookId   = 1,
                RenterId = 2,
                RoomId   = 3,
                Status   = "alloted"
            };

            List <Book> BookList = new List <Book>();

            BookList.Add(Booked);

            Acknowledgement <Book> bookAcknowledgement = new Acknowledgement <Book>();

            bookAcknowledgement.code    = 1;
            bookAcknowledgement.Set     = BookList;
            bookAcknowledgement.Message = "success";


            //Arrange
            var _mockDataService = new Mock <BookingService>();

            _mockDataService.Setup(p => p.AddToBooking(toBeBooked)).Returns(Booked);
            var _bookingManager = new BookingManager(_mockDataService.Object);

            try
            {
                var responseReturned = _bookingManager.AddToBooking(toBeBooked);
                Assert.IsTrue(false);
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }
        public IActionResult AddToBooking(BookingReceived toBeBookedRecieved)
        {
            Book toBeBooked = new Book();

            toBeBooked.RenterId = toBeBookedRecieved.RenterId;
            toBeBooked.RoomId   = toBeBookedRecieved.RoomId;

            //BookingManager bookingManager = new BookingManager();
            string wrongMessage = "Sorry, something went wrong";
            Acknowledgement <Book> returnData = new Acknowledgement <Book>();

            if (!ModelState.IsValid)
            {
                returnData.code    = 0;
                returnData.Message = "model state invalid";
                return(Ok(returnData));
            }

            try
            {
                returnData = search.AddToBooking(toBeBooked);
            }
            //renterIdNotThereException
            //    roomIdNotThereException

            catch (UserStatusInvalid userStatusInvalidEx)
            {
                returnData.code    = 0;
                returnData.Message = userStatusInvalidEx.Message;
                return(Ok(returnData));
            }
            catch (UserIsNotRenter userIsNotRenterEx)
            {
                returnData.code    = 0;
                returnData.Message = userIsNotRenterEx.Message;
                return(Ok(returnData));
            }
            catch (RoomIdNotThere roomIdNotThereEx)
            {
                returnData.code    = 0;
                returnData.Message = roomIdNotThereEx.Message;
                return(Ok(returnData));
            }
            catch (RenterIdNotThere renterIdNotThereEx)
            {
                returnData.code    = 0;
                returnData.Message = renterIdNotThereEx.Message;
                return(Ok(returnData));
            }
            catch (RoomAlreadyBooked roomAlreadyBookedEx)
            {
                returnData.code    = 0;
                returnData.Message = roomAlreadyBookedEx.Message;
                return(Ok(returnData));
            }
            catch (Exception)
            {
                returnData.code    = 0;
                returnData.Message = wrongMessage;
                return(Ok(returnData));
            }

            return(Ok(returnData));
        }