Beispiel #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);
        }
Beispiel #2
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);
        }