public static void UpdateFromModel(this TeamFoundation.WorkItemTracking.Client.WorkItem workItemEntity, WorkItem workItemModel) { if (workItemEntity == null) { throw new ArgumentNullException("workItemEntity"); } if (workItemModel == null) { throw new ArgumentNullException("workItemModel"); } workItemEntity.Title = workItemModel.Title; workItemEntity.Description = workItemModel.Description; if (!string.IsNullOrWhiteSpace(workItemModel.AreaPath)) { workItemEntity.AreaPath = workItemModel.AreaPath; } if (!string.IsNullOrWhiteSpace(workItemModel.IterationPath)) { workItemEntity.IterationPath = workItemModel.IterationPath; } if (!string.IsNullOrWhiteSpace(workItemModel.State)) { workItemEntity.State = workItemModel.State; } if (!string.IsNullOrWhiteSpace(workItemModel.Reason)) { workItemEntity.Reason = workItemModel.Reason; } if (!string.IsNullOrWhiteSpace(workItemModel.AssignedTo)) { workItemEntity.Fields[TeamFoundation.WorkItemTracking.Client.CoreField.AssignedTo].Value = workItemModel.AssignedTo; } if (!string.IsNullOrWhiteSpace(workItemModel.Priority)) { int priority; if (int.TryParse(workItemModel.Priority, NumberStyles.Integer, CultureInfo.InvariantCulture, out priority)) { workItemEntity.Fields.SetFieldValueByReference("Microsoft.VSTS.Common.Priority", priority); // For CodePlex TFS workItemEntity.Fields.SetFieldValueByReference("CodeStudio.Rank", GetPriorityDescription(priority)); } else { // For CodePlex TFS workItemEntity.Fields.SetFieldValueByReference("CodeStudio.Rank", workItemModel.Priority); } } if (!string.IsNullOrWhiteSpace(workItemModel.Severity)) { workItemEntity.Fields.SetFieldValueByReference("Microsoft.VSTS.Common.Severity", workItemModel.Severity); } if (!string.IsNullOrWhiteSpace(workItemModel.StackRank)) { workItemEntity.Fields.SetFieldValueByReference("Microsoft.VSTS.Common.StackRank", double.Parse(workItemModel.StackRank, NumberStyles.Float, CultureInfo.InvariantCulture)); } if (!string.IsNullOrWhiteSpace(workItemModel.ReproSteps)) { workItemEntity.Fields.SetFieldValueByReference("Microsoft.VSTS.TCM.ReproSteps", workItemModel.ReproSteps); } if (!string.IsNullOrWhiteSpace(workItemModel.FoundInBuild)) { workItemEntity.Fields.SetFieldValueByReference("Microsoft.VSTS.Build.FoundIn", workItemModel.FoundInBuild); } if (!string.IsNullOrWhiteSpace(workItemModel.IntegratedInBuild)) { workItemEntity.Fields.SetFieldValueByReference("Microsoft.VSTS.Build.IntegrationBuild", workItemModel.IntegratedInBuild); } }
public void ItShouldGetOneWorkItem() { var mockProxy = new Mock<ITFSWorkItemProxy>(); var item = new WorkItem { Id = 1, Description = "This is the first WorkItem", CreatedBy = "johndoe", Priority = "1", Title = "Bug #1" }; mockProxy.Setup(p => p.GetWorkItem(1)) .Returns(item) .Verifiable(); var repository = new WorkItemRepository(mockProxy.Object); var result = repository.GetOne("1"); Assert.IsTrue(result != null); Assert.AreEqual(result, item); }