Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        public void ShouldCreateValidReservation(string start, string end)
        {
            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 toAdd = new Reservation
            {
                StartDate = DateTime.Parse(start),
                EndDate   = DateTime.Parse(end),
                Guest     = guest,
                Host      = host
            };

            Result <Reservation> result = service.Create(toAdd);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(2, result.Value.ID);
            Assert.AreEqual(host, result.Value.Host);
            Assert.AreEqual(guest, result.Value.Guest);
            Assert.AreEqual(DateTime.Parse(start), result.Value.StartDate);
            Assert.AreEqual(DateTime.Parse(end), result.Value.EndDate);
        }
Пример #7
0
        public void CreateShouldNotAllowNonListedHost()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

            Host host = new Host
            {
                Email        = "*****@*****.**",
                LastName     = "Duper",
                ID           = "abc-123",
                City         = "Chicago",
                State        = "IL",
                StandardRate = 50M,
                WeekendRate  = 100M
            };

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

            Reservation toAdd = new Reservation
            {
                StartDate = DateTime.Parse("2022,02,02"),
                EndDate   = DateTime.Parse("2022,02,06"),
                Guest     = guest,
                Host      = host
            };

            Result <Reservation> result = service.Create(toAdd);

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.Messages[0].Contains("host"));
            Assert.IsNull(result.Value);
        }
Пример #8
0
        public void DeleteShouldNotRunWithNullHost()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

            Host host = null;

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                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 = service.Delete(toDelete);

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("Host"));
        }
Пример #9
0
        public void DeleteShouldDelete()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

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

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                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 = service.Delete(toDelete);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(0, service.ViewByHost(host).Value.Count);
            Assert.AreEqual(copy, result.Value);
        }
Пример #10
0
        public void AddShouldNotAllowNullHost()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

            Host host = null;

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

            Reservation toAdd = new Reservation
            {
                StartDate = DateTime.Parse("2022,02,02"),
                EndDate   = DateTime.Parse("2022,02,06"),
                Guest     = guest,
                Host      = host
            };

            Result <Reservation> result = service.Create(toAdd);

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.Messages[0].Contains("host"));
            Assert.IsNull(result.Value);
        }
Пример #11
0
        public void ShouldReturnGuestWithEmail()
        {
            IGuestRepository guestRepository = new GuestRepoDouble();
            var guestList = guestRepository.ReadAll();

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

            Assert.AreEqual(guest, guestList[0]);
        }
Пример #12
0
        public void UpdateShouldNotUpdateInvalidID(int id)
        {
            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(2021, 12, 28),
                EndDate   = new DateTime(2021, 12, 29),
                Guest     = guest,
                Host      = host,
                ID        = id
            };

            toUpdate.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;


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

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("ID"));
            Assert.AreEqual(copy, service.ViewByHost(hostRepo.ReadAll()[0]).Value[0]);
            Assert.AreEqual(1, service.ViewByHost(hostRepo.ReadAll()[0]).Value.Count);
        }
Пример #13
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]);
        }
Пример #14
0
        public void UpdateShouldNotAllowNullHost()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

            Host host = null;

            Reservation toChange = new Reservation
            {
                StartDate = new DateTime(2022, 02, 03),
                EndDate   = new DateTime(2022, 02, 06),
                Host      = host,
                Guest     = guestRepo.ReadAll()[0],
                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;

            Result <Reservation> result = service.Update(1, toChange);

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.Messages[0].Contains("host"));
            Assert.IsNull(result.Value);
            Assert.AreEqual(copy, service.ViewByHost(hostRepo.ReadAll()[0]).Value[0]);
            Assert.AreEqual(1, service.ViewByHost(hostRepo.ReadAll()[0]).Value.Count);
        }
Пример #15
0
        public static void CreateShouldNotAllowNullReservation()
        {
            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 toAdd = null;

            Result <Reservation> result = service.Create(toAdd);

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.Messages[0].Contains("reservation"));
            Assert.IsNull(result.Value);
        }
Пример #16
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]);
        }
Пример #17
0
        public void UpdateShouldNotAllowInvalidDates(string newStart, string newEnd)
        {
            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 toAdd = new Reservation
            {
                StartDate = new DateTime(2021, 12, 28),
                EndDate   = new DateTime(2021, 12, 29),
                Guest     = guest,
                Host      = host
            };

            toAdd.SetTotal();

            Reservation toUpdate = new Reservation
            {
                StartDate = DateTime.Parse(newStart),
                EndDate   = DateTime.Parse(newEnd),
                Host      = host,
                Guest     = guest,
                ID        = 2
            };

            var adddingResult = service.Create(toAdd);

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

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.Messages[0].Contains("date"));
            Assert.IsNull(result.Value);
            Assert.AreEqual(adddingResult.Value, service.ViewByHost(hostRepo.ReadAll()[0]).Value[0]);
            Assert.AreEqual(2, service.ViewByHost(hostRepo.ReadAll()[0]).Value.Count);
        }
Пример #18
0
        public void DeleteShouldNotRunForNotFoundID()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

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

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                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 = service.Delete(toDelete);

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("ID"));
            Assert.AreEqual(1, service.ViewByHost(host).Value.Count);
            Assert.AreEqual(copy, service.ViewByHost(host).Value[0]);
        }
Пример #19
0
        public void UpdateShouldSucceed()
        {
            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 copy  = new Reservation
            {
                StartDate = new DateTime(2021, 12, 28),
                EndDate   = new DateTime(2021, 12, 29),
                Guest     = guest,
                Host      = host
            };

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

            Reservation toUpdate = new Reservation
            {
                StartDate = new DateTime(2021, 12, 28),
                EndDate   = new DateTime(2021, 12, 29),
                Host      = host,
                Guest     = guest,
                ID        = 1
            };

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

            Assert.IsTrue(result.Success);
            Assert.AreEqual(copy, result.Value);
            Assert.AreEqual(copy, service.ViewByHost(host).Value[0]);
            Assert.AreEqual(1, service.ViewByHost(host).Value.Count);
        }
Пример #20
0
        public void CreateShouldNotAllowInvalidReservationDates(string start, string end)
        {
            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 toAdd = new Reservation
            {
                StartDate = DateTime.Parse(start),
                EndDate   = DateTime.Parse(end),
                Guest     = guest,
                Host      = host
            };

            Result <Reservation> result = service.Create(toAdd);

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("date"));
        }