Skip to content

Commit 04429ec

Browse files
Copilotpascalberger
andcommitted
Fix all PullRequests tests to use identifier comparison instead of reference equality
Co-authored-by: pascalberger <[email protected]>
1 parent 1b03cdf commit 04429ec

File tree

11 files changed

+151
-105
lines changed

11 files changed

+151
-105
lines changed

src/Cake.Issues.PullRequests.Tests/ExceptionAssertExtensions.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace Cake.Issues.PullRequests.Tests;
22

3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using Shouldly;
6+
37
public static class ExceptionAssertExtensions
48
{
59
public static void IsPullRequestIssuesException(this Exception exception, string message)
@@ -8,3 +12,21 @@ public static void IsPullRequestIssuesException(this Exception exception, string
812
Assert.Equal(message, ex.Message);
913
}
1014
}
15+
16+
/// <summary>
17+
/// Extensions to help with issue comparisons in tests after making IIssue immutable.
18+
/// Since issues are now cloned with enhanced properties, we need to compare by content rather than reference.
19+
/// </summary>
20+
public static class IssueAssertExtensions
21+
{
22+
/// <summary>
23+
/// Verifies that the collection contains an issue with the same identifier as the expected issue.
24+
/// This is needed because IIssue is now immutable and IssuesReader returns new objects.
25+
/// </summary>
26+
public static void ShouldContainIssueWithSameIdentifier(
27+
this IEnumerable<IIssue> actualIssues,
28+
IIssue expectedIssue) =>
29+
actualIssues
30+
.Any(x => x.Identifier == expectedIssue.Identifier)
31+
.ShouldBeTrue($"Expected to find issue with identifier '{expectedIssue.Identifier}' but collection only contained: [{string.Join(", ", actualIssues.Select(x => $"'{x.Identifier}'"))}]");
32+
}

src/Cake.Issues.PullRequests.Tests/IssueFiltererTests.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void Should_Apply_Custom_Filters()
118118

119119
// Then
120120
issues.Count.ShouldBe(1);
121-
issues.ShouldContain(issue1);
121+
issues.ShouldContainIssueWithSameIdentifier(issue1);
122122
}
123123

124124
public sealed class TheFilterIssuesByPathMethod
@@ -198,7 +198,7 @@ public void Should_Filter_Issues_If_File_Is_Not_Modified()
198198

199199
// Then
200200
issues.Count.ShouldBe(1);
201-
issues.ShouldContain(issue1);
201+
issues.ShouldContainIssueWithSameIdentifier(issue1);
202202
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered because they do not belong to files that were changed in this pull request");
203203
}
204204
}
@@ -254,7 +254,7 @@ public void Should_Filter_Issues_With_Existing_Active_Comment()
254254

255255
// Then
256256
issues.Count.ShouldBe(1);
257-
issues.ShouldContain(issue2);
257+
issues.ShouldContainIssueWithSameIdentifier(issue2);
258258
}
259259

260260
[Fact]
@@ -303,7 +303,7 @@ public void Should_Filter_Issues_With_Existing_WontFix_Comment()
303303

304304
// Then
305305
issues.Count.ShouldBe(1);
306-
issues.ShouldContain(issue2);
306+
issues.ShouldContainIssueWithSameIdentifier(issue2);
307307
}
308308

309309
[Fact]
@@ -352,7 +352,7 @@ public void Should_Filter_Issues_With_Existing_Resolved_Comment()
352352

353353
// Then
354354
issues.Count.ShouldBe(1);
355-
issues.ShouldContain(issue2);
355+
issues.ShouldContainIssueWithSameIdentifier(issue2);
356356
}
357357
}
358358

@@ -398,7 +398,7 @@ public void Should_Limit_Messages_To_Maximum()
398398

399399
// Then
400400
issues.Count.ShouldBe(1);
401-
issues.ShouldContain(issue1);
401+
issues.ShouldContainIssueWithSameIdentifier(issue1);
402402
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 1");
403403
}
404404

@@ -440,7 +440,7 @@ public void Should_Limit_Messages_To_Maximum_By_Priority()
440440

441441
// Then
442442
issues.Count.ShouldBe(1);
443-
issues.ShouldContain(issue2);
443+
issues.ShouldContainIssueWithSameIdentifier(issue2);
444444
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 1");
445445
}
446446

@@ -481,7 +481,7 @@ public void Should_Limit_Messages_To_Maximum_By_FilePath()
481481

482482
// Then
483483
issues.Count.ShouldBe(1);
484-
issues.ShouldContain(issue2);
484+
issues.ShouldContainIssueWithSameIdentifier(issue2);
485485
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 1");
486486
}
487487
}
@@ -753,8 +753,8 @@ public void Should_Limit_Messages_To_Maximum_By_Priority()
753753

754754
// Then
755755
issues.Count.ShouldBe(2);
756-
issues.ShouldContain(issue2);
757-
issues.ShouldContain(issue3);
756+
issues.ShouldContainIssueWithSameIdentifier(issue2);
757+
issues.ShouldContainIssueWithSameIdentifier(issue3);
758758
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 2 across all runs for provider 'ProviderType Foo' (1 issues already posted in previous runs)");
759759
}
760760

@@ -824,8 +824,8 @@ public void Should_Limit_Messages_To_Maximum_By_FilePath()
824824

825825
// Then
826826
issues.Count.ShouldBe(2);
827-
issues.ShouldContain(issue2);
828-
issues.ShouldContain(issue4);
827+
issues.ShouldContainIssueWithSameIdentifier(issue2);
828+
issues.ShouldContainIssueWithSameIdentifier(issue4);
829829
fixture.Log.Entries.ShouldContain(x => x.Message == "2 issue(s) were filtered to match the global issue limit of 2 across all runs for provider 'ProviderType Foo' (1 issues already posted in previous runs)");
830830
}
831831
}
@@ -883,8 +883,8 @@ public void Should_Limit_Messages_To_Maximum()
883883

