Skip to content

Commit

Permalink
Merge pull request #68 from BoBoBaSs84/feature/add-some-null-checks
Browse files Browse the repository at this point in the history
feat: add some null checks
  • Loading branch information
BoBoBaSs84 authored Dec 21, 2023
2 parents 8d22a3e + 15aeaa1 commit e3567fb
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<VersionMajor>1</VersionMajor>
<VersionMinor>8</VersionMinor>
<VersionPatch>0</VersionPatch>
<VersionPatch>1</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix Condition="$(Configuration.Equals('Debug'))">Development</VersionSuffix>
</PropertyGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/BB84.Extensions/BooleanExtensions.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BB84.Extensions;

public static partial class BooleanExtensions
{
/// <summary>
/// Indicates whether the specified boolean is null.
/// </summary>
/// <param name="value">The boolean value to test.</param>
/// <returns><see langword="true"/> if the <paramref name="value"/>
/// is <see langword="null"/>, otherwise <see langword="false"/>.</returns>
public static bool IsNull(this bool? value)
=> value.HasValue.Equals(false);
}
13 changes: 13 additions & 0 deletions src/BB84.Extensions/ByteExtensions.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BB84.Extensions;

public static partial class ByteExtensions
{
/// <summary>
/// Indicates whether the specified byte array is null.
/// </summary>
/// <param name="value">The byte array value to test.</param>
/// <returns><see langword="true"/> if the <paramref name="value"/>
/// is <see langword="null"/>, otherwise <see langword="false"/>.</returns>
public static bool IsNull(this byte[]? value)
=> value is null;
}
13 changes: 13 additions & 0 deletions src/BB84.Extensions/FloatExtensions.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BB84.Extensions;

public static partial class FloatExtensions
{
/// <summary>
/// Indicates whether the specified float is null.
/// </summary>
/// <param name="value">The float value to test.</param>
/// <returns><see langword="true"/> if the <paramref name="value"/>
/// is <see langword="null"/>, otherwise <see langword="false"/>.</returns>
public static bool IsNull(this float? value)
=> value.HasValue.Equals(false);
}
7 changes: 7 additions & 0 deletions src/BB84.Extensions/FloatExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BB84.Extensions;

/// <summary>
/// The float extensions class.
/// </summary>
public static partial class FloatExtensions
{ }
13 changes: 13 additions & 0 deletions src/BB84.Extensions/IntegerExtensions.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BB84.Extensions;

public static partial class IntegerExtensions
{
/// <summary>
/// Indicates whether the specified integer is null.
/// </summary>
/// <param name="value">The integer value to test.</param>
/// <returns><see langword="true"/> if the <paramref name="value"/>
/// is <see langword="null"/>, otherwise <see langword="false"/>.</returns>
public static bool IsNull(this int? value)
=> value.HasValue.Equals(false);
}
21 changes: 11 additions & 10 deletions src/BB84.Extensions/StringExtensions.IsNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ public static partial class StringExtensions
/// <summary>
/// Indicates whether the specified string is null.
/// </summary>
/// <param name="stringValue">The string value to test.</param>
/// <returns>True if the value parameter is null, otherwise false.</returns>
public static bool IsNull(this string stringValue)
=> stringValue is null;
/// <param name="value">The string value to test.</param>
/// <returns><see langword="true"/> if the <paramref name="value"/>
/// is <see langword="null"/>, otherwise <see langword="false"/>.</returns>
public static bool IsNull(this string value)
=> value is null;

/// <summary>
/// Indicates whether the specified string is null or an <see cref="string.Empty"/> string.
/// </summary>
/// <param name="stringValue">The string value to test.</param>
/// <param name="value">The string value to test.</param>
/// <returns>True if the value parameter is null or an empty string, otherwise false.</returns>
public static bool IsNullOrEmpty(this string stringValue)
=> string.IsNullOrEmpty(stringValue);
public static bool IsNullOrEmpty(this string value)
=> string.IsNullOrEmpty(value);

/// <summary>
/// Indicates whether a specified string is null, empty, or consists only of white-space
/// characters.
/// </summary>
/// <param name="stringValue">The string value to test.</param>
/// <param name="value">The string value to test.</param>
/// <returns>True if the value parameter is null or an empty string or if value consists
/// exclusively of white-space characters, otherwise false.</returns>
public static bool IsNullOrWhiteSpace(this string stringValue)
=> string.IsNullOrWhiteSpace(stringValue);
public static bool IsNullOrWhiteSpace(this string value)
=> string.IsNullOrWhiteSpace(value);
}
12 changes: 12 additions & 0 deletions tests/BB84.ExtensionsTests/BooleanExtensionsTests.IsFalse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;

public partial class BooleanExtensionsTests
{
[DataTestMethod]
[DataRow(true, false)]
[DataRow(false, true)]
public void IsFalseTest(bool value, bool expected)
=> Assert.AreEqual(expected, value.IsFalse());
}
13 changes: 13 additions & 0 deletions tests/BB84.ExtensionsTests/BooleanExtensionsTests.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;

public partial class BooleanExtensionsTests
{
[DataTestMethod]
[DataRow(true, false)]
[DataRow(false, false)]
[DataRow(null, true)]
public void IsNullTest(bool? value, bool expected)
=> Assert.AreEqual(expected, value.IsNull());
}
12 changes: 12 additions & 0 deletions tests/BB84.ExtensionsTests/BooleanExtensionsTests.IsTrue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;

public partial class BooleanExtensionsTests
{
[DataTestMethod]
[DataRow(true, true)]
[DataRow(false, false)]
public void IsTrueTest(bool value, bool expected)
=> Assert.AreEqual(expected, value.IsTrue());
}
28 changes: 3 additions & 25 deletions tests/BB84.ExtensionsTests/BooleanExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;
namespace BB84.ExtensionsTests;

[TestClass]
public class BooleanExtensionsTests
{
[TestMethod]
public void IsTrueTest()
{
bool value = true;

bool result = value.IsTrue();

Assert.IsTrue(result);
}

[TestMethod]
public void IsFalseTest()
{
bool value = false;

bool result = value.IsFalse();

Assert.IsTrue(result);
}
}
public partial class BooleanExtensionsTests
{ }
14 changes: 14 additions & 0 deletions tests/BB84.ExtensionsTests/ByteExtensionsTests.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;

public partial class ByteExtensionsTests
{
[DataTestMethod]
[DataRow(new byte[] { 0 }, false)]
[DataRow(null, true)]
public void IsNullTest(byte[]? value, bool expected)
{
Assert.AreEqual(expected, value.IsNull());
}
}
12 changes: 12 additions & 0 deletions tests/BB84.ExtensionsTests/FloatExtensionsTests.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;

public partial class FloatExtensionsTests
{
[DataTestMethod]
[DataRow(1.67f, false)]
[DataRow(null, true)]
public void IsNullTest(float? value, bool expected)
=> Assert.AreEqual(expected, value.IsNull());
}
5 changes: 5 additions & 0 deletions tests/BB84.ExtensionsTests/FloatExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BB84.ExtensionsTests;

[TestClass]
public partial class FloatExtensionsTests
{ }
12 changes: 12 additions & 0 deletions tests/BB84.ExtensionsTests/IntegerExtensionsTests.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BB84.Extensions;

namespace BB84.ExtensionsTests;

public sealed partial class IntegerExtensionsTests
{
[DataTestMethod]
[DataRow(1, false)]
[DataRow(null, true)]
public void IsNullTest(int? value, bool expected)
=> Assert.AreEqual(expected, value.IsNull());
}

0 comments on commit e3567fb

Please sign in to comment.