/// <summary>
        /// Update work ietm with all required field values
        /// </summary>
        /// <param name="workItemType"></param>
        /// <param name="old_wi_ID"></param>
        /// <param name="projectName"></param>
        /// <param name="dictionaryWIFields"></param>
        /// <returns></returns>
        public bool UpdateWorkIteminTarget(string workItemType, string old_wi_ID, string projectName, Dictionary <string, object> dictionaryWIFields)
        {
            try
            {
                List <WorkItemPatch.Field>     listFields = new List <WorkItemPatch.Field>();
                WorkItemPatchResponse.WorkItem viewModel  = new WorkItemPatchResponse.WorkItem();
                // change some values on a few fields
                foreach (string key in dictionaryWIFields.Keys)
                {
                    listFields.Add(new WorkItemPatch.Field()
                    {
                        op = "add", path = key, value = dictionaryWIFields[key]
                    });
                }
                WorkItemPatch.Field[] fields = listFields.ToArray();
                using (var client = GetHttpClient())
                {
                    var postValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call
                                                                                                                                          // set the httpmethod to Patch
                    var method = new HttpMethod("PATCH");

                    // send the request
                    var request = new HttpRequestMessage(method, projectName + "/_apis/wit/workitems/$" + workItemType + "?bypassRules=true&api-version=" + _configuration.VersionNumber)
                    {
                        Content = postValue
                    };
                    var response = client.SendAsync(request).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                        wiData.Add(new WIMapData()
                        {
                            OldID = old_wi_ID, NewID = viewModel.id.ToString(), WIType = workItemType
                        });
                    }
                    else
                    {
                        var    errorMessage = response.Content.ReadAsStringAsync();
                        string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                        this.LastFailureMessage = error;
                    }

                    return(response.IsSuccessStatusCode);
                }
            }
            catch (OperationCanceledException opr)
            {
                logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t OperationCanceledException: " + opr.Message + "\t" + "\n" + opr.StackTrace + "\n");
            }
            catch (Exception ex)
            {
                logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
            }
            return(false);
        }
        // / <summary>
        // / Create a bug
        // / </summary>
        // / <param name="projectName"></param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem CreateBug(string projectName)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[4];

            // set some field values like title and description
            fields[0] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.Title", value = "Authorization Errors"
            };
            fields[1] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx"
            };
            fields[2] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1"
            };
            fields[3] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Bug?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                var me = response.ToString();

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 3
0
        public WorkItemPatchResponse.WorkItem UpdateWorkItemAddCommitLink(string id)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            Object[] patchDocument = new Object[1];;

            // change some values on a few fields
            patchDocument[0] = new WorkItemPatch.Field()
            {
                op    = "add",
                path  = "/relations/-",
                value = new {
                    rel        = "ArtifactLink",
                    url        = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3",
                    attributes = new {
                        name = "Fixed in Commit"
                    }
                }
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel         = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                    viewModel.Message = "success";
                }
                else
                {
                    dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync <dynamic>();
                    Newtonsoft.Json.Linq.JContainer msg  = responseForInvalidStatusCode.Result;
                    viewModel.Message = msg.ToString();
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Update work ietm with all required field values
        /// </summary>
        /// <param name="workItemType"></param>
        /// <param name="old_wi_ID"></param>
        /// <param name="ProjectName"></param>
        /// <param name="dicWIFields"></param>
        /// <returns></returns>
        public bool UpdateWorkIteminTarget(string workItemType, string old_wi_ID, string ProjectName, Dictionary <string, object> dicWIFields)
        {
            //int pathCount = paths.Count();
            List <WorkItemPatch.Field> lstFields = new List <WorkItemPatch.Field>();

            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            // change some values on a few fields
            foreach (string key in dicWIFields.Keys)
            {
                lstFields.Add(new WorkItemPatch.Field()
                {
                    op = "add", path = key, value = dicWIFields[key]
                });
            }
            WorkItemPatch.Field[] fields = lstFields.ToArray();
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _credentials);

                //var postValue = new StringContent(JsonConvert.SerializeObject(wI), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
                var postValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call
                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + ProjectName + "/_apis/wit/workitems/$" + workItemType + "?bypassRules=true&api-version=2.2")
                {
                    Content = postValue
                };
                var response = client.SendAsync(request).Result;


                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                    WIData.Add(new WIMapData()
                    {
                        OldID = old_wi_ID, NewID = viewModel.id.ToString(), WIType = workItemType
                    });
                }
                else
                {
                    var    errorMessage = response.Content.ReadAsStringAsync();
                    string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                    this.lastFailureMessage = error;
                }

                return(response.IsSuccessStatusCode);
            }
        }
