public async Task SendUpdateRequest()
        {
            const int expectedId = 87094;
            var       workitem   = new WorkItem();

            workitem.Fields = new System.Collections.Generic.Dictionary <string, string>();
            var updateRequest = new UpdateWorkitemRequest(expectedId);

            updateRequest.AddFieldValue("System.Title", "Foo");
            updateRequest.AddFieldValue("System.Tags", "Bla");
            HttpClientMock.Setup(c => c.ExecutePatch <WorkItem>(It.Is <string>(u => VerifyUrl(u, expectedId)), It.Is <UpdateWorkitemRequest.Update[]>(r => ValidateRequest(r, updateRequest.Updates.ToArray())), Constants.JsonPatchMimeType, CancellationToken))
            .ReturnsAsync(workitem)
            .Verifiable();

            var result = await Client.UpdateWorkItemAsync(updateRequest, CancellationToken);

            HttpClientMock.Verify();
            result.Should().Be(workitem);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task<WorkItem> CreateWorkItemAsync(string project, string type, WorkItem item, CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfArgumentNullOrEmpty(project, nameof(project));
            ThrowIfArgumentNullOrEmpty(type, nameof(type));
            ThrowIfArgumentNull(item, nameof(item));

            var updateRequest = new UpdateWorkitemRequest();
            foreach (var field in item.Fields)
            {
                updateRequest.AddFieldValue(field.Key, field.Value);
            }

            var url = VstsUrlBuilder.Create(_instanceName)
               .WithSection(project)
               .ForWorkItems()
               .WithSection($"${type}")
               .Build();

            var result = await _httpClient.ExecutePost<WorkItem>(url, updateRequest.Updates.ToArray(), Constants.JsonPatchMimeType, cancellationToken);
            return result;
        }