Skip to content

Commit

Permalink
test: Validate the WhereNotNull behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Nov 30, 2023
1 parent 3ede0f2 commit 24c6bb6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<MyObject?>.Async(async _ => default(MyObject?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
await Feed<MyStruct?>.Async(async _ => default(MyStruct?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
await Feed<string?>.Async(async _ => default(string?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
await Feed<int?>.Async(async _ => default(int?)).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
}

[TestMethod]
public async Task When_InputIsSomeNotNull_Then_StaySome()
{
await Feed<MyObject?>.Async(async _ => new MyObject()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Some));
await Feed<MyStruct?>.Async(async _ => new MyStruct()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Some));
await Feed<string?>.Async(async _ => "").WhereNotNull().Record().Should().BeAsync(m => m.Message(""));
await Feed<int?>.Async(async _ => 42).WhereNotNull().Record().Should().BeAsync(m => m.Message(42));
}

[TestMethod]
public async Task When_InputUndefined_Then_StayUndefined()
{
await Feed<MyObject?>.Async(async _ => Option<MyObject?>.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined));
await Feed<MyStruct?>.Async(async _ => Option<MyStruct?>.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined));
await Feed<string?>.Async(async _ => Option<string?>.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined));
await Feed<int?>.Async(async _ => Option<int?>.Undefined()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.Undefined));
}

[TestMethod]
public async Task When_InputIsNone_Then_StayNone()
{
await Feed<MyObject?>.Async(async _ => Option<MyObject?>.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
await Feed<MyStruct?>.Async(async _ => Option<MyStruct?>.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
await Feed<string?>.Async(async _ => Option<string?>.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
await Feed<int?>.Async(async _ => Option<int?>.None()).WhereNotNull().Record().Should().BeAsync(m => m.Message(Data.None));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyRecord>(src, _ => true))
.WhenFeed(src => new WhereFeed<MyRecord>(src, (MyRecord _) => true))
.Then_CompilesToCoreRules(CT);

private record MyRecord(int Value);
Expand Down

0 comments on commit 24c6bb6

Please sign in to comment.