Example #1
0
        public List <Hotel> MapScandicToHotels(string[] lines)
        {
            var hotels = new List <Hotel>();

            if (lines == null)
            {
                return(null);
            }

            foreach (string line in lines)
            {
                var hotelString = line.Split(',');
                var hotel       = new Hotel
                {
                    RegionValue    = Convert.ToInt32(hotelString[0].Trim()),
                    Name           = hotelString[1].Trim(),
                    RoomsAvailable = Convert.ToInt32(hotelString[2].Trim())
                };
                if (HotelValidation.ValidateHotel(hotel))
                {
                    hotels.Add(hotel);
                }
                else
                {
                    throw new FormatException("Error in format.");
                }
            }

            return(hotels);
        }
Example #2
0
        public List <Hotel> MapBestWesternToHotels(List <BestWesternHotel> bestWesternHotels)
        {
            var hotels = new List <Hotel>();

            if (bestWesternHotels == null)
            {
                return(null);
            }

            foreach (var bestWesternHotel in bestWesternHotels)
            {
                var hotel = new Hotel
                {
                    RegionValue    = bestWesternHotel.Reg,
                    Name           = bestWesternHotel.Name,
                    RoomsAvailable = bestWesternHotel.LedigaRum
                };
                if (HotelValidation.ValidateHotel(hotel))
                {
                    hotels.Add(hotel);
                }
                else
                {
                    throw new ArgumentException("Error in format.");
                }
            }

            return(hotels);
        }
        public void TestBadHotelRoomsAvailable()
        {
            var badhotel = new Hotel {
                Name = "hotel", RegionValue = 20, RoomsAvailable = -5
            };

            Assert.AreEqual(false, HotelValidation.ValidateHotel(badhotel));
        }
        public void TestBadHotelRegionValue()
        {
            var hotelWithBadRegion = new Hotel {
                Name = "hotel", RegionValue = -5, RoomsAvailable = 3
            };

            Assert.AreEqual(false, HotelValidation.ValidateHotel(hotelWithBadRegion));
        }
        public void TestBadHotelWithoutNameValidation()
        {
            var badHotel = new Hotel {
                RegionValue = -1, RoomsAvailable = -3
            };

            Assert.AreEqual(false, HotelValidation.ValidateHotel(badHotel));
        }
        public void TestGoodHotelValidation()
        {
            var goodHotel = new Hotel {
                Name = "Blåbär", RegionValue = 20, RoomsAvailable = 500
            };

            Assert.AreEqual(true, HotelValidation.ValidateHotel(goodHotel));
        }