Пример #1
0
        /// <summary>
        /// Sets up a sample ticketed event and prints it to the console.
        /// </summary>
        public static void TestSetupTicketService()
        {
            Console.WriteLine("Creating a ticketed event");
            ticketedEvent = new TicketedEvent("Amazing-Concert-@-The-Showbox", new DateTime(2019, 9, 5, 4, 0, 0), 10, 15);
            Console.WriteLine('\n' + ticketedEvent.ToString() + '\n');
            Assert.AreEqual(ticketedEvent.NumberOfAvailableSeats, 150);
            Assert.AreEqual(ticketedEvent.NumberOfSeats, 150);
            Assert.AreEqual(ticketedEvent.NumberOfRows, 10);
            Assert.AreEqual(ticketedEvent.NumberOfColumns, 15);
            Assert.AreEqual(ticketedEvent.Name, "Amazing-Concert-@-The-Showbox");
            Assert.AreEqual(ticketedEvent.Time, new DateTime(2019, 9, 5, 4, 0, 0));
            Assert.AreEqual(ticketedEvent.Seats.Count, 150);
            Assert.IsNotNull(ticketedEvent.SeatHolds);
            Assert.IsNotNull(ticketedEvent.Reservations);
            Assert.AreEqual(ticketedEvent.SeatHoldsCreated, 0);

            Console.WriteLine("Ticketed Event successfully created.");

            Console.WriteLine("Binding Ticketed event to Controller");
            DataController.Instance.LoadTicketedEvent(ticketedEvent);
            Assert.IsTrue(DataController.Instance.Initialized());

            Console.WriteLine("Ticketed Event bound to data controller");

            Console.WriteLine("Creating Ticket Service.");
            ticketService = new MyTicketService();

            Console.WriteLine("Binding ticket service to ticketed event");
            ticketService.BindTicketServiceToEvent(ticketedEvent.Name);

            Console.WriteLine("Test no rebind of ticket service.");
            try
            {
                ticketService.BindTicketServiceToEvent("random-other-event");
                Assert.Fail("Ticket service was rebound, should not happen");
            }
            catch (InvalidOperationException e)
            {
                Assert.IsTrue(e.Message.Contains("The ticket service is already bound to an event"));
            }

            Console.WriteLine("Ticket Service Successfully setup.");
        }
Пример #2
0
        /// <summary>
        /// Runs unit tests
        /// </summary>
        public static void RunTests( )
        {
            Console.WriteLine("===================== RUNNING UNIT TESTS =============================");
            ticketService = null;
            DataController.Instance.LoadTicketedEvent(null);
            ticketedEvent = null;

            TestSetupTicketService();
            TestNumSeatsAvailable();
            TestFindAndHoldSeats();
            TestReserveSeats();

            ticketService = null;
            DataController.Instance.LoadTicketedEvent(null);
            ticketedEvent = null;

            Console.WriteLine("===================== UNIT TESTS PASSED! =============================");

            Console.WriteLine("Running tests resets the ticket service. Use ts create to create another ticket service");
        }
Пример #3
0
        /// <summary>
        /// Creates the ticket service
        /// </summary>
        /// <param name="ticketedEventName">the name of the ticketed event</param>
        /// <param name="year">year of the event</param>
        /// <param name="month">month of the event</param>
        /// <param name="day">day of the event</param>
        /// <param name="hour">hour of the event</param>
        /// <param name="min">minute of the event</param>
        /// <param name="rows">rows of seats at the event</param>
        /// <param name="cols">columns of seats at the event</param>
        public static void CreateTicketService(string ticketedEventName = "Ultimate-Code-Warrior-LIVE-@-Showbox", int year = 2019, int month = 9, int day = 17, int hour = 6, int min = 30, int rows = 20, int cols = 15)
        {
            if (ticketService != null)
            {
                Console.WriteLine("Ticket service already exists. Did you want to replace it with a fresh one? (Y/N) \n");

                string answer = Console.ReadLine();

                switch (answer.ToLower())
                {
                case "y":
                    ticketService = new MyTicketService();
                    Console.WriteLine("Created new ticket service");
                    break;

                case "n":
                    Console.WriteLine("Ticket service was not created.\n");
                    return;

                default:
                    Console.WriteLine("Invalid response (Y/N). Ticket service was not created.\n");
                    break;
                }
            }
            else
            {
                ticketService = new MyTicketService();
            }

            Console.WriteLine("Creating new Ticketed Event");
            DataController.Instance.LoadTicketedEvent(new TicketedEvent(ticketedEventName, new DateTime(year, month, day, hour, min, 0), rows, cols));
            ticketService.BindTicketServiceToEvent(ticketedEventName);
            Console.WriteLine("Ticketed Event created:\n");
            DataController.Instance.PrintTicketedEventStatus(ticketedEventName);
            Console.WriteLine("Binding Ticket Service to ticketed event");
            Console.WriteLine("Ticket Service binded to Ticketed Event. Ready for Service.\n");
        }