test: cover additional Maybe extension methods

This commit is contained in:
Kyle Ratti 2024-05-03 17:14:30 -04:00
parent d2a5e2850b
commit b1578d414c
No known key found for this signature in database
GPG Key ID: 4D429B6287C68DD9

View File

@ -9,10 +9,46 @@ namespace Base.Tests.Structures;
public class MaybeExtensionTests public class MaybeExtensionTests
{ {
[Test] [Test]
public void EnumerableFirstOrEmptyTests() public void Enumerable_FirstOrEmpty_WithEmptyEnumerable_ReturnsEmptyMaybe()
{ {
Assert.That(Array.Empty<string>().FirstOrEmpty(), Is.EqualTo(Maybe.Empty<string>())); // Arrange
Assert.That(new[] { "banana" }.FirstOrEmpty(), Is.EqualTo(Maybe.Create<string>("banana"))); var data = Array.Empty<int>();
// Act
var result = data.FirstOrEmpty();
// Assert
Assert.That(result, Is.InstanceOf<Maybe<int>>());
Assert.That(result.HasValue, Is.False);
}
[Test]
public void Enumerable_FirstOrEmpty_WithMatchingPredicate_ReturnsMaybeWithValue()
{
// Arrange
var data = new[] { 1, 2, 3, 4 };
// Act
var result = data.FirstOrEmpty(x => x > 1);
// Assert
Assert.That(result, Is.InstanceOf<Maybe<int>>());
Assert.That(result.HasValue, Is.True);
Assert.That(result.Value, Is.EqualTo(2));
}
[Test]
public void Enumerable_FirstOrEmpty_WithNonMatchingPredicate_ReturnsEmptyMaybe()
{
// Arrange
var data = new[] { 1, 2, 3, 4 };
// Act
var result = data.FirstOrEmpty(x => x > 100);
// Assert
Assert.That(result, Is.InstanceOf<Maybe<int>>());
Assert.That(result.HasValue, Is.False);
} }
[Test] [Test]