public async Task ImmutableValidator_Validate_Error() { // arrange WorkItemManager manager = BuildManager(); var properties = new Property[] { new Property("A", "String", ""), new Property("B", "String", "bb"), }; // act var result = await manager.CreateAsync("FOO", "BAR", properties); // assert Assert.NotNull(result); Assert.False(result.Success); Assert.NotNull(result.CreatedWorkItem); 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); } ); }
public async Task WorkItemManager_ExecuteCommand_Invoke() { // arrange var manager = new WorkItemManager(new InMemoryDataProvider(), new InMemoryDescriptorProvider( WorkItemDescriptor.Create("BAR", new PropertyDescriptor[] { PropertyDescriptor.Create("A", "String", initialValue: "a"), PropertyDescriptor.Create("B", "String"), }, stages: new StageDescriptor[] { new StageDescriptor("stage-aa", new PropertyValueConditionDescriptor("A", "aa"), Array.Empty <StagePropertyDescriptor>(), new CommandDescriptor[] { new ChangePropertyValueCommandDescriptor("make-bb", "MakeBBC", "B", "bbc") }), }) )); var issue = await manager.CreateAsync("FOO", "BAR", new Property[] { new Property("A", "String", "aa"), new Property("B", "String", "bb"), }); // act var result = await manager.ExecuteCommandAsync("FOO", issue.Id, "make-bb"); // assert Assert.True(result.Success); Assert.Collection(result.UpdatedWorkItem.Properties, p => { Assert.Equal("aa", p.Value); Assert.Equal("A", p.Name); }, p => { Assert.Equal("bbc", p.Value); Assert.Equal("B", p.Name); } ); }
public async Task WorkItemManager_Create_MissingWorkItemType() { // arrange var manager = new WorkItemManager(null, new CommonSdlcDescriptorProvider()); // act await Assert.ThrowsAsync <ArgumentException>(async() => { await manager.CreateAsync("FOO", null, new Property[] { }); }); }
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); } ); } ); }
public async Task WorkItemManager_Create_DoNotCreateWithoutProperties() { // arrange var providerMock = new Mock <IDataProvider>(); providerMock.SetupGet(o => o.Write).Returns(true); var manager = new WorkItemManager(providerMock.Object, new CommonSdlcDescriptorProvider()); // act var result = await manager.CreateAsync("FOO", "BAR", new Property[] { }); // assert Assert.False(result.Success); providerMock.VerifyGet(o => o.Write); providerMock.VerifyNoOtherCalls(); }
public async Task <ActionResult> CreateSingleWorkItem(string projectCode, [FromBody] CreateWorkItemApiRequest request) { try { var result = await _workItemManager.CreateAsync(request.ProjectCode, request.WorkItemType, request.Properties); if (result is { Success : true }) { return(Ok(new WorkItemApiResponse() { Success = true, ProjectCode = result.CreatedWorkItem.ProjectCode, WorkItemId = result.CreatedWorkItem.Id, WorkItem = result.CreatedWorkItem, })); }
public async Task ImmutableValidator_Validate_Success() { // arrange WorkItemManager manager = BuildManager(); var properties = new Property[] { new Property("A", "String", "aa"), new Property("B", "String", string.Empty), }; // act var result = await manager.CreateAsync("FOO", "BAR", properties); // assert Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.CreatedWorkItem); Assert.Empty(result.Errors); }
public async Task StringLengthValidator_Validate_NoSideEffect() { // arrange WorkItemManager manager = BuildManager(); var properties = new Property[] { new Property("A", "String", "ABC"), new Property("B", "String", "ABCDEFGH"), }; // act var result = await manager.CreateAsync("FOO", "BAR", properties); // assert Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.CreatedWorkItem); Assert.Empty(result.Errors); }
public async Task EnumValueProvider_Validate_IgnoreNullValue() { // arrange WorkItemManager manager = BuildManager(); var properties = new Property[] { new Property("A", "String", "a"), new Property("B", "String", "d"), new Property("C", "String", ""), }; // act var result = await manager.CreateAsync("FOO", "BAR", properties); // assert Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.CreatedWorkItem); Assert.Collection(result.Errors); }
public async Task WorkItemManager_ExecuteCommand_NotFound() { // arrange var manager = new WorkItemManager(new InMemoryDataProvider(), new InMemoryDescriptorProvider( WorkItemDescriptor.Create("BAR", new PropertyDescriptor[] { PropertyDescriptor.Create("A", "String", initialValue: "a"), PropertyDescriptor.Create("B", "String"), }) )); var issue = await manager.CreateAsync("FOO", "BAR", new Property[] { new Property("A", "String", "aa"), new Property("B", "String", "bb"), }); // act var result = await manager.ExecuteCommandAsync("FOO", issue.Id, "Close"); // assert Assert.False(result.Success); }
public static async Task <int> ExecuteAsync(WorkItemManager manager, string?projectCode, string?workItemType) { if (manager is null) { throw new ArgumentNullException(nameof(manager)); } if (string.IsNullOrWhiteSpace(projectCode)) { throw new ArgumentException("message", nameof(projectCode)); } if (string.IsNullOrWhiteSpace(workItemType)) { throw new ArgumentException("message", nameof(workItemType)); } var wi = await manager.CreateTemplateAsync(projectCode, workItemType); var propertyDescriptors = manager.DescriptorManager.GetCurrentPropertyDescriptors(wi); if (propertyDescriptors == null) { Console.WriteLine($"Cannot find type {workItemType} in project {projectCode}"); return(1); } var propertiesDictionary = new Dictionary <string, string>(); foreach (var propertyDescriptor in propertyDescriptors) { var value = await ValueProviderReadLineAutoCompletion.Readline(manager, wi, propertyDescriptor, string.Empty); propertiesDictionary.Add(propertyDescriptor.Name, value); } var properties = wi.Properties .Select(property => { if (propertiesDictionary.TryGetValue(property.Name, out var value)) { return(new Property(property.Name, property.DataType, value)); } else { return(property); } }) .Where(p => p != null) .ToArray(); var result = await manager.CreateAsync(projectCode, workItemType, properties); if (result.Success) { Console.WriteLine($"Created WorkItem in project {result.CreatedWorkItem?.ProjectCode} with id {result.Id}"); } else { Console.WriteLine($"Failed to create WorkItem"); foreach (var error in result.Errors) { Console.WriteLine($"{error.Property}: {error.Message}"); } } return(result.Success ? 0 : 1); }