Esempio n. 1
0
        public void Booking_CalculateCosts_WithValidAmount()
        {
            DateTime arrivalDate   = new DateTime(2017, 1, 18);
            DateTime departureDate = new DateTime(2017, 1, 25);

            Booking testBooking = new Booking(4, arrivalDate, departureDate);

            Guest guest1 = new Guest("Andrea", "ya11121314", 23);
            Guest guest2 = new Guest("Joseph", "ya11121315", 21);
            Guest guest3 = new Guest("Keith", "ya122221315", 22);

            testBooking.addGuest(guest1);
            testBooking.addGuest(guest2);
            testBooking.addGuest(guest3);

            Extra         newExtra1 = new Extra("Breakfast");
            Extra         newExtra2 = new Extra("Car Hire");
            ExtraSelector breakfast = new Breakfast();
            ExtraSelector carHire   = new CarHire();

            breakfast.SetExtra(breakfast);
            breakfast.ProcessExtra(newExtra1);
            breakfast.SetExtra(carHire);
            carHire.ProcessExtra(newExtra2);
            newExtra2.StartHire = new DateTime(2017, 1, 18);
            newExtra2.EndHire   = new DateTime(2017, 1, 20);
            testBooking.addExtra(newExtra1);
            testBooking.addExtra(newExtra2);

            double expectedDayCost   = 200;
            double expectedTotalCost = 1150;
            string expected1         = "The cost per day is:\n - Chalet: " + 60 + "£\n - Number of guests/cost: " + testBooking.GuestDict.Count + " / " + 25 * testBooking.GuestDict.Count
                                       + "£\n - Breakfast: " + 5 * testBooking.GuestDict.Count + "£\n - Evening Meals: " + 0 + "£\n - Car Hire: " + 50 + "£\n Total cost per day: " + expectedDayCost + "£";
            string expected2 = "The total booking cost is: " + expectedTotalCost + "£";

            // act - calling methods
            string method1 = testBooking.getCost();
            string method2 = testBooking.getTotalCost();

            // assert - test correctness
            Assert.AreEqual(expected1, method1, "Cost per day calculation is wrong.");
            Assert.AreEqual(expected2, method2, "Total cost calculation is wrong.");
        }
Esempio n. 2
0
        public void Booking_WithValidProperties()
        {
            // arrange attributes
            int      bookingRefNo    = 1;
            DateTime arrivalDate     = new DateTime(2017, 1, 18);
            DateTime departureDate   = new DateTime(2017, 2, 18);
            int      chaletID        = 1;
            string   bookingToString = "Booking Reference No: " + bookingRefNo.ToString() + " - From " + arrivalDate.ToString() + " to " + departureDate.ToString() + ", Chalet ID: " + chaletID.ToString();

            Guest guest1 = new Guest("Andrea", "ya11121314", 23);
            SortedDictionary <string, Guest> guestDict = new SortedDictionary <string, Guest>();

            guestDict.Add(guest1.PassportNo, guest1);

            SortedDictionary <string, Extra> extraDict = new SortedDictionary <string, Extra>();
            Extra         newExtra  = new Extra("Breakfast");
            ExtraSelector breakfast = new Breakfast();

            breakfast.SetExtra(breakfast);
            breakfast.ProcessExtra(newExtra);
            extraDict.Add(newExtra.Description, newExtra);

            // act - calling methods
            Booking testBooking = new Booking(bookingRefNo, arrivalDate, departureDate);

            testBooking.ArrivalDate   = arrivalDate;
            testBooking.DepartureDate = departureDate;
            testBooking.ChaletID      = chaletID;
            testBooking.addGuest(guest1);
            testBooking.addExtra(newExtra);
            string callToString = testBooking.ToString();

            // assert - test correctness
            Assert.AreEqual(chaletID, testBooking.ChaletID, "ChaletID not set properly.");
            Assert.AreEqual(bookingRefNo, testBooking.BookingRefNo, "Booking Reference Number not set properly.");
            Assert.AreEqual(arrivalDate, testBooking.ArrivalDate, "Arrival Date not set properly.");
            Assert.AreEqual(departureDate, testBooking.DepartureDate, "Departure Date not set properly.");
            CollectionAssert.AreEqual(guestDict, testBooking.GuestDict, "Guests Dictionary not set properly.");
            CollectionAssert.AreEqual(extraDict, testBooking.ExtraDict, "Extras Dictionary not set properly.");
            Assert.AreEqual(bookingToString, callToString, "To string method not set properly.");
        }
