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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Monify.Console.Classes.Simple.SimpleForIntTests;

public static class WhenConstructorIsCalled
{
private const int SampleValue = 42;

[Fact]
public static void GivenValueThenValueIsStored()
{
// Arrange
SimpleForInt 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.Simple.SimpleForIntTests;

public static class WhenEqualityOperatorWithIntIsCalled
{
private const int SampleValue = 101;
private const int DifferentValue = 202;

[Fact]
public static void GivenSubjectIsNullThenReturnFalse()
{
// Arrange
SimpleForInt? subject = default;

// Act
bool actual = subject == SampleValue;

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
SimpleForInt subject = new(SampleValue);

// Act
bool actual = subject == SampleValue;

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValueThenReturnFalse()
{
// Arrange
SimpleForInt 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.Simple.SimpleForIntTests;

public static class WhenEqualityOperatorWithSimpleForIntIsCalled
{
private const int SampleValue = 14;
private const int DifferentValue = 17;

[Fact]
public static void GivenBothNullThenReturnTrue()
{
// Arrange
SimpleForInt? left = default;
SimpleForInt? right = default;

// Act
bool actual = left == right;

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenLeftIsNullThenReturnFalse()
{
// Arrange
SimpleForInt? left = default;
SimpleForInt right = new(SampleValue);

// Act
bool actual = left == right;

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
SimpleForInt left = new(SampleValue);
SimpleForInt right = new(SampleValue);

// Act
bool actual = left == right;

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValuesThenReturnFalse()
{
// Arrange
SimpleForInt left = new(SampleValue);
SimpleForInt 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.Simple.SimpleForIntTests;

public static class WhenEqualsWithIntIsCalled
{
private const int SampleValue = 36;
private const int DifferentValue = 12;

[Fact]
public static void GivenSameValueThenReturnTrue()
{
// Arrange
SimpleForInt subject = new(SampleValue);

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

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentValueThenReturnFalse()
{
// Arrange
SimpleForInt 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.Simple.SimpleForIntTests;

public static class WhenEqualsWithObjectIsCalled
{
private const int SampleValue = 28;

[Fact]
public static void GivenNullThenReturnFalse()
{
// Arrange
SimpleForInt subject = new(SampleValue);

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

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenEquivalentSimpleForIntThenReturnTrue()
{
// Arrange
SimpleForInt subject = new(SampleValue);
object other = new SimpleForInt(SampleValue);

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

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenDifferentTypeThenThrowInvalidCastException()
{
// Arrange
SimpleForInt 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,49 @@
namespace Monify.Console.Classes.Simple.SimpleForIntTests;

public static class WhenEqualsWithSimpleForIntIsCalled
{
private const int SampleValue = 51;
private const int DifferentValue = 5;

[Fact]
public static void GivenOtherHasSameValueThenReturnTrue()
{
// Arrange
SimpleForInt subject = new(SampleValue);
SimpleForInt other = new(SampleValue);

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

// Assert
actual.ShouldBeTrue();
}

[Fact]
public static void GivenOtherIsNullThenReturnFalse()
{
// Arrange
SimpleForInt subject = new(SampleValue);
SimpleForInt? other = default;

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

// Assert
actual.ShouldBeFalse();
}

[Fact]
public static void GivenOtherHasDifferentValueThenReturnFalse()
{
// Arrange
SimpleForInt subject = new(SampleValue);
SimpleForInt other = new(DifferentValue);

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

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

public static class WhenGetHashCodeIsCalled
{
private const int FirstValue = 3;
private const int SecondValue = 4;

[Fact]
public static void GivenSameValuesThenReturnSameHashCode()
{
// Arrange
SimpleForInt first = new(FirstValue);
SimpleForInt second = new(FirstValue);

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

// Assert
firstHash.ShouldBe(secondHash);
}

[Fact]
public static void GivenDifferentValuesThenReturnDifferentHashCodes()
{
// Arrange
SimpleForInt first = new(FirstValue);
SimpleForInt 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.Simple.SimpleForIntTests;

public static class WhenImplicitOperatorFromIntIsCalled
{
private const int SampleValue = 77;

[Fact]
public static void GivenValueThenReturnsEquivalentInstance()
{
// Arrange
SimpleForInt 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.Simple.SimpleForIntTests;

public static class WhenImplicitOperatorToIntIsCalled
{
private const int SampleValue = 42;

[Fact]
public static void GivenNullSubjectThenThrowsArgumentNullException()
{
// Arrange
SimpleForInt? subject = default;

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

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

[Fact]
public static void GivenValidSubjectThenReturnsValue()
{
// Arrange
SimpleForInt subject = new(SampleValue);

// Act
int actual = subject;

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