Esempio n. 1
0
    public void Tee_runs_function_and_returns_input()
    {
        var p = new TestPerformerService();

        var actual = TestPerformerService.Start
                     .Tee(a => p.Do(1))
                     .Tee(() => p.Do(2));

        Assert.Same("Hello World", actual);
    }
Esempio n. 2
0
    public async Task TeeAsync_awaits_as_needed_and_runs_functions_in_order()
    {
        var p = new TestPerformerService();

        var actual = await TestPerformerService.Start
                     .TeeAsync(i => p.DoAsync(1))
                     .TeeAsync(() => p.DoAsync(2))
                     .TeeAsync(() => p.Do(3))
                     .TeeAsync(i => p.Do(4));

        Assert.Equal("Hello World", actual);

        p.Reset();

        var actual2 = await TestPerformerService.Start
                      .TeeAsync(() => p.DoAsync(1));

        Assert.Equal("Hello World", actual2);
    }
Esempio n. 3
0
    public async Task TypedTeeAsync_tests()
    {
        var p = new TestPerformerService();

        var newOkResult = await Result.Ok(string.Empty)
                          .TeeOnSuccessAsync(r => p.DoAsync(1))
                          .TeeOnFailureAsync(() => p.DoAsync(1))
                          .TeeOnFailureAsync(failures => Assert.Single(failures))
                          .TeeOnFailureAsync(async failures => await Task.FromResult(Assert.Single(failures)))
                          .TeeOnFailureAsync(() => p.Do(2))
                          .TeeOnSuccessAsync(() => p.Do(2))
                          .TeeOnFailureAsync(() => p.Do(3))
                          .TeeOnSuccessAsync(r => p.Do(3))
                          .TeeOnFailureAsync(() => p.DoAsync(4))
                          .TeeOnSuccessAsync(() => p.DoAsync(4))
                          .TeeOnFailureAsync(() => p.DoAsync(5))
                          .TeeOnSuccessAsync(r => p.DoAsync(5));

        Assert.True(newOkResult.IsSuccess);

        p.Reset();

        var newFailResult = await Result.Fail <int>(new Failure("oops"))
                            .TeeOnSuccessAsync(r => p.DoAsync(1))
                            .TeeOnFailureAsync(() => p.DoAsync(1))
                            .TeeOnFailureAsync(failures => Assert.Single(failures))
                            .TeeOnFailureAsync(async failures => await Task.FromResult(Assert.Single(failures)))
                            .TeeOnFailureAsync(() => p.Do(2))
                            .TeeOnSuccessAsync(() => p.Do(2))
                            .TeeOnFailureAsync(() => p.Do(3))
                            .TeeOnSuccessAsync(r => p.Do(3))
                            .TeeOnFailureAsync(() => p.DoAsync(4))
                            .TeeOnSuccessAsync(() => p.DoAsync(4))
                            .TeeOnFailureAsync(() => p.DoAsync(5))
                            .TeeOnSuccessAsync(r => p.DoAsync(5));

        Assert.True(newFailResult.IsFailed);
        Assert.Equal("oops", newFailResult.Failures.First().Message);
    }