Exemple #1
0
        //Function which will load the tickets from a server and save them in appropriate lists.
        private void loadAllTickets(string url)
        {
            RootTicket rt           = new RootTicket();;
            string     valueFromAPI = "";

            //Try create a web request, if it fails throw an error
            try
            {
                //Get the string represenation of response
                valueFromAPI = APIController.callWebRequest(url);
                //COnvert the string to an object
                rt = TicketResultController.convertStringToObject(valueFromAPI);
                //Add the new ticket to the correct Lists
                TicketResultController.addToTemp(rt);
                TicketResultController.moveTempRootTickets();
                TicketResultController.clearTempRootTicket();
                TicketResultController.populateTicketFromRootTicket();
                TicketResultController.moveTempTickets();
                TicketResultController.clearTempTicket();
                //Add the list of tickets as the data source for the grid view.
                ticketGridView.DataSource = TicketResults.listOfTickets;
                //Have the list display 25 tickets on one page.
                ticketGridView.PageSize = 25;
                //Create two event handlers for when then page is changed and when a ticket is selected
                ticketGridView.PageIndexChanging    += handlePageIndexing;
                ticketGridView.SelectedIndexChanged += showTicket;
                //FInally bind all the data to the grid view
                ticketGridView.DataBind();
            }
            catch (WebException we)
            {
                errorMessageLabel.Text = we.Message;
            }
            catch (Exception ex)
            {
                errorMessageLabel.Text = ex.Message;
            }
            //If there is a second page, (Zendesk API only returns a max of 100 per response) call the function again and repeat the process
            if (rt.next_page != null)
            {
                loadAllTickets(rt.next_page);
            }
        }
        public void TestPopulateTicketsFromRootTickets()
        {
            Assert.IsTrue(TicketResults.tempListOfTikets.Count == 0, "The count was not zero");
            //Setting up Tickets and lists.
            RootTicket rt     = new RootTicket();
            Tickets    ticket = new Tickets();

            ticket.id      = 1;
            ticket.subject = "Test SUbject";
            List <Tickets> list = new List <Tickets>();

            list.Add(ticket);
            rt.tickets = list;
            List <RootTicket> rtList = new List <RootTicket>();

            rtList.Add(rt);
            TicketResults.tempRootTickets = rtList;
            //Run function
            TicketResultController.populateTicketFromRootTicket();
            Assert.IsTrue(TicketResults.tempListOfTikets.Count > 0, "The count was not zero after function");
        }