Beispiel #1
0
        public void DeleteShouldNotHappenWhenIDNotFound()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            Reservation toDelete = new Reservation
            {
                ID = 2
            };
            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

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

            var result = resRepo.Delete(toDelete);

            Assert.AreEqual(1, resRepo.ReadByHost(hostRepo.ReadByEmail("*****@*****.**")).Count);
            Assert.AreEqual(copy, resRepo.ReadByHost(hostRepo.ReadByEmail("*****@*****.**"))[0]);
            Assert.IsNull(result);
        }
Beispiel #2
0
        public void ShouldNotUpdateWhenIDNotInList()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            Reservation toChange = new Reservation
            {
                StartDate = new DateTime(2022, 02, 03),
                EndDate   = new DateTime(2022, 02, 06),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

            toChange.SetTotal();

            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

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

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

            Assert.IsNull(result);
            Assert.AreEqual(resRepo.ReadByHost(hostRepo.ReadAll()[0])[0], copy);
            Assert.AreEqual(1, resRepo.ReadByHost(hostRepo.ReadAll()[0]).Count);
        }
Beispiel #3
0
        public void UpdateShouldAllowOverlapDatesOnResBeingUpdated()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            ReservationService service = new ReservationService(resRepo, guestRepo, hostRepo);

            Host  host  = hostRepo.ReadAll()[0];
            Guest guest = guestRepo.ReadAll()[0];

            Reservation toUpdate = new Reservation
            {
                StartDate = new DateTime(2022, 1, 2),
                EndDate   = new DateTime(2022, 1, 9),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

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

            var result = service.Update(1, toUpdate);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(toUpdate, result.Value);
            Assert.AreEqual(1, resRepo.ReadByHost(host).Count);
        }
Beispiel #4
0
        public void DeleteShouldDelete()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            Reservation toDelete = new Reservation
            {
                ID = 1
            };
            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

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

            var result = resRepo.Delete(toDelete);

            Assert.AreEqual(0, resRepo.ReadByHost(hostRepo.ReadByEmail("*****@*****.**")).Count);
            Assert.AreEqual(copy, result);
        }
Beispiel #5
0
        public void ShouldUpdateReservation()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            Reservation toChange = new Reservation
            {
                StartDate = new DateTime(2022, 02, 03),
                EndDate   = new DateTime(2022, 02, 06),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0],
                ID        = 1
            };

            Reservation result = resRepo.Update(1, toChange);

            Assert.AreEqual(1, result.ID);
            Assert.AreEqual(toChange.StartDate, result.StartDate);
            Assert.AreEqual(toChange.EndDate, result.EndDate);
            Assert.AreEqual(guestRepo.ReadAll()[0], result.Guest);
            Assert.AreEqual(hostRepo.ReadAll()[0], result.Host);
            Assert.AreEqual(180M, result.Total);
            Assert.AreEqual(1, resRepo.ReadByHost(hostRepo.ReadAll()[0]).Count);
        }
Beispiel #6
0
        public void ShouldAddReservationToList()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            Reservation toAdd = new Reservation {
                StartDate = new DateTime(2022, 02, 02),
                EndDate   = new DateTime(2022, 02, 05),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };


            Reservation result = resRepo.Create(toAdd);


            Assert.AreEqual(2, resRepo.ReadByHost(hostRepo.ReadAll()[0]).Count);
            Assert.AreEqual(result, resRepo.ReadByHost(hostRepo.ReadAll()[0])[1]);
        }
Beispiel #7
0
        public void ShouldReturnNothingWhenNoReservationsForHost()
        {
            IReservationRepository resRepo = new ReservationRepoDouble();
            Host host = new Host
            {
                Email = "*****@*****.**"
            };

            List <Reservation> resResult = resRepo.ReadByHost(host);

            Assert.AreEqual(0, resResult.Count);
        }
Beispiel #8
0
        public void ShouldReturnListsOfDTOs()
        {
            //arrange
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            Host host = new Host
            {
                LastName = "Testy1",
                ID       = "abc-123",
                Email    = "*****@*****.**",
                City     = "Chicago",
                State    = "IL",
            };

            host.SetRates(50M, 80M);

            Guest guest = new Guest {
                LastName  = "Testington",
                FirstName = "Tesla",
                Email     = "*****@*****.**",
                ID        = 1
            };

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

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

            //act
            List <Host>        hostResult  = hostRepo.ReadAll();
            List <Guest>       guestResult = guestRepo.ReadAll();
            List <Reservation> resResult   = resRepo.ReadByHost(hostResult[0]);

            //assert
            //host list has length 1, host in it == the expected one
            Assert.AreEqual(1, hostResult.Count);
            Assert.AreEqual(host, hostResult[0]);
            //guest list has length 1, guest in it == expected one
            Assert.AreEqual(1, guestResult.Count);
            Assert.AreEqual(guest, guestResult[0]);
            //reservation list has length 1, reservation in it == expected one
            Assert.AreEqual(1, resResult.Count);
            Assert.AreEqual(410M, resResult[0].Total);
            Assert.AreEqual(reservation, resResult[0]);
        }