diff --git a/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs b/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs index 7aee94c9..29b0c5a6 100644 --- a/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs +++ b/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs @@ -627,13 +627,22 @@ private void CorrectClosedByAndClosedDate(WiRevision rev, WorkItem wi) var wiState = wi.Fields[WiFieldReference.State].ToString() ?? string.Empty; var revState = rev.Fields.GetFieldValueOrDefault(WiFieldReference.State) ?? string.Empty; - if (wiState.Equals("Done", StringComparison.InvariantCultureIgnoreCase) && revState.Equals("New", StringComparison.InvariantCultureIgnoreCase)) + if ( + ( + wiState.Equals("Done", StringComparison.InvariantCultureIgnoreCase) + || wiState.Equals("Closed", StringComparison.InvariantCultureIgnoreCase) + ) + && revState.Equals("New", StringComparison.InvariantCultureIgnoreCase) + ) { rev.Fields.Add(new WiField() { ReferenceName = WiFieldReference.ClosedDate, Value = null }); rev.Fields.Add(new WiField() { ReferenceName = WiFieldReference.ClosedBy, Value = null }); } - if (revState.Equals("Done", StringComparison.InvariantCultureIgnoreCase)) + if ( + revState.Equals("Done", StringComparison.InvariantCultureIgnoreCase) + || revState.Equals("Closed", StringComparison.InvariantCultureIgnoreCase) + ) { if (!rev.Fields.HasAnyByRefName(WiFieldReference.ClosedDate)) rev.Fields.Add(new WiField() { ReferenceName = WiFieldReference.ClosedDate, Value = rev.Time }); diff --git a/src/WorkItemMigrator/tests/Migration.Wi-Import.Tests/WitClient/WitClientUtilsTests.cs b/src/WorkItemMigrator/tests/Migration.Wi-Import.Tests/WitClient/WitClientUtilsTests.cs index d8519b83..074a2211 100644 --- a/src/WorkItemMigrator/tests/Migration.Wi-Import.Tests/WitClient/WitClientUtilsTests.cs +++ b/src/WorkItemMigrator/tests/Migration.Wi-Import.Tests/WitClient/WitClientUtilsTests.cs @@ -330,6 +330,34 @@ public void When_calling_ensure_fields_on_state_change_with_subsequent_revision_ }); } + [Test] + public void When_calling_ensure_fields_on_a_closed_user_Story_with_Then_closed_date_is_added_to_fields() + { + MockedWitClientWrapper witClientWrapper = new MockedWitClientWrapper(); + WitClientUtils wiUtils = new WitClientUtils(witClientWrapper); + + WiRevision rev = new WiRevision(); + rev.Fields = new List(); + rev.Index = 1; + + WiField revState = new WiField(); + revState.ReferenceName = WiFieldReference.State; + revState.Value = "New"; + rev.Fields.Add(revState); + + WorkItem createdWI = wiUtils.CreateWorkItem("User Story"); + createdWI.Fields[WiFieldReference.State] = "Closed"; + + wiUtils.EnsureFieldsOnStateChange(rev, createdWI); + + Assert.Multiple(() => + { + Assert.That(rev.Fields.GetFieldValueOrDefault(WiFieldReference.State), Is.EqualTo("New")); + Assert.That(rev.Fields.GetFieldValueOrDefault(WiFieldReference.ClosedDate), Is.EqualTo(null)); + Assert.That(rev.Fields.GetFieldValueOrDefault(WiFieldReference.ClosedBy), Is.EqualTo(null)); + }); + } + [Test] public void When_calling_ensure_classification_fields_with_empty_args_Then_an_exception_is_thrown() {