From f8e646a0fda0296e92920ae042d100b67918fb27 Mon Sep 17 00:00:00 2001 From: Darren Horrocks Date: Sat, 21 Oct 2023 22:51:25 +0100 Subject: [PATCH] more tests --- bzTorrent.Tests/Extensions/ExtensionsTests.cs | 50 +++++++++++++++++++ bzTorrent/Extensions/ArgumentExtensions.cs | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 bzTorrent.Tests/Extensions/ExtensionsTests.cs diff --git a/bzTorrent.Tests/Extensions/ExtensionsTests.cs b/bzTorrent.Tests/Extensions/ExtensionsTests.cs new file mode 100644 index 0000000..96eca4f --- /dev/null +++ b/bzTorrent.Tests/Extensions/ExtensionsTests.cs @@ -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().IsNullOrEmpty().Should().BeTrue(); + } + + [Fact] + public void IsNullOrEmptyReturnsFalseForArrayWithObjects() + { + var array = new List() { 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); + } + } +} diff --git a/bzTorrent/Extensions/ArgumentExtensions.cs b/bzTorrent/Extensions/ArgumentExtensions.cs index 8d52dfe..0287d7d 100644 --- a/bzTorrent/Extensions/ArgumentExtensions.cs +++ b/bzTorrent/Extensions/ArgumentExtensions.cs @@ -47,7 +47,7 @@ public static void ThrowIfNullOrEmpty(this IEnumerable 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"); } } }