Exemplo n.º 5
0
        public WorkItemPatchResponse.WorkItem UpdateWorkItemAddHyperLink(string id)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            Object[] patchDocument = new Object[2];

            // change some values on a few fields
            patchDocument[0] = new { op = "test", path = "/rev", value = "1" };
            patchDocument[1] = new {
                op    = "add",
                path  = "/relations/-",
                value = new {
                    rel        = "Hyperlink",
                    url        = "http://www.visualstudio.com/team-services",
                    attributes = new {
                        comment = "Visual Studio Team Services"
                    }
                }
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel         = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                    viewModel.Message = "success";
                }
                else
                {
                    dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync <dynamic>();
                    Newtonsoft.Json.Linq.JContainer msg  = responseForInvalidStatusCode.Result;
                    viewModel.Message = msg.ToString();
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
        // / <summary>
        // / update a specific work item by id and return that changed worked item
        // / </summary>
        // / <param name="id"></param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem UpdateWorkItemFields(string id)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[4];

            // change some values on a few fields
            fields[0] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.History", value = "adding some history"
            };
            fields[1] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2"
            };
            fields[2] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.BusinessValue", value = "100"
            };
            fields[3] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.ValueArea", value = "Architectural"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
        // / <summary>
        // / create a work item using bypass rules
        // / </summary>
        // / <param name="projectName">name of project</param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem CreateWorkItemUsingByPassRules(string projectName)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[3];

            // add a title and add a field you normally cant add such as CreatedDate
            fields[0] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.Title", value = "hello world!"
            };
            fields[1] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016"
            };
            fields[2] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.CreatedBy", value = "Art Vandelay"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                var url = _configuration.UriString + projectName + "/_apis/wit/workitems/$UserStory?api-version=2.2";

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                var me = response.ToString();

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 8
0
        public void WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem response = request.CreateWorkItemWithWorkItemLink(_configuration.Project, _configuration.WorkItemId);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);

            request = null;
        }
Exemplo n.º 9
0
        public void WorkItemTracking_WorkItems_UpdateWorkItemByPassRules_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemByPassingRules(_configuration.WorkItemId);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);

            request = null;
        }
Exemplo n.º 10
0
        public void WorkItemTracking_WorkItems_AddAndUpdateWorkItemTags_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem result = request.AddWorkItemTags(_configuration.WorkItemId, "Technical Debt; Spike Needed");

            // assert
            Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode);

            request = null;
        }
Exemplo n.º 11
0
        public WorkItemPatchResponse.WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkToId)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            Object[] patchDocument = new Object[5];

            patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" };
            patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", value = "4" };
            patchDocument[2] = new { op = "add", path = "/fields/System.Description", value = "Follow the code samples from MSDN" };
            patchDocument[3] = new { op = "add", path = "/fields/System.History", value = "Jim has the most context around this." };
            patchDocument[4] = new
            {
                op    = "add",
                path  = "/relations/-",
                value = new
                {
                    rel        = "System.LinkTypes.Hierarchy-Reverse",
                    url        = _configuration.UriString + "/_apis/wit/workitems/" + linkToId,
                    attributes = new
                    {
                        comment = "decomposition of work"
                    }
                }
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 12
0
        // / <summary>
        // / move a work item from a project in agile to a project in scrum
        // / </summary>
        // / <param name="id">work item id</param>
        // / <param name="type">Bug or User Story</param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem ChangeType(string id, string type)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[3];

            // change the work item type, state and reason values in order to change the work item type
            fields[0] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.WorkItemType", value = type
            };
            fields[1] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.State", value = "New"
            };
            fields[2] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.Reason", value = "New"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                var someme = response.ToString();

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 13
0
        // / <summary>
        // / add link to another work item
        // / </summary>
        // / <param name="id">work item id</param>
        // / <param name="linkToId">link to work item id</param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem AddAttachment(string id, string url)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[1];

            // change some values on a few fields
            fields[0] = new WorkItemPatch.Field()
            {
                op    = "add",
                path  = "/relations/-",
                value = new WorkItemPatch.Value()
                {
                    rel        = "AttachedFile",
                    url        = url,
                    attributes = new WorkItemPatch.Attributes()
                    {
                        comment = "adding attachment to work item"
                    }
                }
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 14
0
        public void WorkItemTracking_WorkItems_ChangeType_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem response = request.ChangeType(_configuration.WorkItemId, "User Story");
            var someme = response.ToString();

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);

            request = null;
        }
