Esempio n. 1
0
        public void CreateThenRemoveFileEntry()
        {
            IReservationRepository reservationRepo = new ReservationFileRepository("test", new NullLogger());
            IHostRepository        hostRepository  = new HostFileRepository("test\\hosts.csv", new NullLogger());
            IGuestRepository       guestRepository = new GuestFileRepository("test\\guests.csv", new NullLogger());

            Host  host  = hostRepository.ReadByEmail("*****@*****.**");
            Guest guest = guestRepository.ReadByEmail("*****@*****.**");

            Reservation toAdd = new Reservation
            {
                StartDate = new DateTime(2022, 2, 1),
                EndDate   = new DateTime(2022, 2, 8),
                Host      = host,
                Guest     = guest
            };

            toAdd.SetTotal();

            var result = reservationRepo.Create(toAdd);

            Assert.AreEqual(2, reservationRepo.ReadByHost(host).Count);
            Assert.AreEqual(2, result.ID);
            Assert.AreEqual(toAdd.StartDate, reservationRepo.ReadByHost(host)[1].StartDate);
            Assert.AreEqual(toAdd.EndDate, reservationRepo.ReadByHost(host)[1].EndDate);
            Assert.AreEqual(toAdd.Guest.ID, reservationRepo.ReadByHost(host)[1].Guest.ID);

            result = reservationRepo.Delete(toAdd);

            Assert.AreEqual(1, reservationRepo.ReadByHost(host).Count);
            Assert.AreEqual(2, result.ID);
        }
Esempio n. 2
0
        public void ReadReservationsShouldReturnAllReservationsForHost()
        {
            IReservationRepository reservationRepo = new ReservationFileRepository("test", new NullLogger());
            IHostRepository        hostRepository  = new HostFileRepository("test\\hosts.csv", new NullLogger());
            IGuestRepository       guestRepository = new GuestFileRepository("test\\guests.csv", new NullLogger());
            Host  host  = hostRepository.ReadByEmail("*****@*****.**");
            Guest guest = guestRepository.ReadByEmail("*****@*****.**");

            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                Guest     = guest
            };

            copy.SetTotal();
            copy.ID = 1;

            List <Reservation> reservations = reservationRepo.ReadByHost(host);

            Assert.AreEqual(1, reservations.Count);
            Assert.AreEqual(410, reservations[0].Total);
            Assert.AreEqual(copy.StartDate, reservations[0].StartDate);
            Assert.AreEqual(copy.EndDate, reservations[0].EndDate);
            Assert.AreEqual(copy.ID, reservations[0].ID);
        }
Esempio n. 3
0
        public void DeleteShouldNotRemoveNonMatchedID()
        {
            IReservationRepository reservationRepo = new ReservationFileRepository("test", new NullLogger());
            IHostRepository        hostRepository  = new HostFileRepository("test\\hosts.csv", new NullLogger());
            IGuestRepository       guestRepository = new GuestFileRepository("test\\guests.csv", new NullLogger());

            Host  host  = hostRepository.ReadByEmail("*****@*****.**");
            Guest guest = guestRepository.ReadByEmail("*****@*****.**");

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                Guest     = guest,
                ID        = 2
            };

            toDelete.SetTotal();

            Reservation result = reservationRepo.Delete(toDelete);

            Assert.AreEqual(1, reservationRepo.ReadByHost(host).Count);
            Assert.IsNull(result);
        }
Esempio n. 4
0
        public void UpdateShouldNotChangeNonMatchedID()
        {
            IReservationRepository reservationRepo = new ReservationFileRepository("test", new NullLogger());
            IHostRepository        hostRepository  = new HostFileRepository("test\\hosts.csv", new NullLogger());
            IGuestRepository       guestRepository = new GuestFileRepository("test\\guests.csv", new NullLogger());

            Host        host     = hostRepository.ReadByEmail("*****@*****.**");
            Guest       guest    = guestRepository.ReadByEmail("*****@*****.**");
            Reservation original = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                Guest     = guest,
                ID        = 1
            };

            original.SetTotal();

            Reservation toChange = new Reservation
            {
                StartDate = new DateTime(2022, 2, 1),
                EndDate   = new DateTime(2022, 2, 8),
                Host      = host,
                Guest     = guest,
                ID        = 2
            };

            toChange.SetTotal();

            Reservation result = reservationRepo.Update(2, toChange);

            Assert.AreEqual(1, reservationRepo.ReadByHost(host).Count);
            Assert.AreEqual(original.EndDate, reservationRepo.ReadByHost(host)[0].EndDate);
            Assert.AreEqual(original.StartDate, reservationRepo.ReadByHost(host)[0].StartDate);
        }
Esempio n. 5
0
        public void ReadReservationShouldReturnEmptyListForNoOrEmptyFile()
        {
            IReservationRepository reservationRepo = new ReservationFileRepository("test", new NullLogger());
            IHostRepository        hostRepository  = new HostFileRepository("test\\hosts.csv", new NullLogger());
            IGuestRepository       guestRepository = new GuestFileRepository("test\\guests.csv", new NullLogger());
            Host host = new Host
            {
                Email        = "*****@*****.**",
                ID           = "2",
                City         = "Chicago",
                State        = "IL",
                LastName     = "Fretty",
                WeekendRate  = 100,
                StandardRate = 40
            };

            Guest guest = guestRepository.ReadByEmail("*****@*****.**");

            List <Reservation> reservations = reservationRepo.ReadByHost(host);

            Assert.AreEqual(0, reservations.Count);
        }