Skip to content

Commit

Permalink
Merge pull request #812 from solidify/bugfix/field-closed-date-cannot…
Browse files Browse the repository at this point in the history
…-be-empty

Fix bug where ClosedDate is unset for closed work items
  • Loading branch information
Alexander-Hjelm authored Jul 24, 2023
2 parents ebe3cae + 24c29b6 commit 6f7610f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WiField>();
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<string>(WiFieldReference.State), Is.EqualTo("New"));
Assert.That(rev.Fields.GetFieldValueOrDefault<string>(WiFieldReference.ClosedDate), Is.EqualTo(null));
Assert.That(rev.Fields.GetFieldValueOrDefault<string>(WiFieldReference.ClosedBy), Is.EqualTo(null));
});
}

[Test]
public void When_calling_ensure_classification_fields_with_empty_args_Then_an_exception_is_thrown()
{
Expand Down

0 comments on commit 6f7610f

Please sign in to comment.