Exemplo n.º 15
0
        public void WorkItemTracking_WorkItems_DeleteWorkItem_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
            var deleteResponse = request.DeleteWorkItem(createResponse.id.ToString());

            // assert
            Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);

            request = null;
        }
Exemplo n.º 16
0
        public void WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem createResponse       = request.CreateWorkItem(_configuration.Project);
            WorkItemPatchResponse.WorkItem addHyperLinkResponse = request.UpdateWorkItemAddHyperLink(createResponse.id.ToString());

            // assert
            Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, addHyperLinkResponse.HttpStatusCode);

            request = null;
        }
Exemplo n.º 17
0
        public void WorkItemTracking_WorkItems_AddLink_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            string[] arr = _configuration.WorkItemIds.Split(',');

            // act
            WorkItemPatchResponse.WorkItem response = request.AddLink(arr[0].ToString(), arr[1].ToString());

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);

            request = null;
        }
Exemplo n.º 18
0
        public void WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            ///create a task then change it to a user story
            WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
            WorkItemPatchResponse.WorkItem changeResponse = request.UpdateWorkItemChangeWorkItemType(createResponse.id.ToString());

            // assert
            Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, changeResponse.HttpStatusCode);

            request = null;
        }
Exemplo n.º 19
0
        public WorkItemPatchResponse.WorkItem UpdateWorkItemAddAttachment(string id, string url)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            Object[] patchDocument = new Object[3];

            // change some values on a few fields
            patchDocument[0] = new { op = "test", path = "/rev", value = "1" };
            patchDocument[1] = new { op = "add", path = "/fields/System.History", value = "Adding the necessary spec" };
            patchDocument[2] = new {
                op    = "add",
                path  = "/relations/-",
                value = new {
                    rel        = "AttachedFile",
                    url        = url,
                    attributes = new {
                        comment = "VanDelay Industries - Spec"
                    }
                }
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 20
0
        public void WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success()
        {
            // arrange
            WorkItems request       = new WorkItems(_configuration);
            string    areaPath      = _configuration.MoveToProject; // user project name for root area path
            string    iterationPath = _configuration.MoveToProject; // use project name for root iteration path

            // act
            WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemMoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
            Assert.AreEqual(response.fields.SystemAreaPath, areaPath);
            Assert.AreEqual(response.fields.SystemIterationPath, iterationPath);

            request = null;
        }
Exemplo n.º 21
0
        public void WorkItemTracking_RecycleBin_GetDeletedItem_Success()
        {
            // arrange
            WorkItems  workItemsRequest  = new WorkItems(_configuration);
            RecycleBin recyclebinRequest = new RecycleBin(_configuration);

            // act
            WorkItemPatchResponse.WorkItem         createResponse         = workItemsRequest.CreateWorkItem(_configuration.Project);
            WorkItemPatchResponse.WorkItem         deleteResponse         = workItemsRequest.DeleteWorkItem(createResponse.id.ToString());
            GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString());

            //assert
            Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode);

            workItemsRequest  = null;
            recyclebinRequest = null;
        }
Exemplo n.º 22
0
        public void WorkItemTracking_WorkItems_CreateAndLinkMultipleWorkItems_Success()
        {
            // arrange
            Batch request = new Batch(_configuration);

            // act
            WorkItemBatchPostResponse response = request.CreateAndLinkMultipleWorkItems(_configuration.Project);

            // assert
            foreach (WorkItemBatchPostResponse.Value value in response.values)
            {
                Assert.AreEqual(200, value.code);

                WorkItemPatchResponse.WorkItem workitem = JsonConvert.DeserializeObject <WorkItemPatchResponse.WorkItem>(value.body);
                Assert.IsTrue(workitem.relations.Length == 1);
            }

            request = null;
        }
