-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathAsyncResultOfTTests.cs
More file actions
59 lines (47 loc) · 1.66 KB
/
AsyncResultOfTTests.cs
File metadata and controls
59 lines (47 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions.With
{
public class AsyncResultOfTTests
{
[Fact]
public async Task Successful_results_are_combined_with_mapping()
{
var r1 = Result.Success(1);
var r2 = Result.Success("hola");
var actual = await r1
.WithMap(r2, (a, b) => Task.FromResult(a + b));
actual.IsSuccess.Should().BeTrue();
actual.Value.Should().Be("1hola");
}
[Fact]
public async Task Successful_results_are_combined_with_binding()
{
var r1 = Result.Success(1);
var r2 = Result.Success("hola");
var actual = await r1
.WithBind(r2, (a, b) => Task.FromResult(Result.Success(a + b)));
actual.IsSuccess.Should().BeTrue();
actual.Value.Should().Be("1hola");
}
[Fact]
public async Task Successful_results_are_combined_into_success()
{
var r1 = Result.Success(1);
var r2 = Result.Success("hola");
var actual = await r1
.WithBind(r2, (a, b) => Task.FromResult(Result.Success()));
actual.IsSuccess.Should().BeTrue();
}
[Fact]
public async Task Failures_are_combined_into_failure()
{
var r1 = Result.Failure<int>("Failed");
var r2 = Result.Success("hola");
var actual = await r1
.WithBind(r2, (a, b) => Task.FromResult(Result.Success()));
actual.IsSuccess.Should().BeFalse();
}
}
}