public void CreateBookingTest_ThrowsArgumentException(int Id, DateTime StartDate, DateTime EndDate, bool IsActive, int CustomerId, int RoomId, Customer Customer, Room Room)
        {
            var book = new Booking {
                Id = Id, StartDate = StartDate, EndDate = EndDate, IsActive = IsActive, CustomerId = CustomerId, RoomId = RoomId, Customer = Customer, Room = Room
            };
            Exception ex = Assert.Throws <ArgumentException>(() => bookingManager.CreateBooking(book));

            Assert.Equal(String.Format("The start date cannot be in the past or later than the end date."), ex.Message);
        }
        public void CreateBooking_StartDateNotInFuture_ThrowException()
        {
            var booking = new Booking
            {
                Id         = 1,
                StartDate  = DateTime.Today.AddDays(-1),
                EndDate    = DateTime.Today.AddDays(5),
                CustomerId = 1,
                IsActive   = false
            };

            Assert.Throws <ArgumentException>(() => bm.CreateBooking(booking));
        }
        public void CreateBooking_IsPossibleMoq_Succeed(DateTime start, DateTime end, int roomID, int customerId, bool expectedResult)
        {
            //ARRANGE
            Booking booking = new Booking()
            {
                CustomerId = customerId, StartDate = start, EndDate = end, RoomId = roomID, Id = 2
            };

            //ACT
            var result = fakeBookingManager.CreateBooking(booking);

            Assert.Equal(expectedResult, result);
        }
 public ActionResult Create(BookingViewModel booking)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string add = _bookingManager.CreateBooking(booking);
             if (add == "Exist")
             {
                 ViewBag.VehicleId = new SelectList(_vehicleManager.GetAllVehicle(), "VehicleId", "LicencePlate");
                 ViewBag.ServiceId = new SelectList(_serviceManager.GetAllService(), "ServiceId", "ServiceName");
                 ModelState.AddModelError("", "Booking already register");
                 return(View(booking));
             }
             else
             {
                 return(RedirectToAction("Index"));
             }
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     ViewBag.VehicleId = new SelectList(_vehicleManager.GetAllVehicle(), "VehicleId", "LicencePlate");
     ViewBag.ServiceId = new SelectList(_serviceManager.GetAllService(), "ServiceId", "ServiceName");
     return(View(booking));
 }
 public void CreateBooking_newEmptyBooking_thowsExeption()
 {
     // Arrange
     // Act
     // Assert
     Assert.ThrowsAny <Exception>(() => bookingManager.CreateBooking(new Booking()));
 }
        public void CreateBooking_NoRoomsAvailable_ReturnFalse()
        {
            // Arrange
            var booking = new Booking
            {
                Id        = 1, CustomerId = 1, RoomId = 1, IsActive = true,
                StartDate = firstInMonth1,
                EndDate   = firstInMonth2
            };

            // Act
            var created = bookingManager.CreateBooking(booking);

            // Assert
            Assert.False(created);
        }
예제 #7
0
        public void WhenTheBookingIsCreated()
        {
            Booking booking = new Booking()
            {
                CustomerId = customerId, StartDate = start, EndDate = end, RoomId = roomID, Id = id
            };

            result = bookingManager_mock.CreateBooking(booking);
        }
        public void WhenCreatingABooking()
        {
            Booking booking = new Booking()
            {
                CustomerId = customerId, StartDate = start, EndDate = end, RoomId = roomID, Id = id
            };

            result = fakeBookingManager.CreateBooking(booking);
        }
        public void CreateBook_StartAndEndDateAreAvailable_ExpectTrue(DateTime startDate, DateTime endDate, bool expected)
        {
            Booking bking = new Booking();

            bking.StartDate = startDate;
            bking.EndDate   = endDate;
            var result = bookingManager.CreateBooking(bking);

            Assert.Equal(expected, result);
        }
        public void CreateBookingTest1Case1()
        {
            var b = new Booking()
            {
                StartDate = DateTime.Today.AddDays(-1)
            };

            Assert.Throws <ArgumentException>(() => bookingManager.CreateBooking(b));
        }
