Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Extensions.Test/EnumerableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ public void JoinThrowsArgumentNullExceptionWhenSeparatorIsNull()
Assert.ThrowsExactly<ArgumentNullException>(() => items.Join(separator));
}

[TestMethod]
[DataRow(NullItemHandling.Remove)]
[DataRow(NullItemHandling.Include)]
[DataRow(NullItemHandling.Throw)]
public void JoinWithNullItemHandlingThrowsArgumentNullExceptionWhenSeparatorIsNull(NullItemHandling nullItemHandling)
{
// Arrange
List<string> items = ["a", "b", "c"];
string separator = null!;

// Act & Assert
ArgumentNullException exception = Assert.ThrowsExactly<ArgumentNullException>(() => items.Join(separator, nullItemHandling));
Assert.AreEqual("separator", exception.ParamName);
}

[TestMethod]
public void JoinWithNullItemHandlingRemoveRemovesNullItems()
{
Expand Down
7 changes: 7 additions & 0 deletions Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#pragma warning disable KTSU0004 // Use Ensure.NotNull instead of manual null check
if (items is null)
{
throw new ArgumentNullException(nameof(items), "Items cannot be null.");

Check warning on line 33 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Define a constant instead of using this literal 'Items cannot be null.' 7 times.

Check warning on line 33 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Define a constant instead of using this literal 'Items cannot be null.' 7 times.

Check warning on line 33 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Define a constant instead of using this literal 'Items cannot be null.' 7 times.

Check warning on line 33 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Define a constant instead of using this literal 'Items cannot be null.' 7 times.
}
#pragma warning restore KTSU0004 // Use Ensure.NotNull instead of manual null check

Expand Down Expand Up @@ -203,7 +203,7 @@

if (nullItemHandling is NullItemHandling.Throw)
{
if (items.AnyNull())

Check warning on line 206 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Merge this if statement with the enclosing one.

Check warning on line 206 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Merge this if statement with the enclosing one.

Check warning on line 206 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Merge this if statement with the enclosing one.

Check warning on line 206 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Merge this if statement with the enclosing one.
{
throw new InvalidOperationException("The enumerable contains a null item.");
}
Expand Down Expand Up @@ -259,9 +259,16 @@
}
#pragma warning restore KTSU0004 // Use Ensure.NotNull instead of manual null check

#pragma warning disable KTSU0004 // Use Ensure.NotNull instead of manual null check
if (separator is null)
{
throw new ArgumentNullException(nameof(separator), "Separator cannot be null.");
}
#pragma warning restore KTSU0004 // Use Ensure.NotNull instead of manual null check

if (nullItemHandling is NullItemHandling.Throw)
{
if (items.AnyNull())

Check warning on line 271 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Merge this if statement with the enclosing one.

Check warning on line 271 in Extensions/EnumerableExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Merge this if statement with the enclosing one.
{
throw new InvalidOperationException("The enumerable contains a null item.");
}
Expand Down
Loading