Esempio n. 3
0
        // This method is called on SAVE button click. It saves all the information about the booking, any extras, and guest list and updates the binary file. Appropriate
        // checks are done to see if data need to be edited or it is a new booking.
        private void btnSaveBooking_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ExtraSelector extraType   = new NoExtra();
                ExtraSelector breakfast   = new Breakfast();
                ExtraSelector eveningMeal = new EveningMeal();
                ExtraSelector carHire     = new CarHire();

                if (data.CustDict.StoreCustomers[_custID].DictBookings.ContainsKey(_bookingID))
                {
                    if (clrArrival.SelectedDate == null || clrDeparture.SelectedDate == null)
                    {
                        throw new ArgumentException("Please select an Arrival Date and a Departure Date");
                    }

                    data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ArrivalDate   = Convert.ToDateTime(clrArrival.SelectedDate);
                    data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].DepartureDate = Convert.ToDateTime(clrDeparture.SelectedDate);

                    if (data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID == Int32.Parse(tbxChaletID.Text))
                    {
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID = Int32.Parse(tbxChaletID.Text);
                    }

                    if (!data.CustDict.ChaletsBooked.Contains(Int32.Parse(tbxChaletID.Text)))
                    {
                        data.CustDict.ChaletsBooked.Remove(data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID);
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID = Int32.Parse(tbxChaletID.Text);
                        data.CustDict.ChaletsBooked.Add(Int32.Parse(tbxChaletID.Text));
                    }
                    else if (data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID != Int32.Parse(tbxChaletID.Text) && data.CustDict.ChaletsBooked.Contains(Int32.Parse(tbxChaletID.Text)))
                    {
                        throw new ArgumentException("Chalet already booked, please choose another chalet.");
                    }

                    if (ckbBreakfast.IsChecked == false && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Breakfast"))
                    {
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.Remove("Breakfast");
                    }
                    else if (ckbBreakfast.IsChecked == true && !data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Breakfast"))
                    {
                        Extra extra = new Extra("Breakfast");
                        extraType.SetExtra(breakfast);
                        breakfast.ProcessExtra(extra);
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].addExtra(extra);
                    }

                    if (ckbDinner.IsChecked == false && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Evening Meal"))
                    {
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.Remove("Evening Meal");
                    }
                    else if (ckbDinner.IsChecked == true && !data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Evening Meal"))
                    {
                        Extra extra = new Extra("Evening Meal");
                        extraType.SetExtra(eveningMeal);
                        eveningMeal.ProcessExtra(extra);
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].addExtra(extra);
                    }

                    if (ckbCarHire.IsChecked == false && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Car Hire"))
                    {
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.Remove("Car Hire");
                        tbxDriver.Text            = null;
                        clrStartHire.SelectedDate = null;
                        clrEndHire.SelectedDate   = null;
                    }
                    else if (ckbCarHire.IsChecked == true && !data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Car Hire"))
                    {
                        if (clrStartHire.SelectedDate == null || clrEndHire.SelectedDate == null || tbxDriver.Text == null)
                        {
                            throw new ArgumentException("Please select a start hire date, an end hire date, and a driver name.");
                        }

                        if (clrStartHire.SelectedDate < clrArrival.SelectedDate || clrEndHire.SelectedDate > clrDeparture.SelectedDate)
                        {
                            throw new ArgumentException("Invalid hiring dates. Please, insert dates within your booking period of staying.");
                        }

                        Extra extra = new Extra("Car Hire");
                        extraType.SetExtra(carHire);
                        carHire.ProcessExtra(extra);
                        extra.DriverName = tbxDriver.Text;
                        extra.StartHire  = Convert.ToDateTime(clrStartHire.SelectedDate);
                        extra.EndHire    = Convert.ToDateTime(clrEndHire.SelectedDate);
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].addExtra(extra);
                    }
                    else if (ckbCarHire.IsChecked == true && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Car Hire"))
                    {
                        if (clrStartHire.SelectedDate < clrArrival.SelectedDate || clrEndHire.SelectedDate > clrDeparture.SelectedDate)
                        {
                            throw new ArgumentException("Invalid hiring dates. Please, insert dates within your booking period of staying.");
                        }

                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict["Car Hire"].DriverName = tbxDriver.Text;
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict["Car Hire"].EndHire    = Convert.ToDateTime(clrEndHire.SelectedDate);
                        data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict["Car Hire"].StartHire  = Convert.ToDateTime(clrStartHire.SelectedDate);
                    }
                }

                else
                {
                    if (clrArrival.SelectedDate == null || clrDeparture.SelectedDate == null)
                    {
                        throw new ArgumentException("Please selecet an Arrival Date and a Departure Date");
                    }

                    _newBooking = new Business.Booking(_bookingID, Convert.ToDateTime(clrArrival.SelectedDate), Convert.ToDateTime(clrDeparture.SelectedDate));

                    foreach (KeyValuePair <string, Guest> guest in _tempGuestDict)
                    {
                        _newBooking.addGuest(guest.Value);
                    }

                    if (ckbBreakfast.IsChecked == true)
                    {
                        Extra extra = new Extra("Breakfast");
                        extraType.SetExtra(breakfast);
                        breakfast.ProcessExtra(extra);
                        _newBooking.addExtra(extra);
                    }

                    if (ckbDinner.IsChecked == true)
                    {
                        Extra extra = new Extra("Evening Meal");
                        extraType.SetExtra(eveningMeal);
                        eveningMeal.ProcessExtra(extra);
                        _newBooking.addExtra(extra);
                    }

                    if (ckbCarHire.IsChecked == true)
                    {
                        if (clrStartHire.SelectedDate == null || clrEndHire.SelectedDate == null || tbxDriver.Text == null)
                        {
                            throw new ArgumentException("Please select a start hire date, an end hire date, and a driver name.");
                        }

                        Extra extra = new Extra("Car Hire");
                        extraType.SetExtra(carHire);
                        carHire.ProcessExtra(extra);
                        extra.DriverName = tbxDriver.Text;
                        extra.StartHire  = Convert.ToDateTime(clrStartHire.SelectedDate);
                        extra.EndHire    = Convert.ToDateTime(clrEndHire.SelectedDate);
                        _newBooking.addExtra(extra);
                    }

                    data.CustDict.StoreCustomers[_custID].addBooking(_newBooking);

                    if (!data.CustDict.ChaletsBooked.Contains(Int32.Parse(tbxChaletID.Text)))
                    {
                        _newBooking.ChaletID = Int32.Parse(tbxChaletID.Text);
                        data.CustDict.ChaletsBooked.Add(_newBooking.ChaletID);
                    }
                    else
                    {
                        throw new ArgumentException("Chalet already booked, please choose another chalet.");
                    }
                }

                data.updateFile();
            }
            catch (Exception excep)
            {
                MessageBox.Show(excep.Message);
            }
        }