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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to Monify will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [1.1.3] - TBC

## Fixed
- Equality checks involing an encapsulated array containing identical values now yield true (#19).
- `ToString` no longer throws a `FormatException`.

# [1.1.2] - 2025-10-20

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion build/Tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
<ExcludeByAttribute>Obsolete</ExcludeByAttribute>
<ExcludeByFile>**/*.Designer.cs</ExcludeByFile>
<NoWarn>CA1859;CA1861</NoWarn>
<NoWarn>CA1859;CA1861;IDE0039</NoWarn>
<RootNamespace>$(MSBuildProjectName.Replace('.Tests', ''))</RootNamespace>
<TargetFrameworks>net9.0</TargetFrameworks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenConstructorIsCalled
{
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenValueThenValueIsStored()
{
// Arrange
OutterForArray<int>.Inner instance = new(_sampleValue);

// Act
int[] actual = instance;

// Assert
actual.ShouldBe(_sampleValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenEqualityOperatorWithIntArrayIsCalled
{
private static readonly int[] _differentValue = [4, 5, 6];
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenSubjectIsNullThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner? subject = default;

// Act
bool actual = subject == _sampleValue;

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);

// Act
bool actual = subject == _sampleValue;

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValueThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);

// Act
bool actual = subject == _differentValue;

// Assert
actual.ShouldBeFalse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenEqualityOperatorWithOutterForArrayInnerIsCalled
{
private static readonly int[] _differentValue = [4, 5, 6];
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenBothNullThenReturnTrue()
{
// Arrange
OutterForArray<int>.Inner? left = default;
OutterForArray<int>.Inner? right = default;

// Act
bool actual = left == right;

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenLeftIsNullThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner? left = default;
OutterForArray<int>.Inner right = new(_sampleValue);

// Act
bool actual = left == right;

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
OutterForArray<int>.Inner left = new(_sampleValue);
OutterForArray<int>.Inner right = new(_sampleValue);

// Act
bool actual = left == right;

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValuesThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner left = new(_sampleValue);
OutterForArray<int>.Inner right = new(_differentValue);

// Act
bool actual = left == right;

// Assert
actual.ShouldBeFalse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenEqualsWithIntArrayIsCalled
{
private static readonly int[] _differentValue = [4, 5, 6];
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);

// Act
bool actual = subject.Equals(_sampleValue);

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValueThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);

// Act
bool actual = subject.Equals(_differentValue);

// Assert
actual.ShouldBeFalse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenEqualsWithObjectIsCalled
{
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenNullThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);

// Act
bool actual = subject.Equals((object?)default);

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenEquivalentOutterForArrayInnerThenReturnTrue()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);
object other = new OutterForArray<int>.Inner(_sampleValue);

// Act
bool actual = subject.Equals(other);

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentTypeThenThrowInvalidCastException()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);
object other = string.Empty;

// Act
Action act = () => subject.Equals(other);

// Assert
_ = Should.Throw<InvalidCastException>(act);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenEqualsWithOutterForArrayInnerIsCalled
{
private static readonly int[] _differentValue = [4, 5, 6];
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
OutterForArray<int>.Inner left = new(_sampleValue);
OutterForArray<int>.Inner right = new(_sampleValue);

// Act
bool actual = left.Equals(right);

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValueThenReturnFalse()
{
// Arrange
OutterForArray<int>.Inner left = new(_sampleValue);
OutterForArray<int>.Inner right = new(_differentValue);

// Act
bool actual = left.Equals(right);

// Assert
actual.ShouldBeFalse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenGetHashCodeIsCalled
{
private static readonly int[] _firstValue = [7, 8, 9];
private static readonly int[] _secondValue = [10, 11, 12];

[Fact]
public static void GivenSameValuesThenReturnSameHashCode()
{
// Arrange
OutterForArray<int>.Inner first = new(_firstValue);
OutterForArray<int>.Inner second = new(_firstValue);

// Act
int firstHash = first.GetHashCode();
int secondHash = second.GetHashCode();

// Assert
firstHash.ShouldBe(secondHash);
}

[Fact]
public static void GivenDifferentValuesThenReturnDifferentHashCodes()
{
// Arrange
OutterForArray<int>.Inner first = new(_firstValue);
OutterForArray<int>.Inner second = new(_secondValue);

// Act
int firstHash = first.GetHashCode();
int secondHash = second.GetHashCode();

// Assert
firstHash.ShouldNotBe(secondHash);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenImplicitOperatorFromIntArrayIsCalled
{
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenValueThenReturnsEquivalentInstance()
{
// Arrange
OutterForArray<int>.Inner result = _sampleValue;

// Act
int[] actual = result;

// Assert
actual.ShouldBe(_sampleValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Monify.Console.Classes.Nested.InClass.OutterForArrayTests.InnerTests;

public static class WhenImplicitOperatorToIntArrayIsCalled
{
private static readonly int[] _sampleValue = [1, 2, 3];

[Fact]
public static void GivenNullSubjectThenThrowsArgumentNullException()
{
// Arrange
OutterForArray<int>.Inner? subject = default;

// Act
Action act = () => _ = (int[])subject!;

// Assert
ArgumentNullException exception = Should.Throw<ArgumentNullException>(act);
exception.ParamName.ShouldBe(nameof(subject));
}

[Fact]
public static void GivenValidSubjectThenReturnsValue()
{
// Arrange
OutterForArray<int>.Inner subject = new(_sampleValue);

// Act
int[] actual = subject;

// Assert
actual.ShouldBe(_sampleValue);
}
}
Loading