public async Task Async_WhenSome_ReturnsMappedResult() { const int expected = 5; var result = await AsyncMaybe <int> .Some(2).MapAsync(some => Task.FromResult(some + 3)).OrFail(); Assert.Equal(expected, result); }
public async Task WhenFirstIsSome_AndSecondIsSome_AndThirdIsSome_AndFourthIsSome_UsingMethodReference_ReturnsSome() { const int firstValue = 23; var first = AsyncMaybe <int> .Some(firstValue); const int secondValue = 6589; var second = AsyncMaybe <int> .Some(secondValue); const int thirdValue = 2136589; var third = AsyncMaybe <int> .Some(thirdValue); const int fourthValue = 547894; var fourth = AsyncMaybe <int> .Some(fourthValue); ValueTuple <int, int, int, int> Zipper(int f, int s, int t, int f4) => (f, s, t, f4); var result = await first.Zip(second, third, fourth, Zipper); var value = result.MustBeSome(); Assert.Equal(firstValue, value.Item1); Assert.Equal(secondValue, value.Item2); Assert.Equal(thirdValue, value.Item3); Assert.Equal(fourthValue, value.Item4); }
public async Task Sync_ReturningAsyncNoneUsingLambda_UsingNoArgs_WhenSome_ReturnsNone() { // ReSharper disable once ConvertClosureToMethodGroup var source = await AsyncMaybe <Unit> .Some(new Unit()).FlatMapUnit(() => AsyncMaybe <int> .None()); source.MustBeNone(); }
public async Task WhenAllAreSome_UsingMethodReference_ReturnsSome() { const int firstValue = 23; var first = AsyncMaybe <int> .Some(firstValue); const int secondValue = 6589; var second = AsyncMaybe <int> .Some(secondValue); const int thirdValue = 236589; var third = AsyncMaybe <int> .Some(thirdValue); const int fourthValue = 1236589; var fourth = AsyncMaybe <int> .Some(fourthValue); Task <ValueTuple <int, int, int, int> > Zipper(int v1, int v2, int v3, int v4) => Task.FromResult((v1, v2, v3, v4)); var result = await first.ZipAsync(second, third, fourth, Zipper); var value = result.MustBeSome(); Assert.Equal(firstValue, value.Item1); Assert.Equal(secondValue, value.Item2); Assert.Equal(thirdValue, value.Item3); Assert.Equal(fourthValue, value.Item4); }
public async Task WithLambdas() { var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some => { }, none : () => { }); Assert.Equal(Unit(), result); }
public async Task WithLambdas() { var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some => Task.CompletedTask, () => Task.CompletedTask); Assert.Equal(Unit(), result); }
public async Task WithLambdas() { var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some => Task.FromResult(some + 1), none => 0); Assert.Equal(2, result); }
public async Task Some() { var source = AsyncMaybe <object> .Some(1); var isSome = await source.IsSome; Assert.True(isSome); }
public async Task OnNone_WithAsyncSome_ReturnsOther() { const int expected = 34; var source = await AsyncMaybe <int> .None().Or(AsyncMaybe <int> .Some(expected)); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_WithMethodReferenceReturningAsyncNone_ReturnsSelf() { const int expected = 34; var source = await AsyncMaybe <int> .Some(expected).Or(AsyncMaybe <int> .None); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_WithAsyncSome_ReturnsSelf() { const int expected = 34; var source = await AsyncMaybe <int> .Some(expected).OrAsync(Task.FromResult(AsyncMaybe <int> .Some(545))); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task WithAsyncSomeSome_ReturnsResultOfSome() { const int expected = 3; var source = await AsyncMaybe <int> .Some(1).Map(it => AsyncMaybe <int> .Some(3)).Flatten(); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_WithLambdaReturningAsyncSome_ReturnsSelf() { const int expected = 34; var source = await AsyncMaybe <int> .Some(expected).Or(() => AsyncMaybe <int> .Some(545)); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task Sync_ReturningSome_UsingNoArgs_WhenSome_ReturnsSome() { const int expected = 3; var source = await AsyncMaybe <Unit> .Some(new Unit()).FlatMapUnit(() => Maybe <int> .Some(expected)); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task WithSomeReference_AndNoneLambda() { Task <int> MatchSome(int some) => Task.FromResult(some + 1); var source = AsyncMaybe <int> .Some(1); var result = await source.Match(someAsync : MatchSome, none : none => 0); Assert.Equal(2, result); }
public async Task WithSomeLambda_AndNoneReference() { int MatchNone(None none) => 0; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some => Task.FromResult(some + 1), none : MatchNone); Assert.Equal(2, result); }
public async Task WithSomeReference_AndNoneLambda() { Task MatchSome(int some) => Task.CompletedTask; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(someAsync : MatchSome, noneAsync : () => Task.CompletedTask); Assert.Equal(Unit(), result); }
public async Task WithSomeLambda_AndNoneReference() { Task MatchNone(None none) => Task.CompletedTask; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(someAsync : some => Task.CompletedTask, noneAsync : MatchNone); Assert.Equal(Unit(), result); }
public async Task Async_OnSome_ReturnsSameAsMapAsync() { var source = AsyncMaybe <int> .Some(3); var where = await source.SelectAsync(it => Task.FromResult(it * 2)); var map = await source.MapAsync(it => Task.FromResult(it * 2)); Assert.Equal(where, map); }
public async Task Some_Select_ReturnsSameAsMap() { var source = AsyncMaybe <int> .Some(5); var where = await source.Select(it => { }); var map = await source.Map(it => { }); Assert.Equal(where, map); }
public async Task WithSomeLambda_AndNoneReference() { Task <int> MatchNone() => Task.FromResult(0); var source = AsyncMaybe <int> .Some(1); var result = await source.MatchAsync(some => Task.FromResult(some + 1), MatchNone); Assert.Equal(2, result); }
public async Task WithSomeReference_AndNoneLambda() { int MatchSome(int some) => some + 1; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some : MatchSome, none : () => 0); Assert.Equal(2, result); }
public async Task Some_Map_ActionLambda_ReturnsSomeUnit() { var source = AsyncMaybe <int> .Some(5); var result = await source.MapAsync(() => Task.CompletedTask); var unit = result.MustBeSome(); Assert.IsType <Unit>(unit); }
public async Task Some_Map_Action_T__ActionIsInvokedOnlyOnce() { var rec = new Recorder(); var source = AsyncMaybe <int> .Some(5); var result = await source.MapAsync(rec.Record((int it) => Task.CompletedTask)); result.MustBeSome(); rec.MustHaveExactly(1.Invocations()); }
public async Task WithReferences() { Task <int> MatchSome(int some) => Task.FromResult(some + 1); Task <int> MatchNone() => Task.FromResult(0); var source = AsyncMaybe <int> .Some(1); var result = await source.MatchAsync(MatchSome, MatchNone); Assert.Equal(2, result); }
public async Task WhenFirstIsNone_AndSecondIsSome_UsingLambda_ReturnsNone() { var first = AsyncMaybe <int> .None(); const int secondValue = 6589; var second = AsyncMaybe <int> .Some(secondValue); var result = await first.Zip(second, (f, s) => (first : f, second : s)); result.MustBeNone(); }
public async Task WithReferences() { Task <int> MatchSome(int some) => Task.FromResult(some + 1); int MatchNone(None none) => 0; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(someAsync : MatchSome, none : MatchNone); Assert.Equal(2, result); }
public async Task OnSome_WithLambdaReturningAsyncNone_ReturnsSelf() { const int expected = 34; // ReSharper disable once ConvertClosureToMethodGroup var source = await AsyncMaybe <int> .Some(expected).Or(() => AsyncMaybe <int> .None()); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task WithReferences() { int MatchSome(int some) => some + 1; int MatchNone() => 0; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some : MatchSome, none : MatchNone); Assert.Equal(2, result); }
public async Task WhenSome_ReturnsSingleItemEnumerable() { const int expectedValue = 230023; var source = AsyncMaybe <int> .Some(expectedValue); var result = await source.ToEnumerable(); var value = Assert.Single(result); Assert.Equal(expectedValue, value); }