Beispiel #1
0
 public static void AddBooking(Booking booking)
 {
     if (!IsBooked(booking)){
         _bookings.Add(booking);
     }
     else{
         throw new InvalidOperationException("Booking already exists!");
     }
 }
Beispiel #2
0
        public static Booking Create(DateTime start, int duration, RoomType type)
        {
            DateTime end = start.AddDays(duration);
            IEnumerable<Room> eligableRooms = from room in Room.Rooms where room.Type.Equals(type) select room;

            foreach (Room eligableRoom in eligableRooms){
                Booking preliminaryBooking = new Booking(start, end, null, eligableRoom);
                if (!IsBooked(preliminaryBooking)){
                    return preliminaryBooking;
                }
            }
            throw new OutOfRoomException("No more rooms!");
        }
Beispiel #3
0
        public void TestBookingCollisions()
        {
            CardDetails details = new CardDetails("01912664311", "10/11", "10/13");
            Customer customer = new Customer("Customer", "*****@*****.**", details);
            Room room = Room.Get(1);

            Booking booking1 = new Booking(new DateTime(2012, 4, 1), new DateTime(2012, 4, 5), customer, room);
            Booking bookingConflict = new Booking(new DateTime(2012, 4, 3), new DateTime(2012, 4, 6), customer, room);
            Booking bookingNoConflict = new Booking(new DateTime(2012, 4, 9), new DateTime(2012, 4, 12), customer, room);
            Booking bookingDifferentRoom = new Booking(new DateTime(2012, 4, 3), new DateTime(2012, 4, 6), customer,
                                                       Room.Get(2));
            Booking bookingDifferentRoomNoConflict = new Booking(new DateTime(2012, 4, 12), new DateTime(2012, 4, 19),
                                                                 customer, Room.Get(2));

            Assert.IsTrue(booking1.Contains(bookingConflict));
            Assert.IsTrue(bookingConflict.Contains(booking1));
            Assert.IsFalse(booking1.Contains(bookingNoConflict));
            Assert.IsFalse(booking1.Contains(bookingDifferentRoom));
            Assert.IsFalse(booking1.Contains(bookingDifferentRoomNoConflict));
        }
Beispiel #4
0
        public void TestBookingCreation()
        {
            CardDetails details = new CardDetails("01912664311", "10/11", "10/13");
            Customer customer = new Customer("Customer", "*****@*****.**", details);
            Room room = Room.Get(1);
            DateTime start = new DateTime(2012, 4, 1);
            DateTime end = new DateTime(2012, 4, 5);
            Booking booking = new Booking(start, end, customer, room);

            Assert.AreEqual(string.Format("Room {0} for {1} from {2} to {3}", room.Number, customer, start.ToShortDateString(),
                                 end.ToShortDateString()), booking.ToString());
        }
Beispiel #5
0
 public bool Contains(Booking other)
 {
     if (other.Room != Room){
         return false;
     }
     return other.StartDate >= StartDate && other.StartDate <= EndDate ||
         other.EndDate >= StartDate && other.EndDate <= EndDate;
 }
Beispiel #6
0
 public static bool IsBooked(Booking booking)
 {
     return _bookings.Any(existingBooking => existingBooking.Contains(booking));
 }