public UpdateBuilder On(DateTime changedDate) { _fields[ChangedDateField] = new WorkItemFieldUpdate { NewValue = changedDate.ToString("s") }; return(this); }
public void ShouldIdentifyWhenValueIsNotEmpty([Values(null, "", "V", "V")] string oldValue, [Values("V", "V", null, "")] string newValue) { var update = new WorkItemFieldUpdate { OldValue = oldValue, NewValue = newValue }; update.IsEmpty().Should().BeFalse(); }
public void ShouldIdentifyWhenValueIsCleared(string oldValue, string newValue, bool expectedResult) { var update = new WorkItemFieldUpdate { OldValue = oldValue, NewValue = newValue }; update.IsValueCleared().Should().Be(expectedResult); }
public void ShouldCorrectlyIdentifyWhenValueNotChanged([Values(null, "", "F")] string oldValue, [Values(null, "", "F")] string newValue) { var update = new WorkItemFieldUpdate { OldValue = oldValue, NewValue = newValue }; update.IsValueChanged().Should().BeFalse(); }
public void ShouldCorrectlyIdentifyChange([Values(null, "", "G", "f")] string oldValue, [Values("F", "F", "F", "F")] string newValue) { var update = new WorkItemFieldUpdate { OldValue = oldValue, NewValue = newValue }; update.IsValueChanged().Should().BeTrue(); }
public static void EnsureFieldSet(this IDictionary <string, WorkItemFieldUpdate> source, string fieldName, object value) { var fieldPath = JsonPatchDocumentExtensions.ToFieldPath(fieldName); if (!source.TryGetValue(fieldName, out var updateValue)) { source[fieldName] = new WorkItemFieldUpdate() { NewValue = value, OldValue = value } } ; } }
public void IndexAccessorsShouldReturnUpdateByKey() { var update = new WorkItemUpdate(); update.Fields = new System.Collections.Generic.Dictionary <string, WorkItemFieldUpdate>(); var wfu = new WorkItemFieldUpdate { OldValue = string.Empty, NewValue = "Bla" }; update.Fields.Add("Foo", wfu); var fieldUpdate = update["Foo"]; fieldUpdate.Should().Be(wfu); }
public UpdateBuilder With(string fieldName, WorkItemFieldUpdate value) { _fields[fieldName] = value; On(DateTime.UtcNow); return(this); }
/// <summary> /// /// </summary> /// <param name="azureDevOpsUri">URI as a string</param> /// <param name="personalAccessToken">Personal Access Token as a string</param> /// <param name="azureDevOpsWiqlString">The DevOps Query as a string</param> /// <param name="fields">The specific fields to show as an array</param> /// <returns></returns> public List <WorkItemInstance> GetAllWorkItemsFromAzureDevOps(string azureDevOpsUri, string personalAccessToken, string azureDevOpsWiqlString, string[] fields) { List <WorkItemInstance> workItemsAndCommentsList = new List <WorkItemInstance>(); try { //Set the Uri and Access token Uri devOpsUri = new Uri(azureDevOpsUri); VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(devOpsUri, credentials)) { //Retrieve the work items based on the Wiql string provided WorkItemQueryResult workItemQueryResult = WorkItemResponse(devOpsUri, credentials, azureDevOpsWiqlString); var selectedWorkItemIDs = workItemQueryResult.WorkItems.Select(workItemReference => workItemReference.Id).ToList(); var retrievedWorkItems = workItemTrackingHttpClient.GetWorkItemsAsync(selectedWorkItemIDs, fields, workItemQueryResult.AsOf).Result; foreach (WorkItem workItem in retrievedWorkItems) { int workItemId = (int)workItem.Id; List <WorkItemStateChange> WorkItemStateChangesList = new List <WorkItemStateChange>(); List <WorkItemUpdate> updates = workItemTrackingHttpClient.GetUpdatesAsync(workItemId).Result; foreach (var WorkItemStateChange in updates) { WorkItemStateChange myWorkItemStateChange = new WorkItemStateChange(); myWorkItemStateChange.WorkItemStateChangeId = WorkItemStateChange.Id.ToString(); myWorkItemStateChange.Revision = WorkItemStateChange.Rev.ToString(); myWorkItemStateChange.RevisedBy = WorkItemStateChange.RevisedBy.Name; if (WorkItemStateChange.Fields != null && WorkItemStateChange.Fields.ContainsKey("System.Reason")) { WorkItemFieldUpdate workItemUpdateReason = (WorkItemFieldUpdate)WorkItemStateChange.Fields["System.Reason"]; myWorkItemStateChange.ReasonOldValue = workItemUpdateReason.OldValue != null?workItemUpdateReason.OldValue.ToString() : "OLD VALUE IS NULL"; myWorkItemStateChange.ReasonNewValue = workItemUpdateReason.NewValue != null?workItemUpdateReason.NewValue.ToString() : "NEW VALUE IS NULL"; myWorkItemStateChange.RevisedDate = WorkItemStateChange.RevisedDate.ToShortDateString(); WorkItemStateChangesList.Add(myWorkItemStateChange); } } WorkItemInstance adoWorkItemInstanceClass = new WorkItemInstance(); adoWorkItemInstanceClass.WorkItemUpdateList = WorkItemStateChangesList; //Get the WorkItemId add it to the main record adoWorkItemInstanceClass.WorkItemId = workItem.Fields["System.Id"].ToString(); //Add the work item to the class adoWorkItemInstanceClass.AdoWorkItem = workItem; WorkItemComments workItemComments = workItemTrackingHttpClient.GetCommentsAsync(workItem.Id.Value).Result; //adoWorkItemInstanceClass.AdoCommentsList = new List<WorkItemComment>(); List <WorkItemComment> commentsList = new List <WorkItemComment>(); foreach (WorkItemComment commentItem in workItemComments.Comments) { //Add the comment to the list commentsList.Add(commentItem); } //Add the comments list to the WorkItemInstance class adoWorkItemInstanceClass.AdoCommentsList = commentsList; workItemsAndCommentsList.Add(adoWorkItemInstanceClass); } } } catch (AggregateException aggException) { WorkItemInstance aggExceptionWorkItem = new WorkItemInstance(); aggExceptionWorkItem.ErrorMessage = aggException.InnerException.ToString(); workItemsAndCommentsList.Add(aggExceptionWorkItem); } catch (VssException vssException) { WorkItemInstance vssExceptionWorkItem = new WorkItemInstance(); vssExceptionWorkItem.ErrorMessage = vssException.InnerException.ToString(); workItemsAndCommentsList.Add(vssExceptionWorkItem); } //Output is the Work Items and their comments return(workItemsAndCommentsList); }