Esempio n. 1
0
        public void ShouldNotFindGuestWithNoMatchingEmail()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

            var result = service.FindGuestByEmail("*****@*****.**");

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("guest"));
        }
Esempio n. 2
0
        public void ShouldFindGuestWithEmail()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

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

            Guest guest = new Guest
            {
                LastName  = "Testington",
                FirstName = "Tesla",
                Email     = "*****@*****.**",
                ID        = 1
            };
            var result = service.FindGuestByEmail("*****@*****.**");

            Assert.IsTrue(result.Success);
            Assert.AreEqual(guest, result.Value);
        }
        private void Add()
        {
            ConsoleIO.DisplayLine("*** Add Reservation ***");

            //get the host list and resrvations
            Result <List <Reservation> > reservationsResult = GetReservations();

            ConsoleIO.DisplayStatus(reservationsResult.Success, reservationsResult.Messages);

            if (reservationsResult.Success)
            {
                ConsoleIO.DisplayReservationList(reservationsResult.Value);
            }
            else
            {
                return;
            }

            //instantiate a host
            Host host = reservationsResult.Value.FirstOrDefault().Host;

            //get guest & instantiate
            string         guestEmail  = ConsoleIO.PromptString("Enter guest email", false);
            Result <Guest> guestResult = reservationService.FindGuestByEmail(guestEmail);


            if (!guestResult.Success)
            {
                ConsoleIO.DisplayStatus(guestResult.Success, guestResult.Messages);
                return;
            }
            else
            {
                ConsoleIO.DisplayLine("Guest found");
                ConsoleIO.DisplayLine("");
            }
            Guest guest = guestResult.Value;

            //get start date (required)
            DateTime startDate = ConsoleIO.PromptDateTime("Reservation start date", false);
            //get end date (required)
            DateTime endDate = ConsoleIO.PromptDateTime("Reservation end date", false);

            //perform Create and display result
            Reservation toAdd = new Reservation
            {
                StartDate = startDate,
                EndDate   = endDate,
                Guest     = guest,
                Host      = host
            };

            toAdd.SetTotal();

            ConsoleIO.DisplayReservationSummary(toAdd);
            if (!ConsoleIO.PromptYesNo())
            {
                ConsoleIO.DisplayLine("Reservation was not added");
                return;
            }

            Result <Reservation> createResult = reservationService.Create(toAdd);

            ConsoleIO.DisplayStatus(createResult.Success, createResult.Messages);

            if (createResult.Success)
            {
                ConsoleIO.DisplayLine($"Reservation with ID {createResult.Value.ID} created");
            }
        }