コード例 #1
0
        public async Task ImmutableValidator_Validate_UpdateError()
        {
            // arrange
            WorkItemManager manager = BuildManager();

            var properties = new Property[] {
                new Property("A", "String", "aa"),
                new Property("B", "String", string.Empty),
            };

            // act
            var result1 = await manager.CreateAsync("FOO", "BAR", properties);

            var result = await manager.UpdateAsync("FOO", result1.CreatedWorkItem.Id, new Property[] {
                new Property("B", "String", "bb")
            });

            // assert
            Assert.NotNull(result);
            Assert.False(result.Success);
            Assert.NotNull(result.UpdatedWorkItem);
            Assert.Collection(result.Errors,
                              em =>
            {
                Assert.Equal(nameof(ImmutableValidator), em.Source);
                Assert.Equal(string.Empty, em.ErrorCode);
                Assert.Equal("FOO", em.ProjectCode);
                Assert.Equal("1", em.Id);
                Assert.Equal("B", em.Property);
            }
                              );
        }
コード例 #2
0
        private async Task WorkItemManager_Update_SimpleWithoutDescriptor(IDataProvider dataProvider)
        {
            // arrange
            var manager = new WorkItemManager(dataProvider, new CommonSdlcDescriptorProvider());

            var issue = await manager.CreateAsync("FOO", "BAR", new Property[] {
                new Property("A", "String", "aa"),
                new Property("B", "String", "bb"),
            });

            // act
            var result = await manager.UpdateAsync("FOO", issue.Id, new Property[] {
                new Property("A", "String", "aab"),
            });

            // assert
            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.NotNull(result.UpdatedWorkItem);

            Assert.Equal("FOO", result.UpdatedWorkItem.ProjectCode);
            Assert.Equal("BAR", result.UpdatedWorkItem.WorkItemType);

            Assert.Collection(result.UpdatedWorkItem.Properties,
                              p =>
            {
                Assert.Equal("A", p.Name);
                Assert.Equal("String", p.DataType);
                Assert.Equal("aab", p.Value);
            },
                              p =>
            {
                Assert.Equal("B", p.Name);
                Assert.Equal("String", p.DataType);
                Assert.Equal("bb", p.Value);
            }
                              );

            Assert.Collection(result.UpdatedWorkItem.Log,
                              l =>
            {
                Assert.Collection(l.Changes,
                                  pc =>
                {
                    Assert.Equal("A", pc.Name);
                    Assert.Equal("aa", pc.OldValue);
                    Assert.Equal("aab", pc.NewValue);
                }
                                  );
            }
                              );
        }
コード例 #3
0
        public static async Task <int> ExecuteAsync(WorkItemManager manager, string?projectCode, string?id)
        {
            if (manager is null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            if (string.IsNullOrWhiteSpace(projectCode))
            {
                throw new ArgumentException("message", nameof(projectCode));
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException("message", nameof(id));
            }

            int resultCode = 1;

            var workItem = await manager.GetAsync(projectCode, id);

            if (workItem is null)
            {
                Console.WriteLine($"Could not find the specified workitem {id} in project {projectCode}");
            }
            else
            {
                var propertyDescriptors = manager.DescriptorManager.GetCurrentPropertyDescriptors(workItem);

                var changedProperties = new List <Property>();

                foreach (var property in workItem.Properties)
                {
                    var propertyDescriptor = propertyDescriptors.FirstOrDefault(wi => wi.Name == property.Name);

                    string value;
                    if (propertyDescriptor is null)
                    {
                        Console.Write($"{property.Name} [{property.Value}]: ");
                        value = Console.ReadLine();
                    }
                    else
                    {
                        value = await ValueProviderReadLineAutoCompletion.Readline(manager, workItem, propertyDescriptor, property.Value);
                    }

                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        changedProperties.Add(new Property(property.Name, property.DataType, value));
                    }
                }

                var result = await manager.UpdateAsync(workItem.ProjectCode, workItem.Id, changedProperties);

                if (result.Success)
                {
                    Console.WriteLine($"Updated WorkItem in project {result.UpdatedWorkItem?.ProjectCode} with id {result.UpdatedWorkItem?.Id}");
                }
                else
                {
                    Console.WriteLine($"Failed to update WorkItem");

                    foreach (var error in result.Errors)
                    {
                        Console.WriteLine($"{error.Property}: {error.Message}");
                    }
                }

                resultCode = result.Success ? 0 : 1;
            }

            return(resultCode);
        }