//@skydocs.end() static async Task ResetCard(Card card) { //@skydocs.start(cards.update) var cardPatch = new CardPatch(); cardPatch.Add("isDone", false); //Important note: Make sure that the keys (e.g. isDone) are lower case cardPatch.Add("component", new ComponentCompletion() { Completed = false }); var cardUpdateBody = new Skylight.Api.Assignments.V1.CardRequests.PatchCardRequest(cardPatch, card.AssignmentId, card.SequenceId, card.Id); var cardUpdateResult = await SkyManager.ApiClient.ExecuteRequestAsync(cardUpdateBody); //Handle the resulting status code appropriately switch (cardUpdateResult.StatusCode) { case System.Net.HttpStatusCode.Forbidden: Console.Error.WriteLine("Error updating card: Permission forbidden."); throw new Exception("Error updating card."); case System.Net.HttpStatusCode.Unauthorized: Console.Error.WriteLine("Error updating card: Method call was unauthenticated."); throw new Exception("Error updating card."); case System.Net.HttpStatusCode.NotFound: Console.Error.WriteLine("Error updating card: User not found."); throw new Exception("Error updating card."); case System.Net.HttpStatusCode.OK: Console.WriteLine("Successfully updated card."); break; default: Console.Error.WriteLine("Unhandled card update status code: " + cardUpdateResult.StatusCode); throw new Exception("Error updating card."); } //@skydocs.end() }
public async Task TestPatchCard() { var assignment = CreateAssignmentNew(); var assignmentId = await AssignmentUtils.CreateAssignment(assignment); var cardPatch = new CardPatch(); cardPatch.Add("label", "New Label"); var patchCardRequest = new PatchCardRequest(cardPatch, assignmentId, AssignmentUtils.ROOT_SEQUENCE_ID, CARD_ID); await SkyManager.ApiClient.ExecuteRequestAsync(patchCardRequest); //TODO: If we wanted to do a full integration test, we could get the card and make sure the label has updated var getCardRequest = new GetCardRequest(assignmentId, AssignmentUtils.ROOT_SEQUENCE_ID, CARD_ID); var getCardResponse = await SkyManager.ApiClient.ExecuteRequestAsync(getCardRequest); var returnedCard = getCardResponse.Content; Assert.Equal(SkyManager.IntegrationId, returnedCard.UpdatedBy); Assert.NotNull(returnedCard.Updated); await AssignmentUtils.DeleteAssignment(assignmentId); }