/// <summary> /// Post method for the inquirer to close the case. /// This should be called once the inquirer has accepted all the answers from the involved organizations. /// </summary> private async Task <bool> PostInquirerCaseClosing(string caseNumber, CloseCase closingComments = null) { bool result; // Create a client and connect to LK instance using (var client = new HttpClient()) { // Configure request client.Timeout = TimeSpan.FromSeconds(3000); client.BaseAddress = new Uri(GlobalSettings.Path); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Add("X-Auth-Token", _context.Token); // check parsing of json, might fail on null. var jsonString = JsonUtils <CloseCase> .Serialize(closingComments); var stringContent = new StringContent(jsonString); stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // HTTP POST var response = await client.PostAsync(string.Format("inquirercase/{0}/close", caseNumber), stringContent); result = response.IsSuccessStatusCode; } return(result); }
public IHttpActionResult Post(CloseCase baseRequest) { var response = service.SaveCloseCase(baseRequest); return(Ok(response)); }
public void PostInquirerCaseClose() { // Make sure we're fetching a cable inquiry var openCase = GetMyOrganizationsInquiries(StatusType.Open).Result.Last(); // Check if case is eligible to be closed due to passing the thirty day limit. var eligibleCase = (Convert.ToDateTime(openCase.Created) - DateTime.Now).TotalDays < 30; // Not sure if we should split these, so that we can have a backup case? // Or what we should do in case we cant find an eligible case? Assert.IsTrue(eligibleCase, "Cant find a case eligible for closing with comments (Less than 30 days old)"); // Get the first recipient from either interested or involved. var recipient = openCase.InvolvedRecipients.FirstOrDefault() ?? openCase.InterestedRecipients.FirstOrDefault(); // Generate some comments! var listOfClosedCaseComments = GetClosingCase(recipient, Constants.CLOSING_CASE_COMMENT); var closedOrCanceledCases = GetMyInquiries(StatusType.Canceled).Result; var canceledCase = closedOrCanceledCases.FirstOrDefault(); //Try to close closed or canceled case if (canceledCase != null) { // Need to get separate comments for the recipient of the canceled case. var listOfCanceledCaseComments = new CloseCase { ClosingComments = new[] { new ClosingCaseCommentToRecipient() } }; var task = PostInquirerCaseClosing(canceledCase.Id, listOfCanceledCaseComments); Assert.IsNotNull(task); Assert.IsNotNull(task.Result); //Result should be unsuccessful Assert.IsFalse(task.Result); } // Close open case if (openCase != null) { var recipientsLeftToConfirm = new List <InquirerCaseRecipient>(); if (openCase.InvolvedRecipients.Any()) { // Cannot get any replies to confirm unless the case has any? var taskCofirmed = GetInquirerCaseRepliesToConfirm(EnumUtils.ToDescription(Constants.Case_Status.TO_CONFIRM), openCase.Id); Assert.IsNotNull(taskCofirmed); Assert.IsNotNull(taskCofirmed.Result); recipientsLeftToConfirm = taskCofirmed.Result; } if (recipientsLeftToConfirm != null && recipientsLeftToConfirm.Any() || !openCase.InvolvedRecipients.TrueForAll(ir => ir.Confirmed)) { // you can not close this case // can not do anything nothing more } else { // woohoo, you can close this case. var task = PostInquirerCaseClosing(openCase.Id, listOfClosedCaseComments); Assert.IsNotNull(task); Assert.IsNotNull(task.Result); //Result should be successful Assert.IsTrue(task.Result); //Get case and check if it's closed var inquirerCaseTask = GetInquirerCaseByNumber(openCase.Id, _context.Token); Assert.IsNotNull(inquirerCaseTask); Assert.IsNotNull(inquirerCaseTask.Result); Assert.That(inquirerCaseTask.Result.Status.ToLower(), Is.EqualTo("closed")); } } }