From b1578d414c1e09810726716978dcad74d217b76d Mon Sep 17 00:00:00 2001 From: Kyle Ratti Date: Fri, 3 May 2024 17:14:30 -0400 Subject: [PATCH] test: cover additional Maybe extension methods --- Base.Tests/Structures/MaybeExtensionTests.cs | 42 ++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/Base.Tests/Structures/MaybeExtensionTests.cs b/Base.Tests/Structures/MaybeExtensionTests.cs index cc1814b..e3390bf 100644 --- a/Base.Tests/Structures/MaybeExtensionTests.cs +++ b/Base.Tests/Structures/MaybeExtensionTests.cs @@ -9,10 +9,46 @@ namespace Base.Tests.Structures; public class MaybeExtensionTests { [Test] - public void EnumerableFirstOrEmptyTests() + public void Enumerable_FirstOrEmpty_WithEmptyEnumerable_ReturnsEmptyMaybe() { - Assert.That(Array.Empty().FirstOrEmpty(), Is.EqualTo(Maybe.Empty())); - Assert.That(new[] { "banana" }.FirstOrEmpty(), Is.EqualTo(Maybe.Create("banana"))); + // Arrange + var data = Array.Empty(); + + // Act + var result = data.FirstOrEmpty(); + + // Assert + Assert.That(result, Is.InstanceOf>()); + 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>()); + 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>()); + Assert.That(result.HasValue, Is.False); } [Test]