public void CreateWorkItem_UnitTest() { JsonWitAPI api = APIFactory.JsonWorkItemAPI; const string project = "RestPlaypen"; const string workItemType = "Task"; var fieldValues = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("System.Title", "WorkItem Created by Unit Testing") // new KeyValuePair<string, object>("System.Project", "RestPlaypen"), // new KeyValuePair<string, object>("System.WorkItemType", "Task") }; JsonWorkItem workItem = JsonWitAPI.BuildWorkItem(project, workItemType, fieldValues); Task <JsonWorkItem> createTask = api.CreateWorkItem(project, workItemType, workItem, false); JsonWorkItem finalResult = createTask.Result; Assert.IsNotNull(finalResult); }
/// <summary> /// Creates the work item. /// </summary> /// <param name="project">The project.</param> /// <param name="workItem">The work item.</param> /// <returns>Task<IWorkItem>.</returns> /// <exception cref="ToBeImplementedException"></exception> public Task <IWorkItem> CreateWorkItem(string project, IWorkItem workItem) { string workItemType = workItem.Type.Name; var fieldValues = new List <KeyValuePair <string, object> >(); for (int index = 0; index < workItem.Fields.Count; ++index) { var item = workItem.Fields[index]; var fieldName = item.Name; var fieldValue = item.Value; fieldValues.Add(new KeyValuePair <string, object>(fieldName, fieldValue)); } JsonWorkItem jWorkItem = JsonWitAPI.BuildWorkItem(project, workItemType, fieldValues); var internalTask = r_JsonAPI.CreateWorkItem(project, workItemType, jWorkItem, true); var result = new Task <IWorkItem>(() => { internalTask.Wait(); // TODO Transfer State from jWorkItem to workItem; return(workItem); }); result.Start(); return(result); }