Exemplo n.º 23
0
        public WorkItemPatchResponse.WorkItem UpdateWorkItemAddLink(string id, string linkToId)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            Object[] patchDocument = new Object[1];

            patchDocument[0] = new {
                op    = "add",
                path  = "/relations/-",
                value = new {
                    rel        = "System.LinkTypes.Dependency-forward",
                    url        = _configuration.UriString + "/_apis/wit/workitems/" + linkToId,
                    attributes = new {
                        comment = "Making a new link for the dependency"
                    }
                }
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Create Work items bypassing all rules
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public WorkItemPatchResponse.WorkItem CreateWorkItemUsingByPassRules(string json)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[3];


            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var jsonContent = new StringContent(json, Encoding.UTF8, "application/json-patch+json");
                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + "TestProject" + "/_apis/wit/workitems/$" + "User Story" + "?bypassRules=true&api-version=2.2")
                {
                    Content = jsonContent
                };
                var response = client.SendAsync(request).Result;

                var me = response.ToString();

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }
                else
                {
                    var    errorMessage = response.Content.ReadAsStringAsync();
                    string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                    this.LastFailureMessage = error;
                }

                viewModel.HttpStatusCode = response.StatusCode;
                return(viewModel);
            }
        }
Exemplo n.º 25
0
        public void WorkItemTracking_WorkItems_AddCommitLink_Success()
        {
            // arrange
            WorkItems request = new WorkItems(_configuration);

            // act
            WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemAddCommitLink("3045");

            // assert
            if (response.Message.ToLower().Contains("relation already exists"))
            {
                Assert.Inconclusive("Commit link already exists on bug");
            }
            else
            {
                Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
            }

            request = null;
        }
Exemplo n.º 26
0
        // / <summary>
        // / update fields on work item using bypass rules
        // / </summary>
        // / <param name="id">work item id</param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem UpdateWorkItemFieldsWithByPassRules(string id)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[1];

            // replace value on a field that you normally cannot change, like system.createdby
            fields[0] = new WorkItemPatch.Field()
            {
                op = "replace", path = "/fields/System.CreatedBy", value = "Foo <*****@*****.**>"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?bypassRules=true&api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 27
0
        public WorkItemPatchResponse.WorkItem CreateWorkItemByPassingRules(string projectName)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();

            Object[] patchDocument = new Object[3];

            // patch document to create a work item
            patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" };
            patchDocument[1] = new { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" };
            patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Art VanDelay" };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                var me = response.ToString();

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 28
0
        public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success()
        {
            // arrange
            WorkItems   request            = new WorkItems(_configuration);
            Attachments attachmentsRequest = new Attachments(_configuration);

            // act
            //upload attachment
            var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath);

            //create work item then add attachment to that work item
            WorkItemPatchResponse.WorkItem createResponse           = request.CreateWorkItem(_configuration.Project);
            WorkItemPatchResponse.WorkItem addAttachmentResponse    = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url);
            WorkItemPatchResponse.WorkItem removeAttachmentResponse = request.UpdateWorkItemRemoveAttachment(createResponse.id.ToString());

            // assert
            Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, addAttachmentResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, removeAttachmentResponse.HttpStatusCode);

            request            = null;
            attachmentsRequest = null;
        }
Exemplo n.º 29
0
        public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateLink(string id, string linkToId)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            Object[] patchDocument = new Object[2];

            patchDocument[0] = new { op = "test", path = "/rev", value = "2" };
            patchDocument[1] = new {
                op    = "replace",
                path  = "/relations/0/attributes/comment",
                value = "Adding traceability to dependencies"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                var method  = new HttpMethod("PATCH");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Exemplo n.º 30
0
        public void WorkItemTracking_RecycleBin_PermenentlyDeletedItem_Success()
        {
            // arrange
            WorkItems  workItemsRequest  = new WorkItems(_configuration);
            RecycleBin recyclebinRequest = new RecycleBin(_configuration);

            // act
            WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
            WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString());
            HttpStatusCode permDeleteResponse             = recyclebinRequest.PermenentlyDeleteItem(createResponse.id.ToString());


            ////get delete item
            GetWorkItemExpandAllResponse.WorkItem getDeletedWorkItem = workItemsRequest.GetWorkItem(createResponse.id.ToString());

            //assert
            Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, permDeleteResponse);
            Assert.AreEqual(HttpStatusCode.NoContent, getDeletedWorkItem.HttpStatusCode);

            workItemsRequest  = null;
            recyclebinRequest = null;
        }