Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzehdee committed Oct 21, 2023
1 parent b82d946 commit f8e646a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions bzTorrent.Tests/Extensions/ExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using FluentAssertions;
using System;
using System.Diagnostics;
using bzTorrent.Helpers;
using Xunit;
using bzTorrent.Data;
using bzTorrent.Extensions;
using System.Collections.Generic;

namespace bzTorrent.Tests.Extensions
{
public class ExtensionsTests
{
[Fact]
public void IsNullOrEmptyReturnsTrueForEmptyArray()
{
Array.Empty<object>().IsNullOrEmpty().Should().BeTrue();
}

[Fact]
public void IsNullOrEmptyReturnsFalseForArrayWithObjects()
{
var array = new List<object>() { new object(), new object(), new object() };
array.IsNullOrEmpty().Should().BeFalse();
}

[Fact]
public void IsNullOrEmptyReturnsTrueForNullCastedToArray()
{
var nullArray = (object[])null;
nullArray.IsNullOrEmpty().Should().BeTrue();
}

[Fact]
public void ThrowIfNullThrowsExceptionForNull()
{
object x = null;
var ex = Record.Exception(() => x.ThrowIfNull(nameof(x)));
Assert.NotNull(ex);
}

[Fact]
public void ThrowIfNullDoesNotThrowExceptionForValidObject()
{
object x = new();
var ex = Record.Exception(() => x.ThrowIfNull(nameof(x)));
Assert.Null(ex);
}
}
}
2 changes: 1 addition & 1 deletion bzTorrent/Extensions/ArgumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void ThrowIfNullOrEmpty<T>(this IEnumerable<T> source, string para
{
if (source.IsNullOrEmpty())
{
throw new ArgumentNullException("Enumerable cannot be null or empty", paramName);
throw new ArgumentNullException(paramName, "Cannot be null or empty");
}
}
}
Expand Down

0 comments on commit f8e646a

Please sign in to comment.