FruityFoundation/Base.Tests/Extensions/MaybeExtensionTests.cs

31 lines
850 B
C#
Raw Normal View History

2021-11-19 00:12:02 -05:00
using System;
2022-02-24 19:11:28 -05:00
using FruityFoundation.Base.Extensions;
using FruityFoundation.Base.Structures;
2021-11-19 00:12:02 -05:00
using NUnit.Framework;
namespace Base.Tests.Extensions;
public class MaybeExtensionTests
{
[Test]
public void EnumerableFirstOrEmptyTests()
{
Assert.AreEqual(Maybe<string>.Empty(), Array.Empty<string>().FirstOrEmpty());
Assert.AreEqual(Maybe<string>.Create("banana"), new[] { "banana" }.FirstOrEmpty());
}
[Test]
public void TestToMaybe()
{
Assert.AreEqual(Maybe<int>.Empty(), Maybe<int>.Empty());
Assert.AreEqual(Maybe<string>.Create("banana"), "banana".ToMaybe());
Assert.AreNotEqual(Maybe<int>.Create(293921), Maybe<int>.Create(2));
}
[Test]
public void MaybeNullableTests()
{
Assert.IsNull(Maybe<int>.Empty().ToNullable());
Assert.IsNull(Maybe<int>.Create(0, _ => false).ToNullable());
}
}