From 24c6bb66ddae903697a9041ea49a34a50fceb7f6 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 29 Nov 2023 17:30:11 -0500 Subject: [PATCH] test: Validate the WhereNotNull behavior --- .../Factories/Given_WhereNotNullFactories.cs | 50 +++++++++++++++++++ .../Operators/Given_WhereFeed.CoreRules.cs | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/Uno.Extensions.Reactive.Tests/Factories/Given_WhereNotNullFactories.cs diff --git a/src/Uno.Extensions.Reactive.Tests/Factories/Given_WhereNotNullFactories.cs b/src/Uno.Extensions.Reactive.Tests/Factories/Given_WhereNotNullFactories.cs new file mode 100644 index 0000000000..e875c74ca5 --- /dev/null +++ b/src/Uno.Extensions.Reactive.Tests/Factories/Given_WhereNotNullFactories.cs @@ -0,0 +1,50 @@ +using System; +using System.Linq; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Uno.Extensions.Reactive.Testing; + +namespace Uno.Extensions.Reactive.Tests.Factories; + +[TestClass] +public class Given_WhereNotNullFactories : FeedTests +{ + public record MyObject; + public record struct MyStruct; + + [TestMethod] + public async Task When_InputIsSomeNull_Then_TreatAsNone() + { + await Feed.Async(async _ => default(MyObject?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + await Feed.Async(async _ => default(MyStruct?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + await Feed.Async(async _ => default(string?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + await Feed.Async(async _ => default(int?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + } + + [TestMethod] + public async Task When_InputIsSomeNotNull_Then_StaySome() + { + await Feed.Async(async _ => new MyObject()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Some)); + await Feed.Async(async _ => new MyStruct()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Some)); + await Feed.Async(async _ => "").WhereNotNull().Record().Should().BeAsync(m => m.Message("")); + await Feed.Async(async _ => 42).WhereNotNull().Record().Should().BeAsync(m => m.Message(42)); + } + + [TestMethod] + public async Task When_InputUndefined_Then_StayUndefined() + { + await Feed.Async(async _ => Option.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined)); + await Feed.Async(async _ => Option.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined)); + await Feed.Async(async _ => Option.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined)); + await Feed.Async(async _ => Option.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined)); + } + + [TestMethod] + public async Task When_InputIsNone_Then_StayNone() + { + await Feed.Async(async _ => Option.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + await Feed.Async(async _ => Option.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + await Feed.Async(async _ => Option.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + await Feed.Async(async _ => Option.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None)); + } +} diff --git a/src/Uno.Extensions.Reactive.Tests/Operators/Given_WhereFeed.CoreRules.cs b/src/Uno.Extensions.Reactive.Tests/Operators/Given_WhereFeed.CoreRules.cs index e2a836f231..a21d2267a8 100644 --- a/src/Uno.Extensions.Reactive.Tests/Operators/Given_WhereFeed.CoreRules.cs +++ b/src/Uno.Extensions.Reactive.Tests/Operators/Given_WhereFeed.CoreRules.cs @@ -14,7 +14,7 @@ public partial class Given_WhereFeed : FeedTests public async Task When_WhereFeed_Then_CompilesToCoreRules() => await FeedCoreRules .Using(Feed.Async(async _ => new MyRecord(42))) - .WhenFeed(src => new WhereFeed(src, _ => true)) + .WhenFeed(src => new WhereFeed(src, (MyRecord _) => true)) .Then_CompilesToCoreRules(CT); private record MyRecord(int Value);