-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathCombineSequentialMethodTests.cs
More file actions
77 lines (63 loc) · 3.3 KB
/
CombineSequentialMethodTests.cs
File metadata and controls
77 lines (63 loc) · 3.3 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
using static CSharpFunctionalExtensions.Tests.ResultTests.CombineWithErrorMethodTests;
namespace CSharpFunctionalExtensions.Tests.ResultTests
{
public class CombineSequentialMethodTests
{
[Fact]
public async Task CombineSequential_execute_all_functions_when_all_are_success()
{
var firstReturnValue = 12;
var secondReturnValue = "value";
Task<Result<int>> FirstFunction() => Task.FromResult(Result.Success(firstReturnValue));
Task<Result<string>> SecondFunction() => Task.FromResult(Result.Success(secondReturnValue));
var result = await Result.CombineSequential(FirstFunction,
SecondFunction,
values => new
{
values.DataA,
values.DataB
});
result.IsSuccess.Should().BeTrue();
result.Value.DataA.Should().Be(firstReturnValue);
result.Value.DataB.Should().Be(secondReturnValue);
}
[Fact]
public async Task CombineSequential_execute_first_functions_when_it_fails()
{
var errorValue = "First function error";
Task<Result<int>> FirstFunction() => Task.FromResult(Result.Failure<int>(errorValue));
Task<Result<string>> SecondFunction() => Task.FromResult(Result.Success("value"));
var result = await Result.CombineSequential(FirstFunction,
SecondFunction,
values => new
{
values.DataA,
values.DataB
});
result.IsSuccess.Should().BeFalse();
result.Error.Should().Be(errorValue);
}
[Fact]
public async Task CombineSequential_execute_all_functions_when_second_fails()
{
var errorValue = "Second function error";
Task<Result<string>> FirstFunction() => Task.FromResult(Result.Success("value"));
Task<Result<int>> SecondFunction() => Task.FromResult(Result.Failure<int>(errorValue));
var result = await Result.CombineSequential(FirstFunction,
SecondFunction,
values => new
{
values.DataA,
values.DataB
});
result.IsSuccess.Should().BeFalse();
result.Error.Should().Be(errorValue);
}
}
}