private JsonPatchOperation GetAddHyperlinkWithCommentOperation(IList <WorkItem> targetWorkItems, WorkItemMigrationState state, int sourceId, int targetId, WorkItem sourceWorkItem, ISet <string> enabledPhaseStatuses) { IList <WorkItemRelation> targetRelations = targetWorkItems.First(a => a.Id == targetId).Relations; foreach (WorkItemRelation targetRelation in targetRelations) { if (RelationHelpers.IsRelationHyperlinkToSourceWorkItem(context, targetRelation, sourceId)) { string hyperlink = context.WorkItemIdsUris[sourceId]; // only store the enabled phase statuses RevAndPhaseStatus newRevAndPhaseStatus = new RevAndPhaseStatus(); newRevAndPhaseStatus.Rev = sourceWorkItem.Rev.Value; newRevAndPhaseStatus.PhaseStatus = enabledPhaseStatuses; state.RevAndPhaseStatus = newRevAndPhaseStatus; // get the key even if its letter case is different but it matches otherwise string idKeyFromFields = targetRelation.Attributes.GetKeyIgnoringCase(Constants.RelationAttributeId); object attributeId = targetRelation.Attributes[idKeyFromFields]; JsonPatchOperation addHyperlinkWithCommentOperation = MigrationHelpers.GetHyperlinkAddOperation(hyperlink, newRevAndPhaseStatus.GetCommentRepresentation(), attributeId); return(addHyperlinkWithCommentOperation); } } throw new Exception($"Could not find hyperlink to source work item on target work item with id: {targetId}. Expected source work item id: {sourceId}"); }
public void SetRevAndPhaseStatus_ReturnsCorrectValueForRegularCase() { string revAndPhaseStatusComment = "123;attachments;git commit links"; ISet <string> expectedPhaseStatus = new HashSet <string>(); expectedPhaseStatus.Add("attachments"); expectedPhaseStatus.Add("git commit links"); RevAndPhaseStatus expected = new RevAndPhaseStatus(); expected.Rev = 123; expected.PhaseStatus = expectedPhaseStatus; RevAndPhaseStatus actual = new RevAndPhaseStatus(); actual.SetRevAndPhaseStatus(revAndPhaseStatusComment); Assert.AreEqual(expected.Rev, actual.Rev); foreach (string item in expected.PhaseStatus) { Assert.IsTrue(actual.PhaseStatus.Contains(item)); } }
public void SetRevAndPhaseStatus_ReturnsCorrectValueWhenOnlyRev() { string revAndPhaseStatusComment = "123"; RevAndPhaseStatus expected = new RevAndPhaseStatus(); expected.Rev = 123; expected.PhaseStatus = new HashSet <string>(); RevAndPhaseStatus actual = new RevAndPhaseStatus(); actual.SetRevAndPhaseStatus(revAndPhaseStatusComment); Assert.AreEqual(expected.Rev, actual.Rev); Assert.AreEqual(0, actual.PhaseStatus.Count); }
public void GetCommentRepresentation_ReturnsCorrectValue() { RevAndPhaseStatus revAndPhaseStatus = new RevAndPhaseStatus(); revAndPhaseStatus.Rev = 123; ISet <string> phaseStatus = new HashSet <string>(); phaseStatus.Add("attachments"); phaseStatus.Add("git commit links"); revAndPhaseStatus.PhaseStatus = phaseStatus; string expected = "123;attachments;git commit links"; string actual = revAndPhaseStatus.GetCommentRepresentation(); Assert.AreEqual(expected, actual); }
private RevAndPhaseStatus GetRevAndPhaseStatus(WorkItem targetWorkItem, int sourceWorkItemId) { if (targetWorkItem.Relations != null) { foreach (WorkItemRelation relation in targetWorkItem.Relations) { if (RelationHelpers.IsRelationHyperlinkToSourceWorkItem(context, relation, sourceWorkItemId)) { // get the key even if its letter case is different but it matches otherwise string keyFromFields = relation.Attributes.GetKeyIgnoringCase(Constants.RelationAttributeComment); string relationRevAndPhaseStatusComment = relation.Attributes[keyFromFields].ToString(); RevAndPhaseStatus revAndPhaseStatus = new RevAndPhaseStatus(relationRevAndPhaseStatusComment); return(revAndPhaseStatus); } } } throw new Exception($"Could not find comment in relation hyperlink to source work item on target work item with id: {targetWorkItem.Id.Value}. Expected source work item id: {sourceWorkItemId}"); }