private string ExpectedResult() { using StreamReader r = new StreamReader("Data/ticketResult.json"); string json = r.ReadToEnd(); var expectedResponse = new List <TicketSearchEntity>(); var ticket = JsonConvert.DeserializeObject <Ticket>(json); var ticketEntity = new TicketSearchEntity() { Ticket = ticket, OrganizationName = "Zentry" }; expectedResponse.Add(ticketEntity); return(JsonConvert.SerializeObject(expectedResponse)); }
public List <TicketSearchEntity> GetTicketDetails(string key, string value) { var ticketDetails = new List <TicketSearchEntity>(); var titleCaseKey = TitleCaseString.ToTitleCase(key); using StreamReader r = new StreamReader(_filePath); string json = r.ReadToEnd(); var allTickets = JsonConvert.DeserializeObject <List <Ticket> >(json); foreach (var ticket in allTickets) { var mapTicket = new TicketSearchEntity(); if (ticket.GetType().GetTypeInfo().GetDeclaredProperty(titleCaseKey) != null) { if (ticket.GetType().GetProperty(titleCaseKey).GetValue(ticket)?.ToString() == value) { if (ticket?.Organization_Id != 0) { var orgDetails = _getOrg.GetOrganizationDetails("Id", ticket.Organization_Id.ToString()); mapTicket.Ticket = ticket; mapTicket.OrganizationName = orgDetails?.FirstOrDefault(r => r.Id == ticket?.Organization_Id).Name; } ticketDetails.Add(mapTicket); } } else { Console.WriteLine("Please enter a valid search term for Tickets"); _logger.LogInformation($"Invalid search term {key}"); ticketDetails = null; break; } } return(ticketDetails); }