884884
// Then
885885
issues.Count.ShouldBe(2);
886-
issues.ShouldContain(issue1);
887-
issues.ShouldContain(issue3);
886+
issues.ShouldContainIssueWithSameIdentifier(issue1);
887+
issues.ShouldContainIssueWithSameIdentifier(issue3);
888888

889889
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeA'");
890890
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeB'");
@@ -997,10 +997,10 @@ public void Should_Ignore_Limit_When_Negative()
997997

998998
// Then
999999
issues.Count.ShouldBe(4);
1000-
issues.ShouldContain(issue1);
1001-
issues.ShouldContain(issue2);
1002-
issues.ShouldContain(issue3);
1003-
issues.ShouldContain(issue4);
1000+
issues.ShouldContainIssueWithSameIdentifier(issue1);
1001+
issues.ShouldContainIssueWithSameIdentifier(issue2);
1002+
issues.ShouldContainIssueWithSameIdentifier(issue3);
1003+
issues.ShouldContainIssueWithSameIdentifier(issue4);
10041004
}
10051005

10061006
[Fact]
@@ -1054,8 +1054,8 @@ public void Should_Limit_Messages_To_Maximum_By_Priority()
10541054

10551055
// Then
10561056
issues.Count.ShouldBe(2);
1057-
issues.ShouldContain(issue2);
1058-
issues.ShouldContain(issue3);
1057+
issues.ShouldContainIssueWithSameIdentifier(issue2);
1058+
issues.ShouldContainIssueWithSameIdentifier(issue3);
10591059
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeA'");
10601060
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeB'");
10611061
}
@@ -1109,8 +1109,8 @@ public void Should_Limit_Messages_To_Maximum_By_FilePath()
11091109

11101110
// Then
11111111
issues.Count.ShouldBe(2);
1112-
issues.ShouldContain(issue2);
1113-
issues.ShouldContain(issue3);
1112+
issues.ShouldContainIssueWithSameIdentifier(issue2);
1113+
issues.ShouldContainIssueWithSameIdentifier(issue3);
11141114
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeA'");
11151115
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global limit of 1 issues which should be reported for issue provider 'ProviderTypeB'");
11161116
}
@@ -1260,7 +1260,7 @@ public void Should_Limit_Messages_To_Maximum()
12601260

12611261
// Then
12621262
issues.Count.ShouldBe(1);
1263-
issues.ShouldContain(issue1);
1263+
issues.ShouldContainIssueWithSameIdentifier(issue1);
12641264
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 2 across all runs (1 issues already posted in previous runs)");
12651265
}
12661266

@@ -1315,7 +1315,7 @@ public void Should_Limit_Messages_To_Maximum_By_Priority()
13151315

13161316
// Then
13171317
issues.Count.ShouldBe(1);
1318-
issues.ShouldContain(issue2);
1318+
issues.ShouldContainIssueWithSameIdentifier(issue2);
13191319
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 2 across all runs (1 issues already posted in previous runs)");
13201320
}
13211321

@@ -1369,7 +1369,7 @@ public void Should_Limit_Messages_To_Maximum_By_FilePath()
13691369

13701370
// Then
13711371
issues.Count.ShouldBe(1);
1372-
issues.ShouldContain(issue2);
1372+
issues.ShouldContainIssueWithSameIdentifier(issue2);
13731373
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the global issue limit of 2 across all runs (1 issues already posted in previous runs)");
13741374
}
13751375
}
@@ -1428,8 +1428,8 @@ public void Should_Limit_Messages_To_Maximum()
14281428

14291429
// Then
14301430
issues.Count.ShouldBe(2);
1431-
issues.ShouldContain(issue1);
1432-
issues.ShouldContain(issue3);
1431+
issues.ShouldContainIssueWithSameIdentifier(issue1);
1432+
issues.ShouldContainIssueWithSameIdentifier(issue3);
14331433
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) of type ProviderTypeA were filtered to match the maximum of 1 issues which should be reported for each issue provider");
14341434
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) of type ProviderTypeB were filtered to match the maximum of 1 issues which should be reported for each issue provider");
14351435
}
@@ -1486,8 +1486,8 @@ public void Should_Limit_Messages_To_Maximum_By_Priority()
14861486

14871487
// Then
14881488
issues.Count.ShouldBe(2);
1489-
issues.ShouldContain(issue2);
1490-
issues.ShouldContain(issue3);
1489+
issues.ShouldContainIssueWithSameIdentifier(issue2);
1490+
issues.ShouldContainIssueWithSameIdentifier(issue3);
14911491
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) of type ProviderTypeA were filtered to match the maximum of 1 issues which should be reported for each issue provider");
14921492
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) of type ProviderTypeB were filtered to match the maximum of 1 issues which should be reported for each issue provider");
14931493
}
@@ -1542,8 +1542,8 @@ public void Should_Limit_Messages_To_Maximum_By_FilePath()
15421542

15431543
// Then
15441544
issues.Count.ShouldBe(2);
1545-
issues.ShouldContain(issue2);
1546-
issues.ShouldContain(issue3);
1545+
issues.ShouldContainIssueWithSameIdentifier(issue2);
1546+
issues.ShouldContainIssueWithSameIdentifier(issue3);
15471547
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) of type ProviderTypeA were filtered to match the maximum of 1 issues which should be reported for each issue provider");
15481548
fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) of type ProviderTypeB were filtered to match the maximum of 1 issues which should be reported for each issue provider");
15491549
}

0 commit comments

Comments
 (0)