예제 #11
0
        public void ThenTheResultShouldBe(string p0)
        {
            var booking = new Booking()
            {
                StartDate = Start,
                EndDate   = End
            };

            var result = bookingManager.CreateBooking(booking);

            Assert.Equal(result, bool.Parse(p0));
        }
        public ActionResult Index(BookingViewModel booking)
        {
            try
            {
                booking.CustomerId = (int)Session["Id"];
                if (ModelState.IsValid)
                {
                    if (booking.StartBookingDate < DateTime.Now)
                    {
                        throw new Exception("Start Booking date must be greater than today's date");
                    }
                    if (booking.StartBookingDate > booking.EndBookingDate)
                    {
                        throw new Exception("End Booking date must be greater than start booking date");
                    }
                    string add = _bookingManager.CreateBooking(booking);
                    if (add == "Exist")
                    {
                        int custId = (int)Session["Id"];
                        ViewBag.VehicleId = new SelectList(_vehicleManager.GetAllVehicleByCustomer(custId), "VehicleId", "LicencePlate");
                        ViewBag.ServiceId = new SelectList(_serviceManager.GetAllService(), "ServiceId", "ServiceName");
                        ModelState.AddModelError("", "Booking already register");
                        var Bookings = new BookingViewModel()
                        {
                            bookinglist = _bookingManager.GetAllBooking()
                        };
                        return(View(Bookings));
                    }
                    else
                    {
                        Log.Info("Booking added Successffuly");
                        return(RedirectToAction("Index"));
                    }
                }
            }
            // Catch the exception
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                ModelState.AddModelError("", "Error in booking uploading");
            }
            int custiId = (int)Session["Id"];

            ViewBag.VehicleId = new SelectList(_vehicleManager.GetAllVehicleByCustomer(custiId), "VehicleId", "LicencePlate");
            ViewBag.ServiceId = new SelectList(_serviceManager.GetAllService(), "ServiceId", "ServiceName");
            var bookings = new BookingViewModel()
            {
                bookinglist = _bookingManager.GetAllBooking()
            };

            return(View(bookings));
        }
        public IActionResult Create([Bind("StartDate,EndDate,CustomerId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                bookingManager.CreateBooking(booking);

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["CustomerId"] = new SelectList(customerManager.GetAllCustomers(), "Id", "Name", booking.CustomerId);
            ViewBag.Status         = "The booking could not be created. There were no available room.";
            return(View(booking));
        }
예제 #14
0
        public void TestCreateBooking_ReturnTrue()
        {
            // Arrange
            Booking booking = new Booking();

            booking.StartDate = DateTime.Today.AddDays(1);
            booking.EndDate   = DateTime.Today.AddDays(2);
            // Act
            bool booked = bookingManager.CreateBooking(booking);

            // Assert
            Assert.True(booked);
        }
예제 #15
0
        public ActionResult Create([Bind(Include = "StartDate,EndDate,CustomerId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                Booking newBooking = bookingMan.CreateBooking(booking);
                if (newBooking != null)
                {
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.CustomerId = new SelectList(customerRep.GetAll(), "Id", "Name", booking.CustomerId);
            return(View(booking));
        }
예제 #16
0
        public CreateBookingFakeResources()
        {
            var rooms = new List <Room>
            {
                new Room {
                    Id = 1, Description = "A"
                },
                new Room {
                    Id = 2, Description = "B"
                },
            };
            var customers = new List <Customer>
            {
                new Customer {
                    Id = 1, Email = "*****@*****.**", Name = "Joe"
                },
                new Customer {
                    Id = 2, Email = "*****@*****.**", Name = "Billy"
                },
            };


            DateTime start = DateTime.Today.AddDays(10);
            DateTime end   = DateTime.Today.AddDays(20);

            List <Booking> bookings = new List <Booking>
            {
                new Booking {
                    Id = 1, StartDate = start, EndDate = end, IsActive = true, CustomerId = 1, RoomId = 1, Customer = customers[0], Room = rooms[0]
                },
                new Booking {
                    Id = 2, StartDate = start, EndDate = end, IsActive = true, CustomerId = 2, RoomId = 2, Customer = customers[1], Room = rooms[1]
                }
            };

            fakeBookingRepository = new Mock <IRepository <Booking> >();
            fakeRoomRepository    = new Mock <IRepository <Room> >();

            fakeBookingRepository.Setup(x => x.GetAll()).Returns(bookings);
            fakeRoomRepository.Setup(x => x.GetAll()).Returns(rooms);

            fakeBookingRepository.Setup(x => x.Get(It.Is <int>(id => id > 0 && id < 3))).Returns(bookings[1]);
            fakeRoomRepository.Setup(x => x.Get(It.Is <int>(id => id > 0 && id < 3))).Returns(rooms[1]);

            bookingManager = new BookingManager(fakeBookingRepository.Object, fakeRoomRepository.Object);

            bookingManager.CreateBooking(bookings[0]);
        }
        public void WhenIPressButtonCreateBooking()
        {
            var booking = new Booking
            {
                CustomerId = customerId,
                StartDate  = startDate,
                EndDate    = endDate
            };

            try
            {
                bookingResult = bookingManager.CreateBooking(booking);
            } catch (ArgumentException e)
            {
                bookingResult = false;
            }
        }
        public IActionResult Post([FromBody] Booking booking)
        {
            if (booking == null)
            {
                return(BadRequest());
            }

            bool created = bookingManager.CreateBooking(booking);

            if (created)
            {
                return(CreatedAtRoute("GetBookings", null));
            }
            else
            {
                return(Conflict("The booking could not be created. All rooms are occupied. Please try another period."));
            }
        }
예제 #19
0
        public void WhenIPressTheCreateBookingButton()
        {
            var booking = new Booking
            {
                CustomerId = _customerId,
                StartDate  = _startDate,
                EndDate    = _endDate
            };

            try
            {
                _resultOfBooking = _bookingManager.CreateBooking(booking);
            }
            catch
            {
                _resultOfBooking = false;
            }
        }
예제 #20
0
        public void CreateBooking_BookingNull_ThrowsArgumentException()
        {
            Booking b = null;

            Assert.Throws <ArgumentException>(() => bookingManager.CreateBooking(b));
        }
예제 #21
0
        // POST: api/Booking
        public IHttpActionResult Post([FromBody] Booking booking)
        {
            var response = _bookingManager.CreateBooking(booking);

            return(Ok(response));
        }
예제 #22
0
 public void CreateBooking_AvailableRoom_ReturnsTrue(Booking booking)
 {
     Assert.True(bookingManager.CreateBooking(booking));
 }
예제 #23
0
 public void WhenIPressBook()
 {
     result = bookingManager.CreateBooking(booking);
 }
예제 #24
0
 public IHttpActionResult PostMakeBooking([FromBody] Booking model)
 {
     return(Ok(_bookingManager.CreateBooking(